🎨 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
|
@ -1152,12 +1152,12 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []
|
|||
|
||||
if ignoreLines := getRefSearchIgnoreLines(); 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()
|
||||
}
|
||||
|
||||
orderBy := ` ORDER BY CASE
|
||||
|
@ -1272,12 +1272,12 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
|
|||
|
||||
if ignoreLines := getSearchIgnoreLines(); 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 += " " + orderBy
|
||||
|
|
|
@ -112,7 +112,9 @@ func ResetVirtualBlockRefCache() {
|
|||
return
|
||||
}
|
||||
|
||||
keywords := sql.QueryVirtualRefKeywords(Conf.Search.VirtualRefName, Conf.Search.VirtualRefAlias, Conf.Search.VirtualRefAnchor, Conf.Search.VirtualRefDoc)
|
||||
searchIgnoreLines := getSearchIgnoreLines()
|
||||
refSearchIgnoreLines := getRefSearchIgnoreLines()
|
||||
keywords := sql.QueryVirtualRefKeywords(Conf.Search.VirtualRefName, Conf.Search.VirtualRefAlias, Conf.Search.VirtualRefAnchor, Conf.Search.VirtualRefDoc, searchIgnoreLines, refSearchIgnoreLines)
|
||||
virtualBlockRefCache.Set("virtual_ref", keywords, 1)
|
||||
}
|
||||
|
||||
|
|
|
@ -180,9 +180,16 @@ func QueryBlockAliases(rootID string) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func queryNames() (ret []string) {
|
||||
func queryNames(searchIgnoreLines []string) (ret []string) {
|
||||
ret = []string{}
|
||||
sqlStmt := "SELECT name FROM blocks WHERE name != '' LIMIT ?"
|
||||
sqlStmt := "SELECT name FROM blocks WHERE name != ''"
|
||||
buf := bytes.Buffer{}
|
||||
for _, line := range searchIgnoreLines {
|
||||
buf.WriteString(" AND ")
|
||||
buf.WriteString(line)
|
||||
}
|
||||
sqlStmt += buf.String()
|
||||
sqlStmt += " LIMIT ?"
|
||||
rows, err := query(sqlStmt, 10240)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
|
@ -213,9 +220,16 @@ func queryNames() (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func queryAliases() (ret []string) {
|
||||
func queryAliases(searchIgnoreLines []string) (ret []string) {
|
||||
ret = []string{}
|
||||
sqlStmt := "SELECT alias FROM blocks WHERE alias != '' LIMIT ?"
|
||||
sqlStmt := "SELECT alias FROM blocks WHERE alias != ''"
|
||||
buf := bytes.Buffer{}
|
||||
for _, line := range searchIgnoreLines {
|
||||
buf.WriteString(" AND ")
|
||||
buf.WriteString(line)
|
||||
}
|
||||
sqlStmt += buf.String()
|
||||
sqlStmt += " LIMIT ?"
|
||||
rows, err := query(sqlStmt, 10240)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
|
@ -274,9 +288,15 @@ func queryDocIDsByTitle(title string, excludeIDs []string) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func queryDocTitles() (ret []string) {
|
||||
func queryDocTitles(searchIgnoreLines []string) (ret []string) {
|
||||
ret = []string{}
|
||||
sqlStmt := "SELECT content FROM blocks WHERE type = 'd'"
|
||||
buf := bytes.Buffer{}
|
||||
for _, line := range searchIgnoreLines {
|
||||
buf.WriteString(" AND ")
|
||||
buf.WriteString(line)
|
||||
}
|
||||
sqlStmt += buf.String()
|
||||
rows, err := query(sqlStmt)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
|
|
|
@ -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
Reference in a new issue