up
This commit is contained in:
+8
-8
@@ -1123,9 +1123,9 @@ func badURL(u string) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deduplicateSubstrings 对分词结果进行智能去重。
|
// deduplicateSubstrings 对分词结果进行智能去重。
|
||||||
// 当词 A 是词 B 的子串时(A ≠ B),移除较短的 A。
|
// 当词 A 是词 B 的子串时(A ≠ B),保留两者但标记子串关系。
|
||||||
// 例如 ["气象", "局", "气象局"] → ["气象局", "局"]
|
// 例如 ["气象", "局", "气象局"] → ["气象局", "气象", "局"]
|
||||||
// 保留最长词以确保精确匹配优先,同时短词作为兜底召回。
|
// 保留最长词以确保精确匹配优先,短词作为兜底召回(避免"气象局"索引为空时完全搜不到结果)。
|
||||||
func deduplicateSubstrings(tokens []string) []string {
|
func deduplicateSubstrings(tokens []string) []string {
|
||||||
if len(tokens) <= 1 {
|
if len(tokens) <= 1 {
|
||||||
return tokens
|
return tokens
|
||||||
@@ -1144,15 +1144,15 @@ func deduplicateSubstrings(tokens []string) []string {
|
|||||||
continue // 完全重复的词跳过
|
continue // 完全重复的词跳过
|
||||||
}
|
}
|
||||||
seen[t] = true
|
seen[t] = true
|
||||||
// 检查是否已被更长的词包含(t 是某个已保留词的子串)
|
// 检查是否已被更长的词完全相同地包含(t 是某个已保留词的真子串)
|
||||||
isSubstr := false
|
isDuplicate := false
|
||||||
for _, kept := range result {
|
for _, kept := range result {
|
||||||
if strings.Contains(kept, t) && kept != t {
|
if kept == t {
|
||||||
isSubstr = true
|
isDuplicate = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isSubstr {
|
if !isDuplicate {
|
||||||
result = append(result, t)
|
result = append(result, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user