Skip to content

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

:art: 标点符号不纳入虚拟引用和提及搜索 https://github.com/siyuan-note/siyuan/issues/6272

Liang Dingf5cc328a9bb1
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index 88608804a0..efafd41cdd 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -716,6 +716,7 @@ func buildTreeBackmention(defSQLBlock *sql.Block, refBlocks []*Block, keyword st
for _, v := range set.Values() {
mentionKeywords = append(mentionKeywords, v.(string))
}
+ mentionKeywords = prepareMarkKeywords(mentionKeywords)
ret = searchBackmention(mentionKeywords, keyword, excludeBacklinkIDs, rootID, beforeLen)
return
}
@@ -726,9 +727,6 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink
if 1 > len(mentionKeywords) {
return
}
- sort.SliceStable(mentionKeywords, func(i, j int) bool {
- return len(mentionKeywords[i]) < len(mentionKeywords[j])
- })
table := "blocks_fts" // 大小写敏感
if !Conf.Search.CaseSensitive {
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 25b453d63c..045208661d 100644
--- a/kernel/model/file.go
+++ b/kernel/model/file.go
@@ -615,6 +615,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size
// 虚拟引用排除当前文档名 https://github.com/siyuan-note/siyuan/issues/4537
virtualBlockRefKeywords = gulu.Str.ExcludeElem(virtualBlockRefKeywords, []string{tree.Root.IALAttr("title")})
+ virtualBlockRefKeywords = prepareMarkKeywords(virtualBlockRefKeywords)
}
subTree := &parse.Tree{ID: rootID, Root: &ast.Node{Type: ast.NodeDocument}, Marks: tree.Marks}
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 27233cf694..4f74233329 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -19,6 +19,7 @@ package model
import (
"bytes"
"path"
+ "sort"
"strconv"
"strings"
"time"
@@ -641,7 +642,24 @@ func stringQuery(query string) string {
return strings.TrimSpace(buf.String())
}
+func prepareMarkKeywords(keywords []string) (ret []string) {
+ keywords = gulu.Str.RemoveDuplicatedElem(keywords)
+ for _, k := range keywords {
+ if strings.ContainsAny(k, "?*!@#$%^&()[]{}\\|;:'\",.<>~`") {
+ continue
+ }
+ ret = append(ret, k)
+ }
+
+ sort.SliceStable(ret, func(i, j int) bool {
+ return len(ret[i]) < len(ret[j])
+ })
+ return
+}
+
func markReplaceSpan(text string, keywords []string, replacementStart, replacementEnd string) (ret string) {
+ // 调用该函数前参数 keywords 必须使用 prepareMarkKeywords 函数进行预处理
+
parts := strings.Split(text, " ")
for i, part := range parts {
if "" == part {