An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Block ref search and global search results display reference counts https://github.com/siyuan-note/siyuan/issues/15721
Daniel74304e9cba0b
diff --git a/kernel/model/block.go b/kernel/model/block.goindex d21518f213..d84780af06 100644--- a/kernel/model/block.go+++ b/kernel/model/block.go@@ -61,6 +61,7 @@ type Block struct {Children []*Block `json:"children"`Depth int `json:"depth"`Count int `json:"count"`+ RefCount int `json:"refCount"`Sort int `json:"sort"`Created string `json:"created"`Updated string `json:"updated"`@@ -765,7 +766,7 @@ func GetBlockKramdown(id, mode string) (ret string) {if "md" == mode {// `/api/block/getBlockKramdown` link/image URLs are no longer encoded with spaces https://github.com/siyuan-note/siyuan/issues/15611luteEngine.SetPreventEncodeLinkSpace(true)-+ret = treenode.ExportNodeStdMd(root, luteEngine)} else {tree.Root = rootdiff --git a/kernel/model/search.go b/kernel/model/search.goindex 0a4b9cda76..4a58450612 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -314,6 +314,9 @@ func buildEmbedBlock(embedBlockID string, excludeIDs []string, headingMode int,func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets, isDatabase bool) (ret []*Block, newDoc bool) {cachedTrees := map[string]*parse.Tree{}+ nodeTrees := map[string]*parse.Tree{}+ var nodeIDs []string+ var nodes []*ast.NodeonlyDoc := falseif isSquareBrackets {@@ -332,6 +335,7 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,}btsID = gulu.Str.RemoveDuplicatedElem(btsID)bts := treenode.GetBlockTrees(btsID)+for _, ref := range refs {tree := cachedTrees[ref.DefBlockRootID]if nil == tree {@@ -347,6 +351,15 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,continue}+ nodes = append(nodes, node)+ nodeIDs = append(nodeIDs, node.ID)+ nodeTrees[node.ID] = tree+ }++ refCount := sql.QueryRefCount(nodeIDs)++ for _, node := range nodes {+ tree := nodeTrees[node.ID]sqlBlock := sql.BuildBlockFromNode(node, tree)if nil == sqlBlock {return@@ -355,8 +368,10 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,block := fromSQLBlock(sqlBlock, "", 0)block.RefText = getNodeRefText(node)block.RefText = maxContent(block.RefText, Conf.Editor.BlockRefDynamicAnchorTextMaxLen)+ block.RefCount = refCount[node.ID]ret = append(ret, block)}+if 1 > len(ret) {ret = []*Block{}}@@ -388,7 +403,7 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,hitFirstChildID := falseif b.IsContainerBlock() && "NodeDocument" != b.Type {// `((` 引用候选中排除当前块的父块 https://github.com/siyuan-note/siyuan/issues/4538- tree := cachedTrees[b.RootID]+ tree = cachedTrees[b.RootID]if nil == tree {tree, _ = loadTreeByBlockTree(bts[b.RootID])cachedTrees[b.RootID] = tree@@ -404,16 +419,25 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,if "NodeAttributeView" == b.Type {// 数据库块可以添加到自身数据库块中,当前文档也可以添加到自身数据库块中tmp = append(tmp, b)+ nodeIDs = append(nodeIDs, b.ID)+ nodeTrees[b.ID] = tree} else {// 排除自身块、父块和根块if b.ID != id && !hitFirstChildID && b.ID != rootID {tmp = append(tmp, b)+ nodeIDs = append(nodeIDs, b.ID)+ nodeTrees[b.ID] = tree}}}ret = tmp+ refCount := sql.QueryRefCount(nodeIDs)+ for _, b := range ret {+ b.RefCount = refCount[b.ID]+ }+if !isDatabase {// 如果非数据库中搜索块引,则不允许新建重名文档if block := treenode.GetBlockTree(id); nil != block {@@ -1296,6 +1320,16 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bif 0 == groupBy {filterSelfHPath(ret)}++ var nodeIDs []string+ for _, b := range ret {+ nodeIDs = append(nodeIDs, b.ID)+ }++ refCount := sql.QueryRefCount(nodeIDs)+ for _, b := range ret {+ b.RefCount = refCount[b.ID]+ }return}