Java Code Examples for org.apache.lucene.search.IndexSearcher#getTopReaderContext()

The following examples show how to use org.apache.lucene.search.IndexSearcher#getTopReaderContext() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: lucene-solr   File: TestPayloadSpanUtil.java    License: Apache License 2.0 6 votes vote down vote up
public void testPayloadSpanUtil() throws Exception {
  Directory directory = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), directory,
      newIndexWriterConfig(new PayloadAnalyzer()).setSimilarity(new ClassicSimilarity()));

  Document doc = new Document();
  doc.add(newTextField(FIELD, "xx rr yy mm  pp", Field.Store.YES));
  writer.addDocument(doc);

  IndexReader reader = writer.getReader();
  writer.close();
  IndexSearcher searcher = newSearcher(reader);

  PayloadSpanUtil psu = new PayloadSpanUtil(searcher.getTopReaderContext());

  Collection<byte[]> payloads = psu.getPayloadsForQuery(new TermQuery(new Term(FIELD, "rr")));
  if(VERBOSE) {
    System.out.println("Num payloads:" + payloads.size());
    for (final byte [] bytes : payloads) {
      System.out.println(new String(bytes, StandardCharsets.UTF_8));
    }
  }
  reader.close();
  directory.close();
}
 
Example 2
Source Project: lucene-solr   File: TestGrouping.java    License: Apache License 2.0 5 votes vote down vote up
public ShardState(IndexSearcher s) {
  final IndexReaderContext ctx = s.getTopReaderContext();
  final List<LeafReaderContext> leaves = ctx.leaves();
  subSearchers = new ShardSearcher[leaves.size()];
  for(int searcherIDX=0;searcherIDX<subSearchers.length;searcherIDX++) {
    subSearchers[searcherIDX] = new ShardSearcher(leaves.get(searcherIDX), ctx);
  }

  docStarts = new int[subSearchers.length];
  for(int subIDX=0;subIDX<docStarts.length;subIDX++) {
    docStarts[subIDX] = leaves.get(subIDX).docBase;
    //System.out.println("docStarts[" + subIDX + "]=" + docStarts[subIDX]);
  }
}
 
Example 3
Source Project: lucene-solr   File: SpanTermQuery.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SpanWeight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  final TermStates context;
  final IndexReaderContext topContext = searcher.getTopReaderContext();
  if (termStates == null || termStates.wasBuiltFor(topContext) == false) {
    context = TermStates.build(topContext, term, scoreMode.needsScores());
  }
  else {
    context = termStates;
  }
  return new SpanTermWeight(context, searcher, scoreMode.needsScores() ? Collections.singletonMap(term, context) : null, boost);
}
 
Example 4
Source Project: mtas   File: MtasExtendedSpanTermQuery.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SpanWeight createWeight(IndexSearcher searcher, boolean needsScores, float boost)
    throws IOException {
  final TermContext context;
  final IndexReaderContext topContext = searcher.getTopReaderContext();
  if (termContext == null) {
    context = TermContext.build(topContext, localTerm);
  } else {
    context = termContext;
  }
  return new SpanTermWeight(context, searcher,
      needsScores ? Collections.singletonMap(localTerm, context) : null, boost);
}
 
Example 5
@Override
public Weight createWeight(final IndexSearcher searcher, final ScoreMode scoreMode, final float boost)
        throws IOException {
    final IndexReaderContext context = searcher.getTopReaderContext();
    final TermStates termState = TermStates.build(context, term, scoreMode.needsScores());
    // TODO: set boosts to 1f if needsScores is false?
    return new FieldBoostWeight(termState, boost, fieldBoost.getBoost(term.field(), searcher.getIndexReader()));
}
 
Example 6
Source Project: pyramid   File: CustomSpanTermQuery.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CustomSpanWeight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    final TermContext context;
    final IndexReaderContext topContext = searcher.getTopReaderContext();
    if (termContext == null || termContext.wasBuiltFor(topContext) == false) {
        context = TermContext.build(topContext, term);
    }
    else {
        context = termContext;
    }
    return new CustomSpanTermWeight(context, searcher, needsScores ? Collections.singletonMap(term, context) : null);
}