🎨 改进虚拟引用和反链提及搜索分词 Fix https://github.com/siyuan-note/siyuan/issues/6241
This commit is contained in:
parent
7b2ba61479
commit
9840fc1837
2 changed files with 19 additions and 30 deletions
|
@ -769,7 +769,6 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink
|
|||
}
|
||||
blocks := fromSQLBlocks(&sqlBlocks, strings.Join(terms, search.TermSep), beforeLen)
|
||||
|
||||
// 排除链接文本 https://github.com/siyuan-note/siyuan/issues/1542
|
||||
luteEngine := NewLute()
|
||||
var tmp []*Block
|
||||
for _, b := range blocks {
|
||||
|
@ -783,40 +782,20 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink
|
|||
if !entering || n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
if ast.NodeText == n.Type || ast.NodeLinkText == n.Type {
|
||||
if ast.NodeText == n.Type {
|
||||
textBuf.Write(n.Tokens)
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
text := textBuf.String()
|
||||
text = strings.ToLower(text)
|
||||
text = luteEngine.Space(text)
|
||||
var contain bool
|
||||
for _, mentionKeyword := range mentionKeywords {
|
||||
parts := strings.Split(text, " ")
|
||||
for _, part := range parts {
|
||||
if "" == part {
|
||||
continue
|
||||
}
|
||||
|
||||
if gulu.Str.IsASCII(mentionKeyword) {
|
||||
if part == mentionKeyword {
|
||||
contain = true
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(part, strings.ToLower(mentionKeyword)) {
|
||||
contain = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if contain {
|
||||
break
|
||||
}
|
||||
text = strings.TrimSpace(text)
|
||||
if "" == text {
|
||||
continue
|
||||
}
|
||||
if contain {
|
||||
|
||||
newText := markReplaceSpan(text, mentionKeywords, searchMarkSpanStart, searchMarkSpanEnd)
|
||||
if text != newText {
|
||||
tmp = append(tmp, b)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -640,7 +640,7 @@ func stringQuery(query string) string {
|
|||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
func markReplaceSpan(text string, keywords []string, replacementStart, replacementEnd string) string {
|
||||
func markReplaceSpan(text string, keywords []string, replacementStart, replacementEnd string) (ret string) {
|
||||
parts := strings.Split(text, " ")
|
||||
for i, part := range parts {
|
||||
if "" == part {
|
||||
|
@ -676,5 +676,15 @@ func markReplaceSpan(text string, keywords []string, replacementStart, replaceme
|
|||
parts[i] = search.EncloseHighlighting(part, hitKeywords, replacementStart, replacementEnd, Conf.Search.CaseSensitive)
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
|
||||
ret = strings.Join(parts, " ")
|
||||
if ret != text {
|
||||
return
|
||||
}
|
||||
|
||||
// 包含非 ASCII 字符时再试试不分词匹配
|
||||
if !gulu.Str.IsASCII(text) {
|
||||
ret = search.EncloseHighlighting(text, keywords, replacementStart, replacementEnd, Conf.Search.CaseSensitive)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue