Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error fixing & add fields to ScoredDocument for SearchResponse #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/ranker.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package core

import (
"github.com/huichen/wukong/types"
"github.com/huichen/wukong/utils"
"log"
"sort"
"sync"

"github.com/huichen/wukong/types"
"github.com/huichen/wukong/utils"
)

type Ranker struct {
Expand Down Expand Up @@ -75,7 +76,8 @@ func (ranker *Ranker) Rank(
DocId: d.DocId,
Scores: scores,
TokenSnippetLocations: d.TokenSnippetLocations,
TokenLocations: d.TokenLocations})
TokenLocations: d.TokenLocations,
Fields: fs})
}
numDocs++
}
Expand Down
17 changes: 9 additions & 8 deletions examples/codelab/search_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"encoding/gob"
"encoding/json"
"flag"
"github.com/huichen/wukong/engine"
"github.com/huichen/wukong/types"
"io"
"log"
"net/http"
Expand All @@ -16,6 +14,9 @@ import (
"reflect"
"strconv"
"strings"

"github.com/huichen/wukong/engine"
"github.com/huichen/wukong/types"
)

const (
Expand All @@ -24,12 +25,12 @@ const (
)

var (
searcher = engine.Engine{}
wbs = map[uint64]Weibo{}
weiboData = flag.String("weibo_data", "../../testdata/weibo_data.txt", "微博数据文件")
dictFile = flag.String("dict_file", "../../data/dictionary.txt", "词典文件")
searcher = engine.Engine{}
wbs = map[uint64]Weibo{}
weiboData = flag.String("weibo_data", "../../testdata/weibo_data.txt", "微博数据文件")
dictFile = flag.String("dict_file", "../../data/dictionary.txt", "词典文件")
stopTokenFile = flag.String("stop_token_file", "../../data/stop_tokens.txt", "停用词文件")
staticFolder = flag.String("static_folder", "static", "静态文件目录")
staticFolder = flag.String("static_folder", "static", "静态文件目录")
)

type Weibo struct {
Expand Down Expand Up @@ -73,7 +74,7 @@ func indexWeibo() {
Timestamp: weibo.Timestamp,
RepostsCount: weibo.RepostsCount,
},
})
}, false)
}

searcher.FlushIndex()
Expand Down
8 changes: 5 additions & 3 deletions examples/custom_scoring_criteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"encoding/gob"
"flag"
"fmt"
"github.com/huichen/wukong/engine"
"github.com/huichen/wukong/types"
"log"
"os"
"reflect"
"strconv"
"strings"

"github.com/huichen/wukong/engine"
"github.com/huichen/wukong/types"
)

const (
Expand Down Expand Up @@ -142,7 +143,8 @@ func main() {
log.Print("建立索引")
for i, text := range lines {
searcher.IndexDocument(uint64(i),
types.DocumentIndexData{Content: text, Fields: fieldsSlice[i]})
types.DocumentIndexData{Content: text, Fields: fieldsSlice[i]},
false)
}
searcher.FlushIndex()
log.Print("索引建立完毕")
Expand Down
2 changes: 2 additions & 0 deletions types/search_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type ScoredDocument struct {
// 关键词出现的位置
// 只有当IndexType == LocationsIndex时不为空
TokenLocations [][]int

Fields interface{}
}

// 为了方便排序
Expand Down