|
|
@@ -3,7 +3,6 @@ package core
|
|
|
import (
|
|
|
"testing"
|
|
|
|
|
|
- "github.com/huichen/wukong/engine"
|
|
|
"github.com/huichen/wukong/types"
|
|
|
"github.com/huichen/wukong/utils"
|
|
|
)
|
|
|
@@ -442,61 +441,3 @@ func TestLookupWithLocations(t *testing.T) {
|
|
|
docs, _ := indexer.Lookup([]string{"token2", "token3"}, []string{}, nil, false)
|
|
|
utils.Expect(t, "[[0 21] [28]]", docs[0].TokenLocations)
|
|
|
}
|
|
|
-
|
|
|
-func TestLookupWithLocations1(t *testing.T) {
|
|
|
-
|
|
|
- type Data struct {
|
|
|
- Id int
|
|
|
- Content string
|
|
|
- Labels []string
|
|
|
- }
|
|
|
-
|
|
|
- datas := make([]Data, 0)
|
|
|
-
|
|
|
- data0 := Data{Id: 0, Content: "此次百度收购将成中国互联网最大并购", Labels: []string{"百度", "中国"}}
|
|
|
- datas = append(datas, data0)
|
|
|
-
|
|
|
- data1 := Data{Id: 1, Content: "百度宣布拟全资收购91无线业务", Labels: []string{"百度"}}
|
|
|
- datas = append(datas, data1)
|
|
|
-
|
|
|
- data2 := Data{Id: 2, Content: "百度是中国最大的搜索引擎", Labels: []string{"百度"}}
|
|
|
- datas = append(datas, data2)
|
|
|
-
|
|
|
- data3 := Data{Id: 3, Content: "百度在研制无人汽车", Labels: []string{"百度"}}
|
|
|
- datas = append(datas, data3)
|
|
|
-
|
|
|
- data4 := Data{Id: 4, Content: "BAT是中国互联网三巨头", Labels: []string{"百度"}}
|
|
|
- datas = append(datas, data4)
|
|
|
-
|
|
|
- // 初始化
|
|
|
- searcher_locations := engine.Engine{}
|
|
|
- searcher_locations.Init(types.EngineInitOptions{
|
|
|
- SegmenterDictionaries: "../data/dictionary.txt",
|
|
|
- IndexerInitOptions: &types.IndexerInitOptions{
|
|
|
- IndexType: types.LocationsIndex,
|
|
|
- },
|
|
|
- })
|
|
|
- defer searcher_locations.Close()
|
|
|
- for _, data := range datas {
|
|
|
- searcher_locations.IndexDocument(uint64(data.Id), types.DocumentIndexData{Content: data.Content, Labels: data.Labels})
|
|
|
- }
|
|
|
- searcher_locations.FlushIndex()
|
|
|
- res_locations := searcher_locations.Search(types.SearchRequest{Text: "百度"})
|
|
|
-
|
|
|
- searcher_docids := engine.Engine{}
|
|
|
- searcher_docids.Init(types.EngineInitOptions{
|
|
|
- SegmenterDictionaries: "../data/dictionary.txt",
|
|
|
- IndexerInitOptions: &types.IndexerInitOptions{
|
|
|
- IndexType: types.DocIdsIndex,
|
|
|
- },
|
|
|
- })
|
|
|
- defer searcher_docids.Close()
|
|
|
- for _, data := range datas {
|
|
|
- searcher_docids.IndexDocument(uint64(data.Id), types.DocumentIndexData{Content: data.Content, Labels: data.Labels})
|
|
|
- }
|
|
|
- searcher_docids.FlushIndex()
|
|
|
- res_docids := searcher_docids.Search(types.SearchRequest{Text: "百度"})
|
|
|
- if res_docids.NumDocs != res_locations.NumDocs {
|
|
|
- t.Errorf("期待的搜索结果个数=\"%d\", 实际=\"%d\"", res_docids.NumDocs, res_locations.NumDocs)
|
|
|
- }
|
|
|
-}
|