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


Java MultiReader.close方法代碼示例

本文整理匯總了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();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:37,代碼來源:TermsFilterTest.java

示例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(); 
}
 
開發者ID:europeana,項目名稱:search,代碼行數:41,代碼來源:TestSlowFuzzyQuery.java

示例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(); 
}
 
開發者ID:europeana,項目名稱:search,代碼行數:41,代碼來源:TestFuzzyQuery.java

示例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();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:42,代碼來源:TestBooleanQuery.java

示例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();
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:42,代碼來源:TestBooleanQuery.java


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