final class WANDScorer extends Scorer
max score
from each scorer in order to know when it may call
DocIdSetIterator.advance(int)
rather than DocIdSetIterator.nextDoc()
to move to the next competitive hit.
Implementation is similar to MinShouldMatchSumScorer
except that
instead of enforcing that freq >= minShouldMatch
, we enforce that
∑ max_score >= minCompetitiveScore
.Scorable.ChildScorable
Modifier and Type | Field and Description |
---|---|
(package private) long |
cost |
(package private) int |
doc |
(package private) DisiPriorityQueue |
head |
(package private) DisiWrapper |
lead |
(package private) long |
leadMaxScore |
(package private) MaxScoreSumPropagator |
maxScorePropagator |
private long |
minCompetitiveScore |
private int |
scalingFactor |
(package private) DisiWrapper[] |
tail |
(package private) long |
tailMaxScore |
(package private) int |
tailSize |
(package private) int |
upTo |
Constructor and Description |
---|
WANDScorer(Weight weight,
java.util.Collection<Scorer> scorers) |
Modifier and Type | Method and Description |
---|---|
private void |
addLead(DisiWrapper lead)
Add a disi to the linked list of leads.
|
private void |
addTail(DisiWrapper s)
Add an entry to 'tail'.
|
private void |
advanceAllTail()
Advance all entries from the tail to know about all matches on the
current doc.
|
private void |
advanceHead(int target)
Make sure all disis in 'head' are on or after 'target'.
|
int |
advanceShallow(int target)
Advance to the block of documents that contains
target in order to
get scoring information about this block. |
private void |
advanceTail()
Pop the entry from the 'tail' that has the greatest score contribution,
advance it to the current doc and then add it to 'lead' or 'head'
depending on whether it matches.
|
private void |
advanceTail(DisiWrapper disi) |
int |
docID()
Returns the doc ID that is currently being scored.
|
private int |
doNextCompetitiveCandidate()
Move iterators to the tail until there is a potential match.
|
private static void |
downHeapMaxScore(DisiWrapper[] heap,
int size) |
private boolean |
ensureConsistent() |
java.util.Collection<Scorable.ChildScorable> |
getChildren()
Returns child sub-scorers positioned on the current document
|
float |
getMaxScore(int upTo)
Return the maximum score that documents between the last
target
that this iterator was shallow-advanced to
included and upTo included. |
private static boolean |
greaterMaxScore(DisiWrapper w1,
DisiWrapper w2)
In the tail, we want to get first entries that produce the maximum scores
and in case of ties (eg.
|
private DisiWrapper |
insertTailWithOverFlow(DisiWrapper s)
Insert an entry in 'tail' and evict the least-costly scorer if full.
|
DocIdSetIterator |
iterator()
Return a
DocIdSetIterator over matching documents. |
private void |
moveToNextCandidate(int target)
Set 'doc' to the next potential match, and move all disis of 'head' that
are on this doc into 'lead'.
|
private DisiWrapper |
popTail()
Pop the least-costly scorer from 'tail'.
|
private void |
pushBackLeads(int target)
Move disis that are in 'lead' back to the tail.
|
private static long |
scaleMaxScore(float maxScore,
int scalingFactor)
Scale max scores in an unsigned integer to avoid overflows
(only the lower 32 bits of the long are used) as well as
floating-point arithmetic errors.
|
private static long |
scaleMinScore(float minScore,
int scalingFactor)
Scale min competitive scores the same way as max scores but this time
by rounding down in order to make sure that we do not miss any matches.
|
(package private) static int |
scalingFactor(float f)
Return a scaling factor for the given float so that
f x 2^scalingFactor would be in ]2^15, 2^16].
|
float |
score()
Returns the score of the current document matching the query.
|
void |
setMinCompetitiveScore(float minScore)
Optional method: Tell the scorer that its iterator may safely ignore all
documents whose score is less than the given
minScore . |
TwoPhaseIterator |
twoPhaseIterator()
Optional method: Return a
TwoPhaseIterator view of this
Scorer . |
private void |
updateMaxScores(int target) |
private void |
updateMaxScoresIfNecessary(int target) |
private static void |
upHeapMaxScore(DisiWrapper[] heap,
int i)
Heap helpers
|
private final int scalingFactor
private long minCompetitiveScore
DisiWrapper lead
int doc
long leadMaxScore
final DisiPriorityQueue head
final DisiWrapper[] tail
long tailMaxScore
int tailSize
final long cost
final MaxScoreSumPropagator maxScorePropagator
int upTo
static int scalingFactor(float f)
private static long scaleMaxScore(float maxScore, int scalingFactor)
private static long scaleMinScore(float minScore, int scalingFactor)
private boolean ensureConsistent()
public void setMinCompetitiveScore(float minScore) throws java.io.IOException
Scorable
minScore
. This is a
no-op by default.
This method may only be called from collectors that use
ScoreMode.TOP_SCORES
, and successive calls may only set increasing
values of minScore
.setMinCompetitiveScore
in class Scorable
java.io.IOException
public final java.util.Collection<Scorable.ChildScorable> getChildren() throws java.io.IOException
Scorable
getChildren
in class Scorable
java.io.IOException
public DocIdSetIterator iterator()
Scorer
DocIdSetIterator
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.public TwoPhaseIterator twoPhaseIterator()
Scorer
TwoPhaseIterator
view of this
Scorer
. A return value of null
indicates that
two-phase iteration is not supported.
Note that the returned TwoPhaseIterator
's
approximation
must
advance synchronously with the Scorer.iterator()
: advancing the
approximation must advance the iterator and vice-versa.
Implementing this method is typically useful on Scorer
s
that have a high per-document overhead in order to confirm matches.
The default implementation returns null
.twoPhaseIterator
in class Scorer
private void addLead(DisiWrapper lead)
private void pushBackLeads(int target) throws java.io.IOException
java.io.IOException
private void advanceHead(int target) throws java.io.IOException
java.io.IOException
private void advanceTail(DisiWrapper disi) throws java.io.IOException
java.io.IOException
private void advanceTail() throws java.io.IOException
java.io.IOException
private void updateMaxScores(int target) throws java.io.IOException
java.io.IOException
private void updateMaxScoresIfNecessary(int target) throws java.io.IOException
java.io.IOException
private void moveToNextCandidate(int target) throws java.io.IOException
java.io.IOException
private int doNextCompetitiveCandidate() throws java.io.IOException
java.io.IOException
private void advanceAllTail() throws java.io.IOException
java.io.IOException
public float score() throws java.io.IOException
Scorable
public int advanceShallow(int target) throws java.io.IOException
Scorer
target
in order to
get scoring information about this block. This method is implicitly called
by DocIdSetIterator.advance(int)
and
DocIdSetIterator.nextDoc()
on the returned doc ID. Calling this
method doesn't modify the current DocIdSetIterator.docID()
.
It returns a number that is greater than or equal to all documents
contained in the current block, but less than any doc IDS of the next block.
target
must be >= Scorable.docID()
as well as all targets that
have been passed to Scorer.advanceShallow(int)
so far.advanceShallow
in class Scorer
java.io.IOException
public float getMaxScore(int upTo) throws java.io.IOException
Scorer
target
that this iterator was shallow-advanced
to
included and upTo
included.getMaxScore
in class Scorer
java.io.IOException
public int docID()
Scorable
private DisiWrapper insertTailWithOverFlow(DisiWrapper s)
private void addTail(DisiWrapper s)
private DisiWrapper popTail()
private static void upHeapMaxScore(DisiWrapper[] heap, int i)
private static void downHeapMaxScore(DisiWrapper[] heap, int size)
private static boolean greaterMaxScore(DisiWrapper w1, DisiWrapper w2)