mirror of https://github.com/apache/lucene.git
LUCENE-5221: SimilarityBase.computeNorm is inconsistent with TFIDFSimilarity
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1524457 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
60e7475519
commit
3eb1e1ac54
|
@ -193,6 +193,10 @@ Bug Fixes
|
||||||
* LUCENE-5201: Fixed compression bug in LZ4.compressHC when the input is highly
|
* LUCENE-5201: Fixed compression bug in LZ4.compressHC when the input is highly
|
||||||
compressible and the start offset of the array to compress is > 0.
|
compressible and the start offset of the array to compress is > 0.
|
||||||
(Adrien Grand)
|
(Adrien Grand)
|
||||||
|
|
||||||
|
* LUCENE-5221: SimilarityBase did not write norms the same way as DefaultSimilarity
|
||||||
|
if discountOverlaps == false and index-time boosts are present for the field.
|
||||||
|
(Yubin Kim via Robert Muir)
|
||||||
|
|
||||||
API Changes
|
API Changes
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ public abstract class SimilarityBase extends Similarity {
|
||||||
if (discountOverlaps)
|
if (discountOverlaps)
|
||||||
numTerms = state.getLength() - state.getNumOverlap();
|
numTerms = state.getLength() - state.getNumOverlap();
|
||||||
else
|
else
|
||||||
numTerms = state.getLength() / state.getBoost();
|
numTerms = state.getLength();
|
||||||
return encodeNormValue(state.getBoost(), numTerms);
|
return encodeNormValue(state.getBoost(), numTerms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.document.TextField;
|
import org.apache.lucene.document.TextField;
|
||||||
|
import org.apache.lucene.index.FieldInvertState;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.RandomIndexWriter;
|
import org.apache.lucene.index.RandomIndexWriter;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
|
@ -572,4 +573,20 @@ public class TestSimilarityBase extends LuceneTestCase {
|
||||||
dir.close();
|
dir.close();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LUCENE-5221
|
||||||
|
public void testDiscountOverlapsBoost() throws IOException {
|
||||||
|
DefaultSimilarity expected = new DefaultSimilarity();
|
||||||
|
SimilarityBase actual = new DFRSimilarity(new BasicModelIne(), new AfterEffectB(), new NormalizationH2());
|
||||||
|
expected.setDiscountOverlaps(false);
|
||||||
|
actual.setDiscountOverlaps(false);
|
||||||
|
FieldInvertState state = new FieldInvertState("foo");
|
||||||
|
state.setLength(5);
|
||||||
|
state.setNumOverlap(2);
|
||||||
|
state.setBoost(3);
|
||||||
|
assertEquals(expected.computeNorm(state), actual.computeNorm(state));
|
||||||
|
expected.setDiscountOverlaps(true);
|
||||||
|
actual.setDiscountOverlaps(true);
|
||||||
|
assertEquals(expected.computeNorm(state), actual.computeNorm(state));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue