0
0
Fork 0

added test for query norm

This commit is contained in:
Marty Schoch 2014-04-19 15:04:12 -04:00
parent 7fc21d6094
commit 90692be8e3
1 changed files with 85 additions and 0 deletions

View File

@ -154,3 +154,88 @@ func TestTermScorer(t *testing.T) {
}
}
func TestTermScorerWithQueryNorm(t *testing.T) {
query := TermQuery{
Term: "beer",
Field: "desc",
BoostVal: 3.0,
Explain: true,
}
var docTotal uint64 = 100
var docTerm uint64 = 9
scorer := NewTermQueryScorer(&query, docTotal, docTerm, true)
idf := 1.0 + math.Log(float64(docTotal)/float64(docTerm+1.0))
scorer.SetQueryNorm(2.0)
tests := []struct {
termMatch *index.TermFieldDoc
result *DocumentMatch
}{
{
termMatch: &index.TermFieldDoc{
ID: "one",
Freq: 1,
Norm: 1.0,
},
result: &DocumentMatch{
ID: "one",
Score: math.Sqrt(1.0) * idf * 3.0 * idf * 2.0,
Expl: &Explanation{
Value: math.Sqrt(1.0) * idf * 3.0 * idf * 2.0,
Message: "weight(desc:beer^3.000000 in one), product of:",
Children: []*Explanation{
&Explanation{
Value: 2.0 * idf * 3.0,
Message: "queryWeight(desc:beer^3.000000), product of:",
Children: []*Explanation{
&Explanation{
Value: 3,
Message: "boost",
},
&Explanation{
Value: idf,
Message: "idf(docFreq=9, maxDocs=100)",
},
&Explanation{
Value: 2,
Message: "queryNorm",
},
},
},
&Explanation{
Value: math.Sqrt(1.0) * idf,
Message: "fieldWeight(desc:beer in one), product of:",
Children: []*Explanation{
&Explanation{
Value: 1,
Message: "tf(termFreq(desc:beer)=1",
},
&Explanation{
Value: 1,
Message: "fieldNorm(field=desc, doc=one)",
},
&Explanation{
Value: idf,
Message: "idf(docFreq=9, maxDocs=100)",
},
},
},
},
},
},
},
}
for _, test := range tests {
actual := scorer.Score(test.termMatch)
if !reflect.DeepEqual(actual, test.result) {
t.Errorf("expected %#v got %#v for %#v", test.result, actual, test.termMatch)
}
}
}