Class StableTflSimilarity
java.lang.Object
org.apache.lucene.search.similarities.Similarity
org.apache.lucene.search.similarities.StableTflSimilarity
StableTfl Similarity. A similarity algorithm that estimates term rarity based on term length and
document length, rather than relying on corpus-level statistics like document frequency.
Inspired by BM25, this similarity model replaces IDF with a synthetic function that increases with term length (as a proxy for rarity) and adjusts based on document length.
Scoring formula:
tf = freq / (freq + k1) p = 1 - (1 - m * 2 ^ (-c * |t|)) ^ |d| tr = log(1 + (1 - p + 0.05) / (p + 0.05)) score = boost * tr * tf
This similarity is parameterized by:
k1- saturation parameter for term frequencyc- decay constant controlling how term length impacts rarity
The constant m is fixed internally and controls the base term-match probability.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.search.similarities.Similarity
Similarity.BulkSimScorer, Similarity.SimScorer -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatEmpirical value of c derived from modeling term frequency in English corpuses.static final floatDefault k1 value used in Lucene's implementation of BM25. -
Constructor Summary
ConstructorsConstructorDescriptionStableTFL with these default values:k1 = 1.2c = 0.917StableTflSimilarity(float k1, float c) StableTFL with the supplied parameter values. -
Method Summary
Modifier and TypeMethodDescriptionfinal floatgetC()Returns thecparameter.final floatgetK1()Returns thek1parameter.final Similarity.SimScorerscorer(float boost, CollectionStatistics fieldStats, TermStatistics... termStats) Compute any collection-level weight (e.g.toString()Methods inherited from class org.apache.lucene.search.similarities.Similarity
computeNorm, getDiscountOverlaps
-
Field Details
-
DEFAULT_K1
public static final float DEFAULT_K1Default k1 value used in Lucene's implementation of BM25.- See Also:
-
DEFAULT_C
public static final float DEFAULT_CEmpirical value of c derived from modeling term frequency in English corpuses.- See Also:
-
-
Constructor Details
-
StableTflSimilarity
public StableTflSimilarity(float k1, float c) StableTFL with the supplied parameter values.- Parameters:
k1- Controls non-linear term frequency normalization (saturation).c- Controls how much term length affects term rarity (decay constant).- Throws:
IllegalArgumentException- ifk1is infinite or negativeIllegalArgumentException- ifcis infinite or negative
-
StableTflSimilarity
public StableTflSimilarity()StableTFL with these default values:k1 = 1.2c = 0.917
-
-
Method Details
-
scorer
public final Similarity.SimScorer scorer(float boost, CollectionStatistics fieldStats, TermStatistics... termStats) Description copied from class:SimilarityCompute any collection-level weight (e.g. IDF, average document length, etc) needed for scoring a query.- Specified by:
scorerin classSimilarity- Parameters:
boost- a multiplicative factor to apply to the produces scoresfieldStats- 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.- Returns:
- SimWeight object with the information this Similarity needs to score a query.
-
getK1
public final float getK1()Returns thek1parameter.- See Also:
-
getC
public final float getC()Returns thecparameter.- See Also:
-
toString
-