Package org.apache.lucene.index

Examples of org.apache.lucene.index.MultiReader


    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();
View Full Code Here


    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();
  }
View Full Code Here

    DirectoryReader rA = DirectoryReader.open(dirA);
    readerA = SlowCompositeReaderWrapper.wrap(rA);
    readerAclone = SlowCompositeReaderWrapper.wrap(rA);
    readerA = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dirA));
    readerB = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dirB));
    readerX = SlowCompositeReaderWrapper.wrap(new MultiReader(readerA, readerB));
  }
View Full Code Here

          }
        }
      }
      if (indexes.size() == 0) throw new Exception("No input indexes.");
      IndexReader[] readers = (IndexReader[])indexes.toArray(new IndexReader[0]);
      reader = new MultiReader(readers);
    }
    if (LOG.isInfoEnabled()) {
      LOG.info(dr + "Opened " + numIdx + " index(es) with total " +
               reader.numDocs() + " documents.");
    }
View Full Code Here

    this.conf = conf;
    this.fs = FileSystem.get(conf);
    for (int i = 0; i < indexDirs.length; i++) {
      readers[i] = IndexReader.open(getDirectory(indexDirs[i]));
    }
    init(new MultiReader(readers), conf);
  }
View Full Code Here

    // we can't put deleted docs before the nested reader, because
    // it will throw off the docIds
    IndexReader[] readers = new IndexReader[] {
      edge < 0 ? r : IndexReader.open(makeEmptyIndex(0)),
      IndexReader.open(makeEmptyIndex(0)),
      new MultiReader(new IndexReader[] {
        IndexReader.open(makeEmptyIndex(edge < 0 ? 4 : 0)),
        IndexReader.open(makeEmptyIndex(0)),
        0 == edge ? r : IndexReader.open(makeEmptyIndex(0))
      }),
      IndexReader.open(makeEmptyIndex(0 < edge ? 0 : 7)),
      IndexReader.open(makeEmptyIndex(0)),
      new MultiReader(new IndexReader[] {
        IndexReader.open(makeEmptyIndex(0 < edge ? 0 : 5)),
        IndexReader.open(makeEmptyIndex(0)),
        0 < edge ? r : IndexReader.open(makeEmptyIndex(0))
      })
    };
    IndexSearcher out = new IndexSearcher(new MultiReader(readers));
    out.setSimilarity(s.getSimilarity());
    return out;
  }
View Full Code Here

                // String , need changes in projects.jspf too
                for (String proj : projects) {
                    FSDirectory dir = FSDirectory.open(new File(indexDir, proj));
                    subreaders[ii++] = DirectoryReader.open(dir);
                }
                MultiReader searchables = new MultiReader(subreaders, true);
                if (parallel) {
                    int noThreads = 2 + (2 * Runtime.getRuntime().availableProcessors()); //TODO there might be a better way for counting this
                    executor = Executors.newFixedThreadPool(noThreads);
                }
                searcher = parallel
View Full Code Here

        int ii = 0;
        for (Project project : root) {
            IndexReader ireader = (DirectoryReader.open(FSDirectory.open(new File(droot, project.getPath()))));
            subreaders[ii++] = ireader;
        }
        MultiReader searchables = new MultiReader(subreaders, true);
        if (Runtime.getRuntime().availableProcessors() > 1) {
            int noThreads = 2 + (2 * Runtime.getRuntime().availableProcessors()); //TODO there might be a better way for counting this - or we should honor the command line option here too!
            ExecutorService executor = Executors.newFixedThreadPool(noThreads);
            searcher = new IndexSearcher(searchables, executor);
        } else {
View Full Code Here

            System.out.println("  searcher expired during mock reader init: " + see);
          }
          continue;
        }

        final IndexReader mockReader = new MultiReader(subs);
        final IndexSearcher mockSearcher = new IndexSearcher(mockReader);

        Query query;
        Sort sort;

        if (prevSearchState != null) {
          query = prevSearchState.query;
          sort = prevSearchState.sort;
        } else {
          if (terms == null && docCount > minDocsToMakeTerms) {
            // TODO: try to "focus" on high freq terms sometimes too
            // TODO: maybe also periodically reset the terms...?
            final TermsEnum termsEnum = MultiFields.getTerms(mockReader, "body").iterator(null);
            terms = new ArrayList<>();
            while(termsEnum.next() != null) {
              terms.add(BytesRef.deepCopyOf(termsEnum.term()));
            }
            if (VERBOSE) {
              System.out.println("TEST: init terms: " + terms.size() + " terms");
            }
            if (terms.size() == 0) {
              terms = null;
            }
          }

          if (VERBOSE) {
            System.out.println("  maxDoc=" + mockReader.maxDoc());
          }

          if (terms != null) {
            if (random().nextBoolean()) {
              query = new TermQuery(new Term("body", terms.get(random().nextInt(terms.size()))));
View Full Code Here

    ir.close();
    dir.close();
  }
 
  public void testEmptyIndex() throws Exception {
    IndexSearcher empty = newSearcher(new MultiReader());
    Query query = new TermQuery(new Term("contents", "foo"));
 
    Sort sort = new Sort();
    sort.setSort(new SortedSetSortField("sortedset", false));
    TopDocs td = empty.search(query, null, 10, sort, true, true);
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.MultiReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.