本文整理匯總了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;
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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 );
}
}
示例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);
}
}
示例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;
}
示例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);
}
}