Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve search hit highlighting https://github.com/siyuan-note/siyuan/issues/8807#issuecomment-1663259981

Daniel8e1e8139bb00
diff --git a/kernel/model/file.go b/kernel/model/file.go
index be56fc8481..0834b6574f 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -702,13 +702,6 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
}
}
- // 支持代码块搜索定位 https://github.com/siyuan-note/siyuan/issues/5520
- if ast.NodeCodeBlockCode == n.Type && 0 < len(keywords) && !treenode.IsChartCodeBlockCode(n) {
- text := string(n.Tokens)
- text = search.EncloseHighlighting(text, keywords, search.SearchMarkLeft, search.SearchMarkRight, Conf.Search.CaseSensitive, false)
- n.Tokens = gulu.Str.ToBytes(text)
- }
-
if 0 < len(keywords) {
hitBlock := false
for p := n.Parent; nil != p; p = p.Parent {
@@ -718,7 +711,15 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
}
}
if hitBlock {
- if markReplaceSpan(n, &unlinks, keywords, search.MarkDataType, luteEngine) {
+ if ast.NodeCodeBlockCode == n.Type && !treenode.IsChartCodeBlockCode(n) {
+ // 支持代码块搜索定位 https://github.com/siyuan-note/siyuan/issues/5520
+ code := string(n.Tokens)
+ markedCode := search.EncloseHighlighting(code, keywords, search.SearchMarkLeft, search.SearchMarkRight, Conf.Search.CaseSensitive, false)
+ if code != markedCode {
+ n.Tokens = gulu.Str.ToBytes(markedCode)
+ return ast.WalkContinue
+ }
+ } else if markReplaceSpan(n, &unlinks, keywords, search.MarkDataType, luteEngine) {
return ast.WalkContinue
}
}