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