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
-
final class MinShouldMatchSumScorer extends Scorer
AScorer
forBooleanQuery
whenminShouldMatch
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
Fields Modifier and Type Field Description (package private) long
cost
(package private) int
doc
(package private) int
freq
(package private) DisiPriorityQueue
head
(package private) DisiWrapper
lead
(package private) int
minShouldMatch
(package private) DisiWrapper[]
tail
(package private) int
tailSize
-
Constructor Summary
Constructors Constructor Description MinShouldMatchSumScorer(Weight weight, java.util.Collection<Scorer> scorers, int minShouldMatch)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addLead(DisiWrapper lead)
private void
addTail(DisiWrapper s)
Add an entry to 'tail'.private void
advanceTail()
private void
advanceTail(DisiWrapper top)
int
docID()
Returns the doc ID that is currently being scored.private int
doNext()
Advance tail to the lead until there is a match.private int
doNextCandidate()
Move iterators to the tail until the cumulated size of lead+tail is greater than or equal to minShouldMathprivate static void
downHeapCost(DisiWrapper[] heap, int size)
java.util.Collection<Scorable.ChildScorable>
getChildren()
Returns child sub-scorers positioned on the current documentfloat
getMaxScore(int upTo)
Return the maximum score that documents between the lasttarget
that this iterator wasshallow-advanced
to included andupTo
included.private DisiWrapper
insertTailWithOverFlow(DisiWrapper s)
Insert an entry in 'tail' and evict the least-costly scorer if full.DocIdSetIterator
iterator()
Return aDocIdSetIterator
over matching documents.private DisiWrapper
popTail()
Pop the least-costly scorer from 'tail'.private void
pushBackLeads()
float
score()
Returns the score of the current document matching the query.private void
setDocAndFreq()
Reinitializes head, freq and doc from 'head'TwoPhaseIterator
twoPhaseIterator()
Optional method: Return aTwoPhaseIterator
view of thisScorer
.private void
updateFreq()
Advance all entries from the tail to know about all matches on the current doc.private static void
upHeapCost(DisiWrapper[] heap, int i)
Heap helpers-
Methods inherited from class org.apache.lucene.search.Scorer
advanceShallow, getWeight
-
Methods inherited from class org.apache.lucene.search.Scorable
setMinCompetitiveScore
-
-
-
-
Field Detail
-
minShouldMatch
final int minShouldMatch
-
lead
DisiWrapper lead
-
doc
int doc
-
freq
int freq
-
head
final DisiPriorityQueue head
-
tail
final DisiWrapper[] tail
-
tailSize
int tailSize
-
cost
final long cost
-
-
Method Detail
-
getChildren
public final java.util.Collection<Scorable.ChildScorable> getChildren() throws java.io.IOException
Description copied from class:Scorable
Returns child sub-scorers positioned on the current document- Overrides:
getChildren
in classScorable
- Throws:
java.io.IOException
-
iterator
public DocIdSetIterator iterator()
Description copied from class:Scorer
Return aDocIdSetIterator
over matching documents. The returned iterator will either be positioned on-1
if no documents have been scored yet,DocIdSetIterator.NO_MORE_DOCS
if 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
public TwoPhaseIterator twoPhaseIterator()
Description copied from class:Scorer
Optional method: Return aTwoPhaseIterator
view of thisScorer
. A return value ofnull
indicates that two-phase iteration is not supported. Note that the returnedTwoPhaseIterator
'sapproximation
must advance synchronously with theScorer.iterator()
: advancing the approximation must advance the iterator and vice-versa. Implementing this method is typically useful onScorer
s that have a high per-document overhead in order to confirm matches. The default implementation returnsnull
.- Overrides:
twoPhaseIterator
in classScorer
-
addLead
private void addLead(DisiWrapper lead)
-
pushBackLeads
private void pushBackLeads() throws java.io.IOException
- Throws:
java.io.IOException
-
advanceTail
private void advanceTail(DisiWrapper top) throws java.io.IOException
- Throws:
java.io.IOException
-
advanceTail
private void advanceTail() throws java.io.IOException
- Throws:
java.io.IOException
-
setDocAndFreq
private void setDocAndFreq()
Reinitializes head, freq and doc from 'head'
-
doNext
private int doNext() throws java.io.IOException
Advance tail to the lead until there is a match.- Throws:
java.io.IOException
-
doNextCandidate
private int doNextCandidate() throws java.io.IOException
Move iterators to the tail until the cumulated size of lead+tail is greater than or equal to minShouldMath- Throws:
java.io.IOException
-
updateFreq
private void updateFreq() throws java.io.IOException
Advance all entries from the tail to know about all matches on the current doc.- Throws:
java.io.IOException
-
score
public float score() throws java.io.IOException
Description copied from class:Scorable
Returns the score of the current document matching the query.
-
getMaxScore
public float getMaxScore(int upTo) throws java.io.IOException
Description copied from class:Scorer
Return the maximum score that documents between the lasttarget
that this iterator wasshallow-advanced
to included andupTo
included.- Specified by:
getMaxScore
in classScorer
- Throws:
java.io.IOException
-
docID
public int docID()
Description copied from class:Scorable
Returns the doc ID that is currently being scored.
-
insertTailWithOverFlow
private DisiWrapper insertTailWithOverFlow(DisiWrapper s)
Insert an entry in 'tail' and evict the least-costly scorer if full.
-
addTail
private void addTail(DisiWrapper s)
Add an entry to 'tail'. Fails if over capacity.
-
popTail
private DisiWrapper popTail()
Pop the least-costly scorer from 'tail'.
-
upHeapCost
private static void upHeapCost(DisiWrapper[] heap, int i)
Heap helpers
-
downHeapCost
private static void downHeapCost(DisiWrapper[] heap, int size)
-
-