Simplify包: 模拟ES部分分词规则,对查询关键字进行去重:不依赖slices包

master
宋青青 1 week ago
parent cf8f88dd5d
commit b28661bf9b
  1. 12
      simplify/words.go

@ -1,7 +1,6 @@
package simplify
import (
"slices"
"strings"
"unicode"
)
@ -70,7 +69,7 @@ func (w *Words) Simplify() []string {
filteredWhole := make([]string, 0)
for keyword, times := range repetition {
if times == 1 {
if slices.Contains(w.input, keyword) {
if w.contains(w.input, keyword) {
filteredInput = append(filteredInput, keyword)
} else {
filteredWhole = append(filteredWhole, keyword)
@ -84,6 +83,15 @@ func (w *Words) Simplify() []string {
return result
}
func (w *Words) contains(arr []string, str string) bool {
for _, v := range arr {
if v == str {
return true
}
}
return false
}
// isChineseOrSpace 判断给定的rune字符是否为中文或空格
func (w *Words) isChineseOrSpace(r rune) bool {
return r == ' ' || unicode.Is(unicode.Scripts["Han"], r)

Loading…
Cancel
Save