public void testSweetSpotComputeNorm() {
final SweetSpotSimilarity ss = new SweetSpotSimilarity();
ss.setLengthNormFactors(1,1,0.5f,true);
Similarity d = new DefaultSimilarity();
Similarity s = ss;
// base case, should degrade
FieldInvertState invertState = new FieldInvertState("bogus");
invertState.setBoost(1.0f);
for (int i = 1; i < 1000; i++) {
invertState.setLength(i);
assertEquals("base case: i="+i,
computeAndGetNorm(d, invertState),
computeAndGetNorm(s, invertState),
0.0f);
}
// make a sweet spot
ss.setLengthNormFactors(3,10,0.5f,true);
for (int i = 3; i <=10; i++) {
invertState.setLength(i);
assertEquals("3,10: spot i="+i,
1.0f,
computeAndDecodeNorm(ss, ss, invertState),
0.0f);
}
for (int i = 10; i < 1000; i++) {
invertState.setLength(i-9);
final byte normD = computeAndGetNorm(d, invertState);
invertState.setLength(i);
final byte normS = computeAndGetNorm(s, invertState);
assertEquals("3,10: 10<x : i="+i,
normD,
normS,
0.0f);
}
// separate sweet spot for certain fields
final SweetSpotSimilarity ssBar = new SweetSpotSimilarity();
ssBar.setLengthNormFactors(8,13, 0.5f, false);
final SweetSpotSimilarity ssYak = new SweetSpotSimilarity();
ssYak.setLengthNormFactors(6,9, 0.5f, false);
final SweetSpotSimilarity ssA = new SweetSpotSimilarity();
ssA.setLengthNormFactors(5,8,0.5f, false);
final SweetSpotSimilarity ssB = new SweetSpotSimilarity();
ssB.setLengthNormFactors(5,8,0.1f, false);
Similarity sp = new PerFieldSimilarityWrapper() {
@Override
public Similarity get(String field) {
if (field.equals("bar"))
return ssBar;
else if (field.equals("yak"))