Daniel 2024-06-27 10:51:04 +08:00
parent b73fa77f2b
commit 992586e04a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 15 additions and 2 deletions

View file

@ -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 {

View file

@ -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 {