Skip to content

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

:art: Support ignore search results https://github.com/siyuan-note/siyuan/issues/10089 https://github.com/siyuan-note/siyuan/issues/11830

Daniel992586e04a8f
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 9638919539..6177c45b46 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -321,7 +321,9 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,
if "" == keyword {
// 查询为空时默认的块引排序规则按最近使用优先 https://github.com/siyuan-note/siyuan/issues/3218
- refs := sql.QueryRefsRecent(onlyDoc)
+
+ ignoreLines := getRefSearchIgnoreLines()
+ refs := sql.QueryRefsRecent(onlyDoc, ignoreLines)
for _, ref := range refs {
tree := cachedTrees[ref.DefBlockRootID]
if nil == tree {
diff --git a/kernel/sql/block_ref_query.go b/kernel/sql/block_ref_query.go
index dda9b3e955..2296461140 100644
--- a/kernel/sql/block_ref_query.go
+++ b/kernel/sql/block_ref_query.go
@@ -17,6 +17,7 @@
package sql
import (
+ "bytes"
"database/sql"
"sort"
"strings"
@@ -352,11 +353,21 @@ func QueryRefIDsByDefID(defID string, containChildren bool) (refIDs, refTexts []
return
}
-func QueryRefsRecent(onlyDoc bool) (ret []*Ref) {
+func QueryRefsRecent(onlyDoc bool, ignoreLines []string) (ret []*Ref) {
stmt := "SELECT * FROM refs AS r"
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
+ notLike := bytes.Buffer{}
+ for _, line := range ignoreLines {
+ notLike.WriteString(" AND ")
+ notLike.WriteString(line)
+ }
+ stmt += notLike.String()
+ }
stmt += " GROUP BY r.def_block_id ORDER BY r.id DESC LIMIT 32"
rows, err := query(stmt)
if nil != err {