mirror of https://github.com/apache/lucene.git
LUCENE-8024: Remove unnecessary norms.advanceExact check in score()
This commit is contained in:
parent
148d81c1e9
commit
42c49c25d6
|
@ -230,11 +230,9 @@ public class BM25Similarity extends Similarity {
|
|||
if (norms == null) {
|
||||
norm = k1;
|
||||
} else {
|
||||
if (norms.advanceExact(doc)) {
|
||||
norm = cache[((byte) norms.longValue()) & 0xFF];
|
||||
} else {
|
||||
norm = cache[0];
|
||||
}
|
||||
boolean found = norms.advanceExact(doc);
|
||||
assert found;
|
||||
norm = cache[((byte) norms.longValue()) & 0xFF];
|
||||
}
|
||||
return weightValue * (float) (freq / (freq + norm));
|
||||
}
|
||||
|
@ -259,12 +257,9 @@ public class BM25Similarity extends Similarity {
|
|||
(float) (freq.getValue() / (freq.getValue() + (double) k1)),
|
||||
"tf, computed as freq / (freq + k1) from:", subs);
|
||||
} else {
|
||||
byte norm;
|
||||
if (norms.advanceExact(doc)) {
|
||||
norm = (byte) norms.longValue();
|
||||
} else {
|
||||
norm = 0;
|
||||
}
|
||||
boolean found = norms.advanceExact(doc);
|
||||
assert found;
|
||||
byte norm = (byte) norms.longValue();
|
||||
float doclen = lengthCache[norm & 0xff];
|
||||
subs.add(Explanation.match(b, "b, length normalization parameter"));
|
||||
if ((norm & 0xFF) > 39) {
|
||||
|
|
|
@ -265,16 +265,13 @@ public abstract class SimilarityBase extends Similarity {
|
|||
if (norms == null) {
|
||||
return 1D;
|
||||
}
|
||||
if (norms.advanceExact(doc)) {
|
||||
return LENGTH_TABLE[Byte.toUnsignedInt((byte) norms.longValue())];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
boolean found = norms.advanceExact(doc);
|
||||
assert found;
|
||||
return LENGTH_TABLE[Byte.toUnsignedInt((byte) norms.longValue())];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score(int doc, float freq) throws IOException {
|
||||
// We have to supply something in case norms are omitted
|
||||
return (float) SimilarityBase.this.score(stats, freq, getLengthValue(doc));
|
||||
}
|
||||
|
||||
|
|
|
@ -583,12 +583,9 @@ public abstract class TFIDFSimilarity extends Similarity {
|
|||
if (norms == null) {
|
||||
return raw;
|
||||
} else {
|
||||
float normValue;
|
||||
if (norms.advanceExact(doc)) {
|
||||
normValue = normTable[(int) (norms.longValue() & 0xFF)];
|
||||
} else {
|
||||
normValue = 0;
|
||||
}
|
||||
boolean found = norms.advanceExact(doc);
|
||||
assert found;
|
||||
float normValue = normTable[(int) (norms.longValue() & 0xFF)];
|
||||
return raw * normValue; // normalize for field
|
||||
}
|
||||
}
|
||||
|
@ -629,27 +626,6 @@ public abstract class TFIDFSimilarity extends Similarity {
|
|||
}
|
||||
}
|
||||
|
||||
private Explanation explainField(int doc, Explanation freq, IDFStats stats, NumericDocValues norms, float[] normTable) throws IOException {
|
||||
Explanation tfExplanation = Explanation.match(tf(freq.getValue()), "tf(freq="+freq.getValue()+"), with freq of:", freq);
|
||||
float norm;
|
||||
if (norms == null) {
|
||||
norm = 1f;
|
||||
} else if (norms.advanceExact(doc) == false) {
|
||||
norm = 0f;
|
||||
} else {
|
||||
norm = normTable[(int) (norms.longValue() & 0xFF)];
|
||||
}
|
||||
|
||||
Explanation fieldNormExpl = Explanation.match(
|
||||
norm,
|
||||
"fieldNorm(doc=" + doc + ")");
|
||||
|
||||
return Explanation.match(
|
||||
tfExplanation.getValue() * fieldNormExpl.getValue(),
|
||||
"fieldWeight in " + doc + ", product of:",
|
||||
tfExplanation, fieldNormExpl);
|
||||
}
|
||||
|
||||
private Explanation explainScore(int doc, Explanation freq, IDFStats stats, NumericDocValues norms, float[] normTable) throws IOException {
|
||||
List<Explanation> subs = new ArrayList<Explanation>();
|
||||
if (stats.boost != 1F) {
|
||||
|
@ -662,9 +638,9 @@ public abstract class TFIDFSimilarity extends Similarity {
|
|||
float norm;
|
||||
if (norms == null) {
|
||||
norm = 1f;
|
||||
} else if (norms.advanceExact(doc) == false) {
|
||||
norm = 0f;
|
||||
} else {
|
||||
boolean found = norms.advanceExact(doc);
|
||||
assert found;
|
||||
norm = normTable[(int) (norms.longValue() & 0xFF)];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue