mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 改进虚拟引用和反链提及搜索分词 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)
|
blocks := fromSQLBlocks(&sqlBlocks, strings.Join(terms, search.TermSep), beforeLen)
|
||||||
|
|
||||||
// 排除链接文本 https://github.com/siyuan-note/siyuan/issues/1542
|
|
||||||
luteEngine := NewLute()
|
luteEngine := NewLute()
|
||||||
var tmp []*Block
|
var tmp []*Block
|
||||||
for _, b := range blocks {
|
for _, b := range blocks {
|
||||||
|
|
@ -783,40 +782,20 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink
|
||||||
if !entering || n.IsBlock() {
|
if !entering || n.IsBlock() {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
if ast.NodeText == n.Type || ast.NodeLinkText == n.Type {
|
if ast.NodeText == n.Type {
|
||||||
textBuf.Write(n.Tokens)
|
textBuf.Write(n.Tokens)
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
|
||||||
text := textBuf.String()
|
text := textBuf.String()
|
||||||
text = strings.ToLower(text)
|
text = strings.TrimSpace(text)
|
||||||
text = luteEngine.Space(text)
|
if "" == text {
|
||||||
var contain bool
|
continue
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if contain {
|
|
||||||
|
newText := markReplaceSpan(text, mentionKeywords, searchMarkSpanStart, searchMarkSpanEnd)
|
||||||
|
if text != newText {
|
||||||
tmp = append(tmp, b)
|
tmp = append(tmp, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -640,7 +640,7 @@ func stringQuery(query string) string {
|
||||||
return strings.TrimSpace(buf.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, " ")
|
parts := strings.Split(text, " ")
|
||||||
for i, part := range parts {
|
for i, part := range parts {
|
||||||
if "" == part {
|
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)
|
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
Add a link
Reference in a new issue