2014-07-30 18:30:38 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
2014-09-01 17:15:38 +02:00
|
|
|
|
|
|
|
package simple
|
2014-06-26 17:43:13 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2014-09-01 17:15:38 +02:00
|
|
|
|
|
|
|
"github.com/blevesearch/bleve/search"
|
|
|
|
"github.com/blevesearch/bleve/search/highlight"
|
2014-06-26 17:43:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSimpleFragmentScorer(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct {
|
2014-09-01 17:15:38 +02:00
|
|
|
fragment *highlight.Fragment
|
|
|
|
tlm search.TermLocationMap
|
2014-06-26 17:43:13 +02:00
|
|
|
score float64
|
|
|
|
}{
|
|
|
|
{
|
2014-09-01 17:15:38 +02:00
|
|
|
fragment: &highlight.Fragment{
|
|
|
|
Orig: []byte("cat in the hat"),
|
|
|
|
Start: 0,
|
|
|
|
End: 14,
|
2014-06-26 17:43:13 +02:00
|
|
|
},
|
2014-09-01 17:15:38 +02:00
|
|
|
tlm: search.TermLocationMap{
|
|
|
|
"cat": search.Locations{
|
|
|
|
&search.Location{
|
2014-06-26 17:43:13 +02:00
|
|
|
Pos: 0,
|
|
|
|
Start: 0,
|
|
|
|
End: 3,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
score: 1,
|
|
|
|
},
|
|
|
|
{
|
2014-09-01 17:15:38 +02:00
|
|
|
fragment: &highlight.Fragment{
|
|
|
|
Orig: []byte("cat in the hat"),
|
|
|
|
Start: 0,
|
|
|
|
End: 14,
|
2014-06-26 17:43:13 +02:00
|
|
|
},
|
2014-09-01 17:15:38 +02:00
|
|
|
tlm: search.TermLocationMap{
|
|
|
|
"cat": search.Locations{
|
|
|
|
&search.Location{
|
2014-06-26 17:43:13 +02:00
|
|
|
Pos: 1,
|
|
|
|
Start: 0,
|
|
|
|
End: 3,
|
|
|
|
},
|
|
|
|
},
|
2014-09-01 17:15:38 +02:00
|
|
|
"hat": search.Locations{
|
|
|
|
&search.Location{
|
2014-06-26 17:43:13 +02:00
|
|
|
Pos: 4,
|
|
|
|
Start: 11,
|
|
|
|
End: 14,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
score: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
scorer := NewSimpleFragmentScorer(test.tlm)
|
|
|
|
scorer.Score(test.fragment)
|
2014-09-01 17:15:38 +02:00
|
|
|
if test.fragment.Score != test.score {
|
|
|
|
t.Errorf("expected score %f, got %f", test.score, test.fragment.Score)
|
2014-06-26 17:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|