Skip to content

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

:art: Improve backlink filtering below the heading https://github.com/siyuan-note/siyuan/issues/14929

Daniel4528be886e56
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index ea25433038..5cff17ead0 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -476,7 +476,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int, containChild
var paragraphParentIDs []string
for _, link := range links {
for _, ref := range link.Refs {
- if "NodeParagraph" == ref.Type {
+ if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
paragraphParentIDs = append(paragraphParentIDs, ref.ParentID)
}
}
@@ -494,7 +494,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int, containChild
}
for _, link := range links {
for _, ref := range link.Refs {
- if "NodeParagraph" == ref.Type {
+ if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
if processedParagraphs.Contains(ref.ParentID) {
continue
}
@@ -580,7 +580,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
var paragraphParentIDs []string
for _, link := range links {
for _, ref := range link.Refs {
- if "NodeParagraph" == ref.Type {
+ if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
parentRefParagraphs[ref.ParentID] = ref
paragraphParentIDs = append(paragraphParentIDs, ref.ParentID)
}
@@ -615,7 +615,15 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
continue
}
- if "" != strings.TrimSpace(c.Text()) {
+ text := c.Text()
+ if strings.HasPrefix(text, "#") {
+ tmp := strings.ReplaceAll(text, "#", "")
+ if " " == tmp { // 如果是标题标记符则跳过
+ continue
+ }
+ }
+
+ if "" != strings.TrimSpace(text) {
paragraphUseParentLi = false
break
}
@@ -640,7 +648,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret []
}
for _, link := range links {
for _, ref := range link.Refs {
- if "NodeParagraph" == ref.Type {
+ if "NodeParagraph" == ref.Type || "NodeHeading" == ref.Type {
if processedParagraphs.Contains(ref.ParentID) {
continue
}