From 18f6bc307384e6c372148627dffdbd4e27a5ed8e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 12 Mar 2023 22:07:20 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=8F=8D=E9=93=BE=E6=8F=90=E5=8F=8A?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=8C=83=E5=9B=B4=E5=A2=9E=E5=8A=A0=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E3=80=81=E5=88=AB=E5=90=8D=E5=92=8C=E5=A4=87=E6=B3=A8?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/7639?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/backlink.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index 6f2d9ac56..23002b011 100644 --- a/kernel/model/backlink.go +++ b/kernel/model/backlink.go @@ -642,7 +642,7 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink } buf := bytes.Buffer{} - buf.WriteString("SELECT * FROM " + table + " WHERE " + table + " MATCH '{content}:(") + buf.WriteString("SELECT * FROM " + table + " WHERE " + table + " MATCH '" + columnFilter() + ":(") for i, mentionKeyword := range mentionKeywords { if Conf.Search.BacklinkMentionKeywordsLimit < i { util.PushMsg(fmt.Sprintf(Conf.Language(38), len(mentionKeywords)), 5000) @@ -688,7 +688,7 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink if !entering || n.IsBlock() { return ast.WalkContinue } - if ast.NodeText == n.Type { + if ast.NodeText == n.Type { // 这里包含了标签命中的情况,因为 Lute 没有启用 TextMark textBuf.Write(n.Tokens) } return ast.WalkContinue @@ -703,6 +703,14 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink newText := markReplaceSpanWithSplit(text, mentionKeywords, search.GetMarkSpanStart(search.MarkDataType), search.GetMarkSpanEnd()) if text != newText { tmp = append(tmp, b) + } else { + // columnFilter 中的命名、别名和备注命中的情况 + // 反链提及搜索范围增加命名、别名和备注 https://github.com/siyuan-note/siyuan/issues/7639 + if gulu.Str.Contains(trimMarkTags(b.Name), mentionKeywords) || + gulu.Str.Contains(trimMarkTags(b.Alias), mentionKeywords) || + gulu.Str.Contains(trimMarkTags(b.Memo), mentionKeywords) { + tmp = append(tmp, b) + } } } blocks = tmp @@ -727,6 +735,10 @@ func searchBackmention(mentionKeywords []string, keyword string, excludeBacklink return } +func trimMarkTags(str string) string { + return strings.TrimSuffix(strings.TrimPrefix(str, ""), "") +} + func getContainStr(str string, strs []string) string { str = strings.ToLower(str) for _, s := range strs {