Package org.apache.lucene.search
Class MinShouldMatchSumScorer
java.lang.Object
org.apache.lucene.search.Scorable
org.apache.lucene.search.Scorer
org.apache.lucene.search.MinShouldMatchSumScorer
A
Scorer for BooleanQuery when
minShouldMatch is
between 2 and the total number of clauses.
This implementation keeps sub scorers in 3 different places:
- lead: a linked list of scorer that are positioned on the desired doc ID
- tail: a heap that contains at most minShouldMatch - 1 scorers that are
behind the desired doc ID. These scorers are ordered by cost so that we
can advance the least costly ones first.
- head: a heap that contains scorers which are beyond the desired doc ID,
ordered by doc ID in order to move quickly to the next candidate.
Finding the next match consists of first setting the desired doc ID to the
least entry in 'head' and then advance 'tail' until there is a match.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.search.Scorable
Scorable.ChildScorable -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final long(package private) int(package private) int(package private) final DisiPriorityQueue(package private) DisiWrapper(package private) final int(package private) final DisiWrapper[](package private) int -
Constructor Summary
ConstructorsConstructorDescriptionMinShouldMatchSumScorer(Weight weight, Collection<Scorer> scorers, int minShouldMatch) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddLead(DisiWrapper lead) private voidAdd an entry to 'tail'.private voidprivate voidadvanceTail(DisiWrapper top) intdocID()Returns the doc ID that is currently being scored.private intdoNext()Advance tail to the lead until there is a match.private intMove iterators to the tail until the cumulated size of lead+tail is greater than or equal to minShouldMathprivate static voiddownHeapCost(DisiWrapper[] heap, int size) final Collection<Scorable.ChildScorable> Returns child sub-scorers positioned on the current documentfloatgetMaxScore(int upTo) Return the maximum score that documents between the lasttargetthat this iterator wasshallow-advancedto included andupToincluded.private DisiWrapperInsert an entry in 'tail' and evict the least-costly scorer if full.iterator()Return aDocIdSetIteratorover matching documents.private DisiWrapperpopTail()Pop the least-costly scorer from 'tail'.private voidfloatscore()Returns the score of the current document matching the query.private voidReinitializes head, freq and doc from 'head'Optional method: Return aTwoPhaseIteratorview of thisScorer.private voidAdvance all entries from the tail to know about all matches on the current doc.private static voidupHeapCost(DisiWrapper[] heap, int i) Heap helpersMethods inherited from class org.apache.lucene.search.Scorer
advanceShallow, getWeightMethods inherited from class org.apache.lucene.search.Scorable
setMinCompetitiveScore
-
Field Details
-
minShouldMatch
final int minShouldMatch -
lead
DisiWrapper lead -
doc
int doc -
freq
int freq -
head
-
tail
-
tailSize
int tailSize -
cost
final long cost
-
-
Constructor Details
-
MinShouldMatchSumScorer
MinShouldMatchSumScorer(Weight weight, Collection<Scorer> scorers, int minShouldMatch)
-
-
Method Details
-
getChildren
Description copied from class:ScorableReturns child sub-scorers positioned on the current document- Overrides:
getChildrenin classScorable- Throws:
IOException
-
iterator
Description copied from class:ScorerReturn aDocIdSetIteratorover matching documents. The returned iterator will either be positioned on-1if no documents have been scored yet,DocIdSetIterator.NO_MORE_DOCSif all documents have been scored already, or the last document id that has been scored otherwise. The returned iterator is a view: calling this method several times will return iterators that have the same state. -
twoPhaseIterator
Description copied from class:ScorerOptional method: Return aTwoPhaseIteratorview of thisScorer. A return value ofnullindicates that two-phase iteration is not supported. Note that the returnedTwoPhaseIterator'sapproximationmust advance synchronously with theScorer.iterator(): advancing the approximation must advance the iterator and vice-versa. Implementing this method is typically useful onScorers that have a high per-document overhead in order to confirm matches. The default implementation returnsnull.- Overrides:
twoPhaseIteratorin classScorer
-
addLead
-
pushBackLeads
- Throws:
IOException
-
advanceTail
- Throws:
IOException
-
advanceTail
- Throws:
IOException
-
setDocAndFreq
private void setDocAndFreq()Reinitializes head, freq and doc from 'head' -
doNext
Advance tail to the lead until there is a match.- Throws:
IOException
-
doNextCandidate
Move iterators to the tail until the cumulated size of lead+tail is greater than or equal to minShouldMath- Throws:
IOException
-
updateFreq
Advance all entries from the tail to know about all matches on the current doc.- Throws:
IOException
-
score
Description copied from class:ScorableReturns the score of the current document matching the query.- Specified by:
scorein classScorable- Throws:
IOException
-
getMaxScore
Description copied from class:ScorerReturn the maximum score that documents between the lasttargetthat this iterator wasshallow-advancedto included andupToincluded.- Specified by:
getMaxScorein classScorer- Throws:
IOException
-
docID
public int docID()Description copied from class:ScorableReturns the doc ID that is currently being scored. -
insertTailWithOverFlow
Insert an entry in 'tail' and evict the least-costly scorer if full. -
addTail
Add an entry to 'tail'. Fails if over capacity. -
popTail
Pop the least-costly scorer from 'tail'. -
upHeapCost
Heap helpers -
downHeapCost
-