package org.apache.lucene.search.similarities;
import org.apache.lucene.search.Explanation;
public class BM25Stats {
/** BM25's idf */
private final Explanation idf;
/** The average document length. */
private final float avgdl;
/** query's inner boost */
private final float queryBoost;
/** query's outer boost (only for explain) */
private float topLevelBoost;
/** weight (idf * boost) */
private float weight;
/** field name, for pulling norms */
private final String field;
/** precomputed norm[256] with k1 * ((1 - b) + b * dl / avgdl) */
private final float cache[];
BM25Stats(String field, Explanation idf, float queryBoost, float avgdl, float cache[]) {
this.field = field;
this.idf = idf;
this.queryBoost = queryBoost;
this.avgdl = avgdl;
this.cache = cache;
}
public float getValueForNormalization() {
// we return a TF-IDF like normalization to be nice, but we don't actually normalize ourselves.
final float queryWeight = idf.getValue() * queryBoost;
return queryWeight * queryWeight;
}
public void normalize(float queryNorm, float topLevelBoost) {
// we don't normalize with queryNorm at all, we just capture the top-level boost
this.topLevelBoost = topLevelBoost;
this.weight = idf.getValue() * queryBoost * topLevelBoost;
}
}