當前位置: 首頁>>代碼示例>>Java>>正文


Java IndexWriterConfig.setSimilarity方法代碼示例

本文整理匯總了Java中org.apache.lucene.index.IndexWriterConfig.setSimilarity方法的典型用法代碼示例。如果您正苦於以下問題:Java IndexWriterConfig.setSimilarity方法的具體用法?Java IndexWriterConfig.setSimilarity怎麽用?Java IndexWriterConfig.setSimilarity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.index.IndexWriterConfig的用法示例。


在下文中一共展示了IndexWriterConfig.setSimilarity方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
private IndexWriterConfig getIndexWriterConfig(boolean create) {
    final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer());
    iwc.setCommitOnClose(false); // we by default don't commit on close
    iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND);
    iwc.setIndexDeletionPolicy(deletionPolicy);
    // with tests.verbose, lucene sets this up: plumb to align with filesystem stream
    boolean verbose = false;
    try {
        verbose = Boolean.parseBoolean(System.getProperty("tests.verbose"));
    } catch (Exception ignore) {
    }
    iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger));
    iwc.setMergeScheduler(mergeScheduler);
    MergePolicy mergePolicy = config().getMergePolicy();
    // Give us the opportunity to upgrade old segments while performing
    // background merges
    mergePolicy = new ElasticsearchMergePolicy(mergePolicy);
    iwc.setMergePolicy(mergePolicy);
    iwc.setSimilarity(engineConfig.getSimilarity());
    iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());
    iwc.setCodec(engineConfig.getCodec());
    iwc.setUseCompoundFile(true); // always use compound on flush - reduces # of file-handles on refresh
    return iwc;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:InternalEngine.java

示例2: beforeClass

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
  dir = newDirectory();
  IndexWriterConfig iwConfig = newIndexWriterConfig(new MockAnalyzer(random()));
  iwConfig.setMergePolicy(newLogMergePolicy());
  iwConfig.setSimilarity(sim);
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig);

  Document doc = new Document();
  doc.add(new TextField("text", "this is a test test test", Field.Store.NO));
  iw.addDocument(doc);

  doc = new Document();
  doc.add(new TextField("text", "second test", Field.Store.NO));
  iw.addDocument(doc);

  reader = iw.getReader();
  searcher = newSearcher(reader);
  iw.close();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:21,代碼來源:TestLongNormValueSource.java

示例3: testReallyNoNormsForDrillDown

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
public void testReallyNoNormsForDrillDown() throws Exception {
  Directory dir = newDirectory();
  Directory taxoDir = newDirectory();
  IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
  iwc.setSimilarity(new PerFieldSimilarityWrapper() {
      final Similarity sim = new DefaultSimilarity();

      @Override
      public Similarity get(String name) {
        assertEquals("field", name);
        return sim;
      }
    });
  TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
  FacetsConfig config = new FacetsConfig();

  Document doc = new Document();
  doc.add(newTextField("field", "text", Field.Store.NO));
  doc.add(new FacetField("a", "path"));
  writer.addDocument(config.build(taxoWriter, doc));
  IOUtils.close(writer, taxoWriter, dir, taxoDir);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:24,代碼來源:TestTaxonomyFacetCounts.java

示例4: openWriter

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
private IndexWriter openWriter(Conf conf, boolean create) throws IOException {
    File indexDir = new File(conf.getEsaIndexDir());
    indexDir.mkdirs();
    System.out.println("Create index on " + indexDir.getAbsolutePath());
    Directory fsDirectory = FSDirectory.open(indexDir);

    IndexWriterConfig config = new IndexWriterConfig(Conf.LUCENE_VERSION, new ESAAnalyzer(conf));
    config.setSimilarity(new ESASimilarity());
    if (create) {
        // Create a new index in the directory, removing any
        // previously indexed documents:
        config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    } else {
        // Add new documents to an existing index:
        config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    }
    return new IndexWriter(fsDirectory, config);
}
 
開發者ID:iamxiatian,項目名稱:wikit,代碼行數:19,代碼來源:IndexConceptVisitor.java

示例5: createOrLoadIndexWriter

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
protected static IndexWriter createOrLoadIndexWriter(URI index, Analyzer analyser) throws CorruptIndexException, LockObtainFailedException, IOException  {
	Directory directory = FSDirectory.open(Paths.get(index));
	IndexWriterConfig iwc = new IndexWriterConfig(analyser);
	iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
	iwc.setSimilarity(new SnomedSimilarity());
	IndexWriter writer = new IndexWriter(directory, iwc);
	return writer;
}
 
開發者ID:wardle,項目名稱:rsterminology,代碼行數:9,代碼來源:Search.java

示例6: newIndexWriter

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
private/*synchronized elsewhere*/IndexWriter newIndexWriter( IndexIdentifier identifier )
{
    assertNotClosed();
    try
    {
        Directory dir = filesystemFacade.getDirectory( baseStorePath, identifier ); //getDirectory(
        // baseStorePath, identifier );
        directoryExists( dir );
        IndexType type = getType( identifier, false );
        IndexWriterConfig writerConfig = new IndexWriterConfig( type.analyzer );
        writerConfig.setIndexDeletionPolicy( new MultipleBackupDeletionPolicy() );
        Similarity similarity = type.getSimilarity();
        if ( similarity != null )
        {
            writerConfig.setSimilarity( similarity );
        }
        IndexWriter indexWriter = new IndexWriter( dir, writerConfig );
        // TODO We should tamper with this value and see how it affects the
        // general performance. Lucene docs says rather <10 for mixed
        // reads/writes
        //            writer.setMergeFactor( 8 );
        return indexWriter;
    }
    catch ( IOException e )
    {
        throw new RuntimeException( e );
    }
}
 
開發者ID:neo4j-contrib,項目名稱:neo4j-lucene5-index,代碼行數:29,代碼來源:LuceneDataSource.java

示例7: indexFiles

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
/**
 * Indexes files located in given input path.
 * @param path Path to the documents directory. Can be a single file as well.
 * @param rootDir A path in the @path parameter which is a root directory for the document storage. It determines the relative path
 * the files will be index with.
 */
public void indexFiles(String path, String rootDir) {
    storage = rootDir;
    if (!storage.endsWith(File.separator)) {
        storage += File.separator;
    }
    final File docDir = new File(path);
    if (!docDir.exists() || !docDir.canRead()) {
        LOG.fatal("Document directory '{}' does not exist or is not readable, please check the path.",docDir.getAbsoluteFile());            
        System.exit(1);
    }
    try {
        startTime = System.currentTimeMillis();
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_45, analyzer);
        PayloadSimilarity ps = new PayloadSimilarity();
        ps.setDiscountOverlaps(false);
        config.setSimilarity(ps);
        config.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
        try (IndexWriter writer = new IndexWriter(FSDirectory.open(indexDir), config))
        {
            LOG.info("Getting list of documents to index.");
            List<File> files = getDocs(docDir);
            countFiles(files);
            LOG.info("Number of documents to index is {}",count);
            indexDocsThreaded(files, writer);
        }
    } catch (IOException ex) {
        LOG.error(ex);
    }
}
 
開發者ID:martinliska,項目名稱:MIaS,代碼行數:36,代碼來源:Indexing.java

示例8: newIndexWriterConfig

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
/** create a new index writer config with random defaults using the specified random */
public static IndexWriterConfig newIndexWriterConfig(Random r, Version v, Analyzer a) {
  IndexWriterConfig c = new IndexWriterConfig(v, a);
  c.setSimilarity(classEnvRule.similarity);
  if (VERBOSE) {
    // Even though TestRuleSetupAndRestoreClassEnv calls
    // InfoStream.setDefault, we do it again here so that
    // the PrintStreamInfoStream.messageID increments so
    // that when there are separate instances of
    // IndexWriter created we see "IW 0", "IW 1", "IW 2",
    // ... instead of just always "IW 0":
    c.setInfoStream(new TestRuleSetupAndRestoreClassEnv.ThreadNameFixingPrintStreamInfoStream(System.out));
  }

  if (r.nextBoolean()) {
    c.setMergeScheduler(new SerialMergeScheduler());
  } else if (rarely(r)) {
    int maxThreadCount = TestUtil.nextInt(r, 1, 4);
    int maxMergeCount = TestUtil.nextInt(r, maxThreadCount, maxThreadCount+4);
    ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler();
    cms.setMaxMergesAndThreads(maxMergeCount, maxThreadCount);
    c.setMergeScheduler(cms);
  }
  if (r.nextBoolean()) {
    if (rarely(r)) {
      // crazy value
      c.setMaxBufferedDocs(TestUtil.nextInt(r, 2, 15));
    } else {
      // reasonable value
      c.setMaxBufferedDocs(TestUtil.nextInt(r, 16, 1000));
    }
  }
  if (r.nextBoolean()) {
    if (rarely(r)) {
      // crazy value
      c.setTermIndexInterval(r.nextBoolean() ? TestUtil.nextInt(r, 1, 31) : TestUtil.nextInt(r, 129, 1000));
    } else {
      // reasonable value
      c.setTermIndexInterval(TestUtil.nextInt(r, 32, 128));
    }
  }
  if (r.nextBoolean()) {
    int maxNumThreadStates = rarely(r) ? TestUtil.nextInt(r, 5, 20) // crazy value
        : TestUtil.nextInt(r, 1, 4); // reasonable value

    c.setMaxThreadStates(maxNumThreadStates);
  }

  c.setMergePolicy(newMergePolicy(r));

  if (rarely(r)) {
    c.setMergedSegmentWarmer(new SimpleMergedSegmentWarmer(c.getInfoStream()));
  }
  c.setUseCompoundFile(r.nextBoolean());
  c.setReaderPooling(r.nextBoolean());
  c.setReaderTermsIndexDivisor(TestUtil.nextInt(r, 1, 4));
  c.setCheckIntegrityAtMerge(r.nextBoolean());
  return c;
}
 
開發者ID:europeana,項目名稱:search,代碼行數:60,代碼來源:LuceneTestCase.java

示例9: initialize

import org.apache.lucene.index.IndexWriterConfig; //導入方法依賴的package包/類
private void initialize(File indexPath, int kmerSize, boolean minStrandKmer, Similarity similarity, int workerThreads, int ramBufferSize) throws Exception {
    if(!indexPath.exists()) {
        indexPath.mkdirs();
    }
    
    if(indexPath.exists()) {
        cleanUpDirectory(indexPath);
    }
    
    this.indexPath = indexPath;
    this.minStrandKmer = minStrandKmer;
    this.analyzer = new KmerIndexAnalyzer(kmerSize, minStrandKmer);
    Directory dir = new MMapDirectory(this.indexPath.toPath()); 
    IndexWriterConfig config = new IndexWriterConfig(this.analyzer); 
    if(similarity != null) {
        config.setSimilarity(similarity);
    }
    
    this.workerThreads = workerThreads;
    
    if(ramBufferSize > 0) {
        config.setRAMBufferSizeMB(ramBufferSize);
    }
    
    config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
    this.indexWriter = new IndexWriter(dir, config);
    
    this.executor = new BlockingExecutor(this.workerThreads, this.workerThreads * 2);
    
    for(int i=0;i<this.workerThreads;i++) {
        Document doc = new Document();
        Field filenameField = new StringField(IndexConstants.FIELD_FILENAME, "", Field.Store.YES);
        Field headerField = new StringField(IndexConstants.FIELD_HEADER, "", Field.Store.YES);
        Field sequenceDirectionField = new StringField(IndexConstants.FIELD_SEQUENCE_DIRECTION, "", Field.Store.YES);
        Field taxonTreeField = new StringField(IndexConstants.FIELD_TAXONOMY_TREE, "", Field.Store.YES);
        Field sequenceField = new TextField(IndexConstants.FIELD_SEQUENCE, "", Field.Store.NO);

        doc.add(filenameField);
        doc.add(headerField);
        doc.add(sequenceDirectionField);
        doc.add(taxonTreeField);
        doc.add(sequenceField);
        
        this.freeQueue.offer(doc);
    }
}
 
開發者ID:iychoi,項目名稱:biospectra,代碼行數:47,代碼來源:Indexer.java


注:本文中的org.apache.lucene.index.IndexWriterConfig.setSimilarity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。