From c2c4c2393f718c616aa96a4fb48505dd303a5c5f Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 29 May 2025 21:02:04 +0800 Subject: [PATCH] :art: Improve backlink filtering below the heading https://github.com/siyuan-note/siyuan/issues/14929 --- kernel/model/backlink.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index ea2543303..9f38e2819 100644 --- a/kernel/model/backlink.go +++ b/kernel/model/backlink.go @@ -656,6 +656,38 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keywords []string) (ret [] ret = append(ret, ref) } } + + if 0 < len(keywords) { + // 过滤场景处理标题下方块 Improve backlink filtering below the heading https://github.com/siyuan-note/siyuan/issues/14929 + headingRefChildren := map[string]*Block{} + var headingIDs []string + for _, link := range links { + for _, ref := range link.Refs { + if "NodeHeading" == ref.Type { + headingRefChildren[ref.ID] = ref + headingIDs = append(headingIDs, ref.ID) + } + } + } + var headingChildren []*Block + for _, headingID := range headingIDs { + sqlChildren := sql.GetChildBlocks(headingID, "", -1) + children := fromSQLBlocks(&sqlChildren, "", 12) + headingChildren = append(headingChildren, children...) + } + for _, child := range headingChildren { + if nil == child { + continue + } + + if matchBacklinkKeyword(child, keywords) { + heading := headingRefChildren[child.ParentID] + if nil != heading { + ret = append(ret, heading) + } + } + } + } return }