Skip to content

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

:art: Improve block ref searching https://github.com/siyuan-note/siyuan/issues/12010

Danielafcb66689250
diff --git a/kernel/model/search.go b/kernel/model/search.go
index fc01586c0b..bebd9d3f70 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -322,8 +322,9 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,
if "" == keyword {
// 查询为空时默认的块引排序规则按最近使用优先 https://github.com/siyuan-note/siyuan/issues/3218
+ typeFilter := Conf.Search.TypeFilter()
ignoreLines := getRefSearchIgnoreLines()
- refs := sql.QueryRefsRecent(onlyDoc, ignoreLines)
+ refs := sql.QueryRefsRecent(onlyDoc, typeFilter, ignoreLines)
var btsID []string
for _, ref := range refs {
btsID = append(btsID, ref.DefBlockRootID)
diff --git a/kernel/sql/block_ref_query.go b/kernel/sql/block_ref_query.go
index b57a848ba3..8593d848a9 100644
--- a/kernel/sql/block_ref_query.go
+++ b/kernel/sql/block_ref_query.go
@@ -360,12 +360,11 @@ func QueryRefIDsByDefID(defID string, containChildren bool) (refIDs, refTexts []
return
}
-func QueryRefsRecent(onlyDoc bool, ignoreLines []string) (ret []*Ref) {
- stmt := "SELECT * FROM refs AS r"
+func QueryRefsRecent(onlyDoc bool, typeFilter string, ignoreLines []string) (ret []*Ref) {
+ stmt := "SELECT r.* FROM refs AS r, blocks AS b WHERE b.id = r.def_block_id AND b.type IN " + typeFilter
if onlyDoc {
stmt = "SELECT r.* FROM refs AS r, blocks AS b WHERE b.type = 'd' AND b.id = r.def_block_id"
}
- stmt += " WHERE 1 = 1"
if 0 < len(ignoreLines) {
// Support ignore search results https://github.com/siyuan-note/siyuan/issues/10089
buf := bytes.Buffer{}