diff --git a/kernel/model/search.go b/kernel/model/search.go index 963891953..6177c45b4 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 dda9b3e95..229646114 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 {