public class BM25Similarity extends Similarity
Similarity.SimScorer
Modifier and Type | Field and Description |
---|---|
protected boolean |
discountOverlaps
True if overlap tokens (tokens with a position of increment of zero) are
discounted from the document's length.
|
Constructor and Description |
---|
BM25Similarity()
BM25 with these default values:
k1 = 1.2
b = 0.75
|
BM25Similarity(float k1,
float b)
BM25 with the supplied parameter values.
|
Modifier and Type | Method and Description |
---|---|
protected float |
avgFieldLength(CollectionStatistics collectionStats)
The default implementation computes the average as
sumTotalTermFreq / docCount |
long |
computeNorm(FieldInvertState state)
Computes the normalization value for a field, given the accumulated
state of term processing for this field (see
FieldInvertState ). |
float |
getB()
Returns the
b parameter |
boolean |
getDiscountOverlaps()
Returns true if overlap tokens are discounted from the document's length.
|
float |
getK1()
Returns the
k1 parameter |
protected float |
idf(long docFreq,
long docCount)
Implemented as
log(1 + (docCount - docFreq + 0.5)/(docFreq + 0.5)) . |
Explanation |
idfExplain(CollectionStatistics collectionStats,
TermStatistics termStats)
Computes a score factor for a simple term and returns an explanation
for that score factor.
|
Explanation |
idfExplain(CollectionStatistics collectionStats,
TermStatistics[] termStats)
Computes a score factor for a phrase.
|
protected float |
scorePayload(int doc,
int start,
int end,
BytesRef payload)
The default implementation returns
1 |
Similarity.SimScorer |
scorer(float boost,
CollectionStatistics collectionStats,
TermStatistics... termStats)
Compute any collection-level weight (e.g.
|
void |
setDiscountOverlaps(boolean v)
Sets whether overlap tokens (Tokens with 0 position increment) are
ignored when computing norm.
|
String |
toString() |
protected boolean discountOverlaps
public BM25Similarity(float k1, float b)
k1
- Controls non-linear term frequency normalization (saturation).b
- Controls to what degree document length normalizes tf values.IllegalArgumentException
- if k1
is infinite or negative, or if b
is
not within the range [0..1]
public BM25Similarity()
k1 = 1.2
b = 0.75
protected float idf(long docFreq, long docCount)
log(1 + (docCount - docFreq + 0.5)/(docFreq + 0.5))
.protected float scorePayload(int doc, int start, int end, BytesRef payload)
1
protected float avgFieldLength(CollectionStatistics collectionStats)
sumTotalTermFreq / docCount
public void setDiscountOverlaps(boolean v)
public boolean getDiscountOverlaps()
setDiscountOverlaps(boolean)
public final long computeNorm(FieldInvertState state)
Similarity
FieldInvertState
).
Matches in longer fields are less precise, so implementations of this
method usually set smaller values when state.getLength()
is large,
and larger values when state.getLength()
is small.
Note that for a given term-document frequency, greater unsigned norms
must produce scores that are lower or equal, ie. for two encoded norms
n1
and n2
so that
Long.compareUnsigned(n1, n2) > 0
then
SimScorer.score(freq, n1) <= SimScorer.score(freq, n2)
for any legal freq
.
0
is not a legal norm, so 1
is the norm that produces
the highest scores.
computeNorm
in class Similarity
state
- current processing state for this fieldpublic Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics termStats)
The default implementation uses:
idf(docFreq, docCount);Note that
CollectionStatistics.docCount()
is used instead of
IndexReader#numDocs()
because also
TermStatistics.docFreq()
is used, and when the latter
is inaccurate, so is CollectionStatistics.docCount()
, and in the same direction.
In addition, CollectionStatistics.docCount()
does not skew when fields are sparse.collectionStats
- collection-level statisticstermStats
- term-level statistics for the termpublic Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics[] termStats)
The default implementation sums the idf factor for each term in the phrase.
collectionStats
- collection-level statisticstermStats
- term-level statistics for the terms in the phrasepublic final Similarity.SimScorer scorer(float boost, CollectionStatistics collectionStats, TermStatistics... termStats)
Similarity
scorer
in class Similarity
boost
- a multiplicative factor to apply to the produces scorescollectionStats
- collection-level statistics, such as the number of tokens in the collection.termStats
- term-level statistics, such as the document frequency of a term across the collection.public final float getK1()
k1
parameterBM25Similarity(float, float)
public final float getB()
b
parameterBM25Similarity(float, float)
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.