mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve search index ignore for virtual refs https://github.com/siyuan-note/siyuan/issues/11827
This commit is contained in:
parent
7b1dcd269c
commit
1011cd4900
4 changed files with 54 additions and 25 deletions
|
|
@ -44,18 +44,18 @@ func GetRefDuplicatedDefRootIDs() (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func QueryVirtualRefKeywords(name, alias, anchor, doc bool) (ret []string) {
|
||||
func QueryVirtualRefKeywords(name, alias, anchor, doc bool, searchIgnoreLines, refSearchIgnoreLines []string) (ret []string) {
|
||||
if name {
|
||||
ret = append(ret, queryNames()...)
|
||||
ret = append(ret, queryNames(searchIgnoreLines)...)
|
||||
}
|
||||
if alias {
|
||||
ret = append(ret, queryAliases()...)
|
||||
ret = append(ret, queryAliases(searchIgnoreLines)...)
|
||||
}
|
||||
if anchor {
|
||||
ret = append(ret, queryRefTexts()...)
|
||||
ret = append(ret, queryRefTexts(refSearchIgnoreLines)...)
|
||||
}
|
||||
if doc {
|
||||
ret = append(ret, queryDocTitles()...)
|
||||
ret = append(ret, queryDocTitles(searchIgnoreLines)...)
|
||||
}
|
||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||
sort.SliceStable(ret, func(i, j int) bool {
|
||||
|
|
@ -64,9 +64,16 @@ func QueryVirtualRefKeywords(name, alias, anchor, doc bool) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func queryRefTexts() (ret []string) {
|
||||
func queryRefTexts(refSearchIgnoreLines []string) (ret []string) {
|
||||
ret = []string{}
|
||||
sqlStmt := "SELECT DISTINCT content FROM refs LIMIT 10240"
|
||||
sqlStmt := "SELECT DISTINCT content FROM refs WHERE 1 = 1"
|
||||
buf := bytes.Buffer{}
|
||||
for _, line := range refSearchIgnoreLines {
|
||||
buf.WriteString(" AND ")
|
||||
buf.WriteString(line)
|
||||
}
|
||||
sqlStmt += buf.String()
|
||||
sqlStmt += " LIMIT 10240"
|
||||
rows, err := query(sqlStmt)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query failed: %s", sqlStmt, err)
|
||||
|
|
@ -361,12 +368,12 @@ func QueryRefsRecent(onlyDoc bool, ignoreLines []string) (ret []*Ref) {
|
|||
stmt += " WHERE 1 = 1"
|
||||
if 0 < len(ignoreLines) {
|
||||
// Support ignore search results https://github.com/siyuan-note/siyuan/issues/10089
|
||||
notLike := bytes.Buffer{}
|
||||
buf := bytes.Buffer{}
|
||||
for _, line := range ignoreLines {
|
||||
notLike.WriteString(" AND ")
|
||||
notLike.WriteString(line)
|
||||
buf.WriteString(" AND ")
|
||||
buf.WriteString(line)
|
||||
}
|
||||
stmt += notLike.String()
|
||||
stmt += buf.String()
|
||||
}
|
||||
stmt += " GROUP BY r.def_block_id ORDER BY r.id DESC LIMIT 32"
|
||||
rows, err := query(stmt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue