Skip to content

Commit

Permalink
Update tokenizer.go
Browse files Browse the repository at this point in the history
  • Loading branch information
songzhibin97 committed Aug 17, 2022
1 parent 12769cf commit 477af1c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions searcher/words/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func (t *Tokenizer) Cut(text string) []string {
//移除所有的空格
text = utils.RemoveSpace(text)

var wordMap = make(map[string]int)
var wordMap = make(map[string]struct{})

resultChan := t.seg.CutForSearch(text, true)
var wordsSlice []string
for {
w, ok := <-resultChan
if !ok {
Expand All @@ -53,14 +54,10 @@ func (t *Tokenizer) Cut(text string) []string {
_, found := wordMap[w]
if !found {
//去除重复的词
wordMap[w] = 1
wordMap[w] = struct{}{}
wordsSlice = append(wordsSlice, w)
}
}

var wordsSlice []string
for k := range wordMap {
wordsSlice = append(wordsSlice, k)
}

return wordsSlice
}

0 comments on commit 477af1c

Please sign in to comment.