Package org.apache.lucene.index

Examples of org.apache.lucene.index.MultiReader


    }
    wA.close();
    wB.close();
    readerA = IndexReader.open(dirA, true);
    readerB = IndexReader.open(dirB, true);
    readerX = new MultiReader(new IndexReader[] { readerA, readerB });
  }
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

    // 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(random, 0), true),
      IndexReader.open(makeEmptyIndex(random, 0), true),
      new MultiReader(new IndexReader[] {
        IndexReader.open(makeEmptyIndex(random, edge < 0 ? 4 : 0), true),
        IndexReader.open(makeEmptyIndex(random, 0), true),
        0 == edge ? r : IndexReader.open(makeEmptyIndex(random, 0), true)
      }),
      IndexReader.open(makeEmptyIndex(random, 0 < edge ? 0 : 7), true),
      IndexReader.open(makeEmptyIndex(random, 0), true),
      new MultiReader(new IndexReader[] {
        IndexReader.open(makeEmptyIndex(random, 0 < edge ? 0 : 5), true),
        IndexReader.open(makeEmptyIndex(random, 0), true),
        0 < edge ? r : IndexReader.open(makeEmptyIndex(random, 0), true)
      })
    };
    IndexSearcher out = new IndexSearcher(new MultiReader(readers));
    out.setSimilarity(s.getSimilarity());
    return out;
  }
View Full Code Here

        {
            final IndexSearcher indexSearcher = ctx.acquireIndexSearcher();
            searchers.add( indexSearcher );
            contextReaders.add( indexSearcher.getIndexReader() );
        }
        return new MultiReader( contextReaders.toArray( new IndexReader[contextReaders.size()] ) );
    }
View Full Code Here

                           if (indexReader == null)
                           {
                              try
                              {
                                 readers = getReadOnlyIndexReaders(false, false);
                                 indexReader = new MultiReader(readers);
                              }
                              catch (Throwable e)
                              {
                                 // 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)
                              {
                                 // this is safe index reader retrieval. The last index already closed, possibly merged or
                                 // any other exception that occurs here
View Full Code Here

      readers[i] = indexAccessor.getReader(false);
      multiReaderAccessors.put(readers[i], indexAccessor);
      i++;
    }

    MultiReader multiReader = new MultiReader(readers, true);

    return multiReader;
  }
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

        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

    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

            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<BytesRef>();
            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

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.