Package org.apache.lucene.index

Examples of org.apache.lucene.index.MultiReader


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


          new FileSystemDirectory(fs, new Path(shards[i].getDirectory()),
              false, conf);
      readers[i] = IndexReader.open(dir);
    }

    IndexReader reader = new MultiReader(readers);
    IndexSearcher searcher = new IndexSearcher(reader);
    Hits hits = searcher.search(new TermQuery(new Term("content", "apache")));

    assertEquals(numRuns * numDocsPerRun, hits.length());

    int[] counts = new int[numDocsPerRun];
    for (int i = 0; i < hits.length(); i++) {
      Document doc = hits.doc(i);
      counts[Integer.parseInt(doc.get("id"))]++;
    }

    for (int i = 0; i < numDocsPerRun; i++) {
      assertEquals(numRuns, counts[i]);
    }

    // max field length is 2, so "dot" is also indexed but not "org"
    hits = searcher.search(new TermQuery(new Term("content", "dot")));
    assertEquals(numRuns, hits.length());

    hits = searcher.search(new TermQuery(new Term("content", "org")));
    assertEquals(0, hits.length());

    searcher.close();
    reader.close();

    // open and close an index writer with KeepOnlyLastCommitDeletionPolicy
    // to remove earlier checkpoints
    for (int i = 0; i < shards.length; i++) {
      Directory dir =
View Full Code Here

        unsortedReaders = super.getMergeReaders();
        final AtomicReader atomicView;
        if (unsortedReaders.size() == 1) {
          atomicView = unsortedReaders.get(0);
        } else {
          final IndexReader multiReader = new MultiReader(unsortedReaders.toArray(new AtomicReader[unsortedReaders.size()]));
          atomicView = SlowCompositeReaderWrapper.wrap(multiReader);
        }
        docMap = sorter.sort(atomicView);
        sortedView = SortingAtomicReader.wrap(atomicView, docMap);
      }
View Full Code Here

                            Collection<FacetHandler<?>> facetHandlers,
                            Collection<RuntimeFacetHandlerFactory<?,?>> facetHandlerFactories,
                            WorkArea workArea,
                            boolean useSubReaders) throws IOException
  {
    super(useSubReaders ? new MultiReader(createSubReaders(reader, workArea), false) : reader);
    if(useSubReaders)
    {
      _dir = reader.directory();
      BoboIndexReader[] subReaders = (BoboIndexReader[])in.getSequentialSubReaders();
      if(subReaders != null && subReaders.length > 0)
View Full Code Here

    isNewReader = isNewReader || (readerMap.size() != 0);
    if (!isNewReader){
      return this;
    }
    else{
      MultiReader newMreader = new MultiReader(currentReaders.toArray(new BoboIndexReader[currentReaders.size()]),false);
      BoboIndexReader newReader = BoboIndexReader.getInstanceAsSubReader(newMreader,this._facetHandlers,this._runtimeFacetHandlerFactories);
      newReader._dir = _dir;
      return newReader;
    }
  }
View Full Code Here

                            Collection<FacetHandler<?>> facetHandlers,
                            Collection<RuntimeFacetHandlerFactory<?,?>> facetHandlerFactories,
                            WorkArea workArea,
                            boolean useSubReaders) throws IOException
  {
    super(useSubReaders ? new MultiReader(createSubReaders(reader, workArea), false) : reader);
    if(useSubReaders)
    {
      _dir = reader.directory();
      BoboIndexReader[] subReaders = (BoboIndexReader[])in.getSequentialSubReaders();
      if(subReaders != null && subReaders.length > 0)
View Full Code Here

                                 if (indexReader == null)
                                 {
                                     try
                                     {
                                         readers = getReadOnlyIndexReaders(false, false);
                                         indexReader = new MultiReader(readers);
                                     }
                                     catch (Throwable e)//NOSONAR
                                     {
                                         // this is safe index reader retrieval. The last index already closed, possibly merged or
                                         // any other exception that occurs here
                                         LOG.warn("Could not create the MultiReader :" + e.getLocalizedMessage());
                                         LOG.debug("Could not create the MultiReader", e);
                                     }
                                 }
                                 if ((indexReader != null && !indexReader.isCurrent()))
                                 {
                                     // safe release reader
                                     if (indexReader != null)
                                     {
                                         for (ReadOnlyIndexReader reader : readers)
                                         {
                                             reader.release();
                                         }
                                     }
                                     try
                                     {
                                         readers = getReadOnlyIndexReaders(false, false);
                                         indexReader = new MultiReader(readers);
                                     }
                                     catch (Throwable e)//NOSONAR
                                     {
                                         // this is safe index reader retrieval. The last index already closed, possibly merged or
                                         // any other exception that occurs here
View Full Code Here

   * Test that complements works with MultiReader
   */
  @Test
  public void testComplementsWithMultiReader() throws Exception {
    final IndexReader origReader = indexReader;
    indexReader = new MultiReader(origReader);
    try {
      doTestComplements();
    } finally {
      indexReader = origReader;
    }
View Full Code Here

        unsortedReaders = super.getMergeReaders();
        final AtomicReader atomicView;
        if (unsortedReaders.size() == 1) {
          atomicView = unsortedReaders.get(0);
        } else {
          final IndexReader multiReader = new MultiReader(unsortedReaders.toArray(new AtomicReader[unsortedReaders.size()]));
          atomicView = SlowCompositeReaderWrapper.wrap(multiReader);
        }
        docMap = sorter.sort(atomicView);
        sortedView = SortingAtomicReader.wrap(atomicView, docMap);
      }
View Full Code Here

   * Test that complements works with MultiReader
   */
  @Test
  public void testComplementsWithMultiReader() throws Exception {
    final IndexReader origReader = indexReader;
    indexReader = new MultiReader(origReader);
    try {
      doTestComplements();
    } finally {
      indexReader = origReader;
    }
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.