2014-07-30 18:30:38 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
2016-10-02 16:13:14 +02:00
|
|
|
//
|
|
|
|
// 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{
|
2016-04-03 05:54:36 +02:00
|
|
|
"cat": []*search.Location{
|
2016-04-03 06:03:33 +02:00
|
|
|
{
|
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{
|
2016-04-03 05:54:36 +02:00
|
|
|
"cat": []*search.Location{
|
2016-04-03 06:03:33 +02:00
|
|
|
{
|
2014-06-26 17:43:13 +02:00
|
|
|
Pos: 1,
|
|
|
|
Start: 0,
|
|
|
|
End: 3,
|
|
|
|
},
|
|
|
|
},
|
2016-04-03 05:54:36 +02:00
|
|
|
"hat": []*search.Location{
|
2016-04-03 06:03:33 +02:00
|
|
|
{
|
2014-06-26 17:43:13 +02:00
|
|
|
Pos: 4,
|
|
|
|
Start: 11,
|
|
|
|
End: 14,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
score: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2014-09-04 01:16:46 +02:00
|
|
|
scorer := NewFragmentScorer(test.tlm)
|
2014-06-26 17:43:13 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|