本文整理汇总了Java中org.apache.lucene.index.MultiReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java MultiReader.close方法的具体用法?Java MultiReader.close怎么用?Java MultiReader.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.index.MultiReader
的用法示例。
在下文中一共展示了MultiReader.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMissingField
import org.apache.lucene.index.MultiReader; //导入方法依赖的package包/类
public void testMissingField() throws Exception {
String fieldName = "field1";
Directory rd1 = newDirectory();
RandomIndexWriter w1 = new RandomIndexWriter(random(), rd1);
Document doc = new Document();
doc.add(newStringField(fieldName, "content1", Field.Store.YES));
w1.addDocument(doc);
IndexReader reader1 = w1.getReader();
w1.close();
fieldName = "field2";
Directory rd2 = newDirectory();
RandomIndexWriter w2 = new RandomIndexWriter(random(), rd2);
doc = new Document();
doc.add(newStringField(fieldName, "content2", Field.Store.YES));
w2.addDocument(doc);
IndexReader reader2 = w2.getReader();
w2.close();
TermsFilter tf = new TermsFilter(new Term(fieldName, "content1"));
MultiReader multi = new MultiReader(reader1, reader2);
for (AtomicReaderContext context : multi.leaves()) {
DocIdSet docIdSet = tf.getDocIdSet(context, context.reader().getLiveDocs());
if (context.reader().docFreq(new Term(fieldName, "content1")) == 0) {
assertNull(docIdSet);
} else {
FixedBitSet bits = (FixedBitSet) docIdSet;
assertTrue("Must be >= 0", bits.cardinality() >= 0);
}
}
multi.close();
reader1.close();
reader2.close();
rd1.close();
rd2.close();
}
示例2: testTieBreaker
import org.apache.lucene.index.MultiReader; //导入方法依赖的package包/类
/**
* MultiTermQuery provides (via attribute) information about which values
* must be competitive to enter the priority queue.
*
* SlowFuzzyQuery optimizes itself around this information, if the attribute
* is not implemented correctly, there will be problems!
*/
public void testTieBreaker() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
addDoc("a123456", writer);
addDoc("c123456", writer);
addDoc("d123456", writer);
addDoc("e123456", writer);
Directory directory2 = newDirectory();
RandomIndexWriter writer2 = new RandomIndexWriter(random(), directory2);
addDoc("a123456", writer2);
addDoc("b123456", writer2);
addDoc("b123456", writer2);
addDoc("b123456", writer2);
addDoc("c123456", writer2);
addDoc("f123456", writer2);
IndexReader ir1 = writer.getReader();
IndexReader ir2 = writer2.getReader();
MultiReader mr = new MultiReader(ir1, ir2);
IndexSearcher searcher = newSearcher(mr);
SlowFuzzyQuery fq = new SlowFuzzyQuery(new Term("field", "z123456"), 1f, 0, 2);
TopDocs docs = searcher.search(fq, 2);
assertEquals(5, docs.totalHits); // 5 docs, from the a and b's
mr.close();
ir1.close();
ir2.close();
writer.close();
writer2.close();
directory.close();
directory2.close();
}
示例3: testTieBreaker
import org.apache.lucene.index.MultiReader; //导入方法依赖的package包/类
/**
* MultiTermQuery provides (via attribute) information about which values
* must be competitive to enter the priority queue.
*
* FuzzyQuery optimizes itself around this information, if the attribute
* is not implemented correctly, there will be problems!
*/
public void testTieBreaker() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
addDoc("a123456", writer);
addDoc("c123456", writer);
addDoc("d123456", writer);
addDoc("e123456", writer);
Directory directory2 = newDirectory();
RandomIndexWriter writer2 = new RandomIndexWriter(random(), directory2);
addDoc("a123456", writer2);
addDoc("b123456", writer2);
addDoc("b123456", writer2);
addDoc("b123456", writer2);
addDoc("c123456", writer2);
addDoc("f123456", writer2);
IndexReader ir1 = writer.getReader();
IndexReader ir2 = writer2.getReader();
MultiReader mr = new MultiReader(ir1, ir2);
IndexSearcher searcher = newSearcher(mr);
FuzzyQuery fq = new FuzzyQuery(new Term("field", "z123456"), 1, 0, 2, false);
TopDocs docs = searcher.search(fq, 2);
assertEquals(5, docs.totalHits); // 5 docs, from the a and b's
mr.close();
ir1.close();
ir2.close();
writer.close();
writer2.close();
directory.close();
directory2.close();
}
示例4: testDeMorgan
import org.apache.lucene.index.MultiReader; //导入方法依赖的package包/类
public void testDeMorgan() throws Exception {
Directory dir1 = newDirectory();
RandomIndexWriter iw1 = new RandomIndexWriter(random(), dir1);
Document doc1 = new Document();
doc1.add(newTextField("field", "foo bar", Field.Store.NO));
iw1.addDocument(doc1);
IndexReader reader1 = iw1.getReader();
iw1.close();
Directory dir2 = newDirectory();
RandomIndexWriter iw2 = new RandomIndexWriter(random(), dir2);
Document doc2 = new Document();
doc2.add(newTextField("field", "foo baz", Field.Store.NO));
iw2.addDocument(doc2);
IndexReader reader2 = iw2.getReader();
iw2.close();
BooleanQuery query = new BooleanQuery(); // Query: +foo -ba*
query.add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.MUST);
WildcardQuery wildcardQuery = new WildcardQuery(new Term("field", "ba*"));
wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
query.add(wildcardQuery, BooleanClause.Occur.MUST_NOT);
MultiReader multireader = new MultiReader(reader1, reader2);
IndexSearcher searcher = newSearcher(multireader);
assertEquals(0, searcher.search(query, 10).totalHits);
final ExecutorService es = Executors.newCachedThreadPool(new NamedThreadFactory("NRT search threads"));
searcher = new IndexSearcher(multireader, es);
if (VERBOSE)
System.out.println("rewritten form: " + searcher.rewrite(query));
assertEquals(0, searcher.search(query, 10).totalHits);
es.shutdown();
es.awaitTermination(1, TimeUnit.SECONDS);
multireader.close();
reader1.close();
reader2.close();
dir1.close();
dir2.close();
}
示例5: testDeMorgan
import org.apache.lucene.index.MultiReader; //导入方法依赖的package包/类
public void testDeMorgan() throws Exception {
Directory dir1 = newDirectory();
RandomIndexWriter iw1 = new RandomIndexWriter(random(), dir1);
Document doc1 = new Document();
doc1.add(newTextField("field", "foo bar", Field.Store.NO));
iw1.addDocument(doc1);
IndexReader reader1 = iw1.getReader();
iw1.close();
Directory dir2 = newDirectory();
RandomIndexWriter iw2 = new RandomIndexWriter(random(), dir2);
Document doc2 = new Document();
doc2.add(newTextField("field", "foo baz", Field.Store.NO));
iw2.addDocument(doc2);
IndexReader reader2 = iw2.getReader();
iw2.close();
BooleanQuery query = new BooleanQuery(); // Query: +foo -ba*
query.add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.MUST);
WildcardQuery wildcardQuery = new WildcardQuery(new Term("field", "ba*"));
wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
query.add(wildcardQuery, BooleanClause.Occur.MUST_NOT);
MultiReader multireader = new MultiReader(reader1, reader2);
IndexSearcher searcher = new IndexSearcher(multireader);
assertEquals(0, searcher.search(query, 10).totalHits);
final ExecutorService es = Executors.newCachedThreadPool(new NamedThreadFactory("NRT search threads"));
searcher = new IndexSearcher(multireader, es);
if (VERBOSE)
System.out.println("rewritten form: " + searcher.rewrite(query));
assertEquals(0, searcher.search(query, 10).totalHits);
es.shutdown();
es.awaitTermination(1, TimeUnit.SECONDS);
multireader.close();
reader1.close();
reader2.close();
dir1.close();
dir2.close();
}