@Override public Scorer scorer(LeafReaderContext context) throws IOException { return in.scorer(context); }
private FunctionFactorScorer functionScorer(LeafReaderContext context) throws IOException { Scorer subQueryScorer = subQueryWeight.scorer(context); if (subQueryScorer == null) { return null; } final LeafScoreFunction[] leafFunctions = new LeafScoreFunction[functions.length]; final Bits[] docSets = new Bits[functions.length]; for (int i = 0; i < functions.length; i++) { ScoreFunction function = functions[i]; leafFunctions[i] = function.getLeafScoreFunction(context); if (filterWeights[i] != null) { ScorerSupplier filterScorerSupplier = filterWeights[i].scorerSupplier(context); docSets[i] = Lucene.asSequentialAccessBits(context.reader().maxDoc(), filterScorerSupplier); } else { docSets[i] = new Bits.MatchAllBits(context.reader().maxDoc()); } } return new FunctionFactorScorer(this, subQueryScorer, scoreMode, functions, maxBoost, leafFunctions, docSets, combineFunction, needsScores); }
/** * Optional method. * Get a {@link ScorerSupplier}, which allows to know the cost of the {@link Scorer} * before building it. The default implementation calls {@link #scorer} and * builds a {@link ScorerSupplier} wrapper around it. * @see #scorer */ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { final Scorer scorer = scorer(context); if (scorer == null) { return null; } return new ScorerSupplier() { @Override public Scorer get(long leadCost) { return scorer; } @Override public long cost() { return scorer.iterator().cost(); } }; }
@Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { Scorer scorer = weight.scorer(ctx); if (scorer == null) return DoubleValues.EMPTY; DocIdSetIterator it = scorer.iterator(); return new DoubleValues() { @Override public double doubleValue() throws IOException { return scorer.score(); } @Override public boolean advanceExact(int doc) throws IOException { if (it.docID() > doc) return false; return it.docID() == doc || it.advance(doc) == doc; } }; }
/** Create the scorer used to score our associated DisjunctionMaxQuery */ @Override public Scorer scorer(LeafReaderContext context) throws IOException { List<Scorer> scorers = new ArrayList<>(); for (Weight w : weights) { // we will advance() subscorers Scorer subScorer = w.scorer(context); if (subScorer != null) { scorers.add(subScorer); } } if (scorers.isEmpty()) { // no sub-scorers had any documents return null; } else if (scorers.size() == 1) { // only one sub-scorer in this segment return scorers.get(0); } else { return new DisjunctionMaxScorer(this, tieBreakerMultiplier, scorers, needsScores); } }
/** * Optional method, to return a {@link BulkScorer} to * score the query and send hits to a {@link Collector}. * Only queries that have a different top-level approach * need to override this; the default implementation * pulls a normal {@link Scorer} and iterates and * collects the resulting hits which are not marked as deleted. * * @param context * the {@link org.apache.lucene.index.LeafReaderContext} for which to return the {@link Scorer}. * * @return a {@link BulkScorer} which scores documents and * passes them to a collector. * @throws IOException if there is a low-level I/O error */ public BulkScorer bulkScorer(LeafReaderContext context) throws IOException { Scorer scorer = scorer(context); if (scorer == null) { // No docs match return null; } // This impl always scores docs in order, so we can // ignore scoreDocsInOrder: return new DefaultBulkScorer(scorer); }
@Override public Scorer scorer(LeafReaderContext context) throws IOException { final WeightOrDocIdSet weightOrBitSet = rewrite(context); if (weightOrBitSet.weight != null) { return weightOrBitSet.weight.scorer(context); } else { return scorer(weightOrBitSet.set); } }
@Override public Scorer scorer(LeafReaderContext context) throws IOException { final WeightOrDocIdSet weightOrBitSet = rewrite(context); if (weightOrBitSet == null) { return null; } else if (weightOrBitSet.weight != null) { return weightOrBitSet.weight.scorer(context); } else { return scorer(weightOrBitSet.set); } }
private static Scorer getScorer(Query query, CodecReader reader) throws IOException { IndexSearcher s = new IndexSearcher(reader); s.setQueryCache(null); Weight weight = s.createWeight(s.rewrite(query), false, 1.0f); return weight.scorer(reader.getContext()); }
BooleanClause c = cIter.next(); if (c.isProhibited()) { Scorer scorer = w.scorer(context); if (scorer != null) { prohibited.add(scorer);
/** * Returns {@link Matches} for a specific document, or {@code null} if the document * does not match the parent query * * A query match that contains no position information (for example, a Point or * DocValues query) will return {@link MatchesUtils#MATCH_WITH_NO_TERMS} * * @param context the reader's context to create the {@link Matches} for * @param doc the document's id relative to the given context's reader * @lucene.experimental */ public Matches matches(LeafReaderContext context, int doc) throws IOException { Scorer scorer = scorer(context); if (scorer == null) { return null; } final TwoPhaseIterator twoPhase = scorer.twoPhaseIterator(); if (twoPhase == null) { if (scorer.iterator().advance(doc) != doc) { return null; } } else { if (twoPhase.approximation().advance(doc) != doc || twoPhase.matches() == false) { return null; } } return MatchesUtils.MATCH_WITH_NO_TERMS; }
query = searcher.rewrite(query); final Weight weight = searcher.createWeight(query, false, 1); final Scorer scorer = weight.scorer(readerContext); if (scorer != null) { final DocIdSetIterator it = scorer.iterator();
scorer = weight.scorer(readerContext);
@Override public Scorer scorer(LeafReaderContext context) throws IOException { shardKeyMap.add(context.reader()); return in.scorer(context); }
/** * Get a {@link DocIdSet} that matches the inner documents. */ public DocIdSetIterator innerDocs(LeafReaderContext ctx) throws IOException { final IndexReaderContext topLevelCtx = ReaderUtil.getTopLevelContext(ctx); IndexSearcher indexSearcher = new IndexSearcher(topLevelCtx); Weight weight = indexSearcher.createNormalizedWeight(innerQuery, false); Scorer s = weight.scorer(ctx); return s == null ? null : s.iterator(); } }
private static BitSetProducer newParentDocBitSetProducer(Version indexVersionCreated) { return context -> { Query query = Queries.newNonNestedFilter(indexVersionCreated); final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context); final IndexSearcher searcher = new IndexSearcher(topLevelContext); searcher.setQueryCache(null); final Weight weight = searcher.createNormalizedWeight(query, false); Scorer s = weight.scorer(context); return s == null ? null : BitSet.of(s.iterator(), context.reader().maxDoc()); }; } }
searcher.setQueryCache(null); Weight weight = searcher.createNormalizedWeight(childFilter, false); Scorer childDocsScorer = weight.scorer(ctx);
Scorer scorer = nestedWeight.scorer(context); if (scorer == null) { continue;
static CodecReader wrapReader(String recoverySourceField, CodecReader reader, Supplier<Query> retainSourceQuerySupplier) throws IOException { NumericDocValues recoverySource = reader.getNumericDocValues(recoverySourceField); if (recoverySource == null || recoverySource.nextDoc() == DocIdSetIterator.NO_MORE_DOCS) { return reader; // early terminate - nothing to do here since non of the docs has a recovery source anymore. } BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.add(new DocValuesFieldExistsQuery(recoverySourceField), BooleanClause.Occur.FILTER); builder.add(retainSourceQuerySupplier.get(), BooleanClause.Occur.FILTER); IndexSearcher s = new IndexSearcher(reader); s.setQueryCache(null); Weight weight = s.createWeight(s.rewrite(builder.build()), false, 1.0f); Scorer scorer = weight.scorer(reader.getContext()); if (scorer != null) { return new SourcePruningFilterCodecReader(recoverySourceField, reader, BitSet.of(scorer.iterator(), reader.maxDoc())); } else { return new SourcePruningFilterCodecReader(recoverySourceField, reader, null); } }
/** * Check whether there is one or more documents matching the provided query. */ public static boolean exists(IndexSearcher searcher, Query query) throws IOException { final Weight weight = searcher.createNormalizedWeight(query, false); // the scorer API should be more efficient at stopping after the first // match than the bulk scorer API for (LeafReaderContext context : searcher.getIndexReader().leaves()) { final Scorer scorer = weight.scorer(context); if (scorer == null) { continue; } final Bits liveDocs = context.reader().getLiveDocs(); final DocIdSetIterator iterator = scorer.iterator(); for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { if (liveDocs == null || liveDocs.get(doc)) { return true; } } } return false; }