/** Returns the score of the current document matching the query. * Initially invalid, until the {@link #iterator()} is advanced the first time. * @return The score of the required scorer, eventually increased by the score * of the optional scorer when it also matches the current document. */ @Override public float score() throws IOException { // TODO: sum into a double and cast to float if we ever send required clauses to BS1 int curDoc = reqScorer.docID(); float score = reqScorer.score(); int optScorerDoc = optIterator.docID(); if (optScorerDoc < curDoc) { optScorerDoc = optIterator.advance(curDoc); } if (optScorerDoc == curDoc) { score += optScorer.score(); } return score; }
/** * 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; }
/** Sole constructor. */ public DefaultBulkScorer(Scorer scorer) { if (scorer == null) { throw new NullPointerException(); } this.scorer = scorer; this.iterator = scorer.iterator(); this.twoPhase = scorer.twoPhaseIterator(); }
/** Construct a <code>ReqExclScorer</code>. * @param reqScorer The scorer that must match, except where * @param exclScorer indicates exclusion. */ public ReqExclScorer(Scorer reqScorer, Scorer exclScorer) { super(reqScorer.weight); this.reqScorer = reqScorer; reqTwoPhaseIterator = reqScorer.twoPhaseIterator(); if (reqTwoPhaseIterator == null) { reqApproximation = reqScorer.iterator(); } else { reqApproximation = reqTwoPhaseIterator.approximation(); } exclTwoPhaseIterator = exclScorer.twoPhaseIterator(); if (exclTwoPhaseIterator == null) { exclApproximation = exclScorer.iterator(); } else { exclApproximation = exclTwoPhaseIterator.approximation(); } }
/** * 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(); } }
limit = Integer.MAX_VALUE; final IndexSearcher searcher = new IndexSearcher(readerContext.reader()); searcher.setQueryCache(null); 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(); if (segState.rld.sortMap != null && limit != Integer.MAX_VALUE) { assert privateSegment != null; while ((docID = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { while ((docID = it.nextDoc()) < limit) { if (segState.rld.delete(docID)) { delCount++;
/** * 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; }
List<LeafReaderContext> leaves = searcher.getIndexReader().leaves(); Query rewritten = searcher.rewrite(query); Weight weight = searcher.createWeight(rewritten, true, 1); scorer = weight.scorer(readerContext); int actualDoc = scorer.docID(); if (actualDoc < targetDoc) { actualDoc = scorer.iterator().advance(targetDoc); hit.score = combine(hit.score, true, scorer.score()); } else {
DocIdSetIterator scorerIt = null; if (needsScores) { Scorer scorer = weight.scorer(entry.context); if (scorer != null) { scorerIt = scorer.iterator(); subCollector.setScorer(scorer); while ((docID = docIdSetIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (needsScores) { assert scorerIt != null && scorerIt.docID() < docID; scorerIt.advance(docID); assert scorerIt.docID() == docID;
/** * {@inheritDoc} */ public ScoreNode nextScoreNode() throws IOException { if (scorer == null) { return null; } int doc = scorer.nextDoc(); if (doc == DocIdSetIterator.NO_MORE_DOCS) { return null; } String uuid = reader.document(doc).get(FieldNames.UUID); return new ScoreNode(uuid, scorer.score(), doc); }
@Override protected float score(DisiWrapper topList) throws IOException { double score = 0; for (DisiWrapper w = topList; w != null; w = w.next) { score += w.scorer.score(); } return (float)score; } }
@Override public int numDeletesToMerge(SegmentCommitInfo info, int delCount, IOSupplier<CodecReader> readerSupplier) throws IOException { final int numDeletesToMerge = super.numDeletesToMerge(info, delCount, readerSupplier); if (numDeletesToMerge != 0 && info.getSoftDelCount() > 0) { final CodecReader reader = readerSupplier.get(); if (reader.getLiveDocs() != null) { BooleanQuery.Builder builder = new BooleanQuery.Builder(); builder.add(new DocValuesFieldExistsQuery(field), BooleanClause.Occur.FILTER); builder.add(retentionQuerySupplier.get(), BooleanClause.Occur.FILTER); Scorer scorer = getScorer(builder.build(), FilterCodecReader.wrapLiveDocs(reader, null, reader.maxDoc())); if (scorer != null) { DocIdSetIterator iterator = scorer.iterator(); Bits liveDocs = reader.getLiveDocs(); int numDeletedDocs = reader.numDeletedDocs(); while (iterator.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { if (liveDocs.get(iterator.docID()) == false) { numDeletedDocs--; } } return numDeletedDocs; } } } assert numDeletesToMerge >= 0 : "numDeletesToMerge: " + numDeletesToMerge; assert numDeletesToMerge <= info.info.maxDoc() : "numDeletesToMerge: " + numDeletesToMerge + " maxDoc:" + info.info.maxDoc(); return numDeletesToMerge; } }
public DisiWrapper(Scorer scorer) { this.scorer = scorer; this.spans = null; this.iterator = scorer.iterator(); this.cost = iterator.cost(); this.doc = -1; this.twoPhaseView = scorer.twoPhaseIterator(); if (twoPhaseView != null) { approximation = twoPhaseView.approximation(); matchCost = twoPhaseView.matchCost(); } else { approximation = iterator; matchCost = 0f; } }
@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; } }; }
BooleanClause c = cIter.next(); if (c.isProhibited()) { Scorer scorer = w.scorer(context); if (scorer != null) { prohibited.add(scorer); ? prohibited.get(0) : new DisjunctionSumScorer(this, prohibited, false); if (prohibitedScorer.twoPhaseIterator() != null) { return new ReqExclBulkScorer(positiveScorer, prohibitedScorer.iterator());
@Override public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException { collector.setScorer(scorer); if (scorer.docID() == -1 && min == 0 && max == DocIdSetIterator.NO_MORE_DOCS) { scoreAll(collector, iterator, twoPhase, acceptDocs); return DocIdSetIterator.NO_MORE_DOCS; } else { int doc = scorer.docID(); if (doc < min) { if (twoPhase == null) { doc = iterator.advance(min); } else { doc = twoPhase.approximation().advance(min); } } return scoreRange(collector, iterator, twoPhase, acceptDocs, doc, max); } }