mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
🎨 Support ignore search results https://github.com/siyuan-note/siyuan/issues/10089 https://github.com/siyuan-note/siyuan/issues/11830
This commit is contained in:
parent
b73fa77f2b
commit
992586e04a
2 changed files with 15 additions and 2 deletions
|
|
@ -321,7 +321,9 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets,
|
||||||
|
|
||||||
if "" == keyword {
|
if "" == keyword {
|
||||||
// 查询为空时默认的块引排序规则按最近使用优先 https://github.com/siyuan-note/siyuan/issues/3218
|
// 查询为空时默认的块引排序规则按最近使用优先 https://github.com/siyuan-note/siyuan/issues/3218
|
||||||
refs := sql.QueryRefsRecent(onlyDoc)
|
|
||||||
|
ignoreLines := getRefSearchIgnoreLines()
|
||||||
|
refs := sql.QueryRefsRecent(onlyDoc, ignoreLines)
|
||||||
for _, ref := range refs {
|
for _, ref := range refs {
|
||||||
tree := cachedTrees[ref.DefBlockRootID]
|
tree := cachedTrees[ref.DefBlockRootID]
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -352,11 +353,21 @@ func QueryRefIDsByDefID(defID string, containChildren bool) (refIDs, refTexts []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func QueryRefsRecent(onlyDoc bool) (ret []*Ref) {
|
func QueryRefsRecent(onlyDoc bool, ignoreLines []string) (ret []*Ref) {
|
||||||
stmt := "SELECT * FROM refs AS r"
|
stmt := "SELECT * FROM refs AS r"
|
||||||
if onlyDoc {
|
if onlyDoc {
|
||||||
stmt = "SELECT r.* FROM refs AS r, blocks AS b WHERE b.type = 'd' AND b.id = r.def_block_id"
|
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"
|
stmt += " GROUP BY r.def_block_id ORDER BY r.id DESC LIMIT 32"
|
||||||
rows, err := query(stmt)
|
rows, err := query(stmt)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue