@@ -61,7 +61,7 @@ func TestSuggest(t *testing.T) {
6161 terms := make ([]Suggestion , 10 )
6262 for i := 0 ; i < 10 ; i ++ {
6363 terms [i ] = Suggestion {Term : fmt .Sprintf ("foo %d" , i ),
64- Score : 1.0 , Payload : fmt .Sprintf ("bar %d" , i )}
64+ Score : 1.0 , Payload : fmt .Sprintf ("bar %d" , i ), Incr : true }
6565 }
6666 err := a .AddTerms (terms ... )
6767 assert .Nil (t , err )
@@ -87,4 +87,26 @@ func TestSuggest(t *testing.T) {
8787 assert .Contains (t , suggestion .Payload , "bar" )
8888 assert .NotZero (t , suggestion .Score )
8989 }
90+
91+ // Ensure score is incremented according to INCR
92+ oldScore := suggestions [0 ].Score
93+
94+ err = a .AddTerms (terms ... )
95+ suggestions , err = a .SuggestOpts ("f" , SuggestOptions {Num : 10 , WithScores : true , WithPayloads : true })
96+ assert .Nil (t , err )
97+ for _ , suggestion := range suggestions {
98+ assert .Greater (t , suggestion .Score , oldScore )
99+ }
100+
101+ // Now, replace scores by disabling INCR
102+ for i := 0 ; i < len (terms ); i ++ {
103+ terms [i ].Incr = false
104+ }
105+
106+ err = a .AddTerms (terms ... )
107+ suggestions , err = a .SuggestOpts ("f" , SuggestOptions {Num : 10 , WithScores : true , WithPayloads : true })
108+ assert .Nil (t , err )
109+ for _ , suggestion := range suggestions {
110+ assert .Equal (t , suggestion .Score , oldScore )
111+ }
90112}
0 commit comments