🎨 搜索自定义属性改为搜索全部属性 https://github.com/siyuan-note/siyuan/issues/7367

This commit is contained in:
Liang Ding 2023-02-15 14:26:50 +08:00
parent 5371da84aa
commit d1f493e2d2
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -591,7 +591,6 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
"snippet(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS content, " +
"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
stmt := "SELECT " + projections + " FROM " + table + " WHERE " + table + " MATCH '" + columnFilter() + ":(" + quotedKeyword + ")' AND type IN " + Conf.Search.TypeFilter()
stmt = customIALFilter(quotedKeyword)
orderBy := ` order by case
when name = '${keyword}' then 10
when alias = '${keyword}' then 20
@ -609,7 +608,7 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {
else 65535 end ASC, sort ASC, length ASC`
orderBy = strings.ReplaceAll(orderBy, "${keyword}", keyword)
stmt += orderBy + " LIMIT " + strconv.Itoa(Conf.Search.Limit)
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
blocks := sql.SelectBlocksRawStmtNoParse(stmt, Conf.Search.Limit)
ret = fromSQLBlocks(&blocks, "", beforeLen)
if 1 > len(ret) {
ret = []*Block{}
@ -645,7 +644,7 @@ func fullTextSearchByRegexp(exp, boxFilter, pathFilter, typeFilter, orderBy stri
stmt += boxFilter + pathFilter
stmt += " " + orderBy
stmt += " LIMIT " + strconv.Itoa(Conf.Search.Limit)
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
blocks := sql.SelectBlocksRawStmtNoParse(stmt, Conf.Search.Limit)
ret = fromSQLBlocks(&blocks, "", beforeLen)
if 1 > len(ret) {
ret = []*Block{}
@ -683,7 +682,6 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
"highlight(" + table + ", 11, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS content, " +
"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
stmt := "SELECT " + projections + " FROM " + table + " WHERE (`" + table + "` MATCH '" + columnFilter() + ":(" + query + ")'"
stmt += customIALFilter(query)
stmt += ") AND type IN " + typeFilter
stmt += boxFilter + pathFilter
stmt += " " + orderBy
@ -716,7 +714,6 @@ func fullTextSearchCount(query, boxFilter, pathFilter, typeFilter string) (match
}
stmt := "SELECT COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` FROM `" + table + "` WHERE (`" + table + "` MATCH '" + columnFilter() + ":(" + query + ")'"
stmt += customIALFilter(query)
stmt += ") AND type IN " + typeFilter
stmt += boxFilter + pathFilter
result, _ := sql.Query(stmt)
@ -728,20 +725,6 @@ func fullTextSearchCount(query, boxFilter, pathFilter, typeFilter string) (match
return
}
// customIALFilter 用于组装自定义属性过滤条件。
// 打开自定义属性搜索选项后出现多余搜索结果 https://github.com/siyuan-note/siyuan/issues/7367
func customIALFilter(query string) string {
if !Conf.Search.Custom {
return ""
}
reg := strings.TrimPrefix(query, "\"")
reg = strings.TrimSuffix(reg, "\"")
reg = regexp.QuoteMeta(reg)
reg = "custom-.*" + reg + ".*"
return " OR ial REGEXP '" + reg + "'"
}
func markSearch(text string, keyword string, beforeLen int) (marked string, score float64) {
if 0 == len(keyword) {
marked = text
@ -906,6 +889,9 @@ func columnFilter() string {
if Conf.Search.Memo {
buf.WriteString(" memo")
}
if Conf.Search.Custom {
buf.WriteString(" ial")
}
buf.WriteString(" tag}")
return buf.String()
}