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: Improve `Add to Database` search sorting https://github.com/siyuan-note/siyuan/issues/10952
Daniel225930d3cf6a
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 25bcc4a060..934af36ae9 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -36,6 +36,7 @@ import ("github.com/siyuan-note/siyuan/kernel/cache""github.com/siyuan-note/siyuan/kernel/treenode""github.com/siyuan-note/siyuan/kernel/util"+ "github.com/xrash/smetrics")func SetDatabaseBlockView(blockID, viewID string) (err error) {@@ -194,7 +195,12 @@ func SearchAttributeView(keyword string) (ret []*SearchAttributeViewResult) {ret = []*SearchAttributeViewResult{}keyword = strings.TrimSpace(keyword)- avs := map[string]string{}+ type result struct {+ AvID string+ AvName string+ Score float64+ }+ var avs []*resultavDir := filepath.Join(util.DataDir, "storage", "av")const limit = 16entries, err := os.ReadDir(avDir)@@ -220,17 +226,23 @@ func SearchAttributeView(keyword string) (ret []*SearchAttributeViewResult) {}if strings.Contains(strings.ToLower(name), strings.ToLower(keyword)) {- avs[id] = name+ score := smetrics.JaroWinkler(name, keyword, 0.7, 4)+ avs = append(avs, &result{AvID: id, AvName: name, Score: score})count++- if limit <= count {+ if "" == keyword && limit <= count {break}}}+ sort.Slice(avs, func(i, j int) bool { return avs[i].Score > avs[j].Score })+ if limit < len(avs) {+ avs = avs[:limit]+ }+var avIDs []string- for avID := range avs {- avIDs = append(avIDs, avID)+ for _, av := range avs {+ avIDs = append(avIDs, av.AvID)}blockIDs := treenode.BatchGetMirrorAttrViewBlockIDs(avIDs)trees := map[string]*parse.Tree{}@@ -261,8 +273,14 @@ func SearchAttributeView(keyword string) (ret []*SearchAttributeViewResult) {}avID := node.AttributeViewID- name := avs[avID]- if "" == name {+ var existAv *result+ for _, av := range avs {+ if av.AvID == avID {+ existAv = av+ break+ }+ }+ if nil == existAv {continue}@@ -287,7 +305,7 @@ func SearchAttributeView(keyword string) (ret []*SearchAttributeViewResult) {if !exist {ret = append(ret, &SearchAttributeViewResult{AvID: avID,- AvName: name,+ AvName: existAv.AvName,BlockID: blockID,HPath: hPath,})diff --git a/kernel/model/search.go b/kernel/model/search.goindex d3e7d53785..ba519f4e5f 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -384,17 +384,22 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets}}- if b.ID != id && !hitFirstChildID && b.ID != rootID {+ if "NodeAttributeView" == b.Type {+ // 数据库块可以添加到自身数据库块中,当前文档也可以添加到自身数据库块中tmp = append(tmp, b)+ } else {+ // 排除自身块、父块和根块+ if b.ID != id && !hitFirstChildID && b.ID != rootID {+ tmp = append(tmp, b)+ }}+}ret = tmp- if "" != keyword {- if block := treenode.GetBlockTree(id); nil != block {- p := path.Join(block.HPath, keyword)- newDoc = nil == treenode.GetBlockTreeRootByHPath(block.BoxID, p)- }+ if block := treenode.GetBlockTree(id); nil != block {+ p := path.Join(block.HPath, keyword)+ newDoc = nil == treenode.GetBlockTreeRootByHPath(block.BoxID, p)}// 在 hPath 中加入笔记本名 Show notebooks in hpath of block ref search list results https://github.com/siyuan-note/siyuan/issues/9378