mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 01:21:14 +08:00
🐛 打开自定义属性搜索选项后出现多余搜索结果 Fix https://github.com/siyuan-note/siyuan/issues/7367
This commit is contained in:
parent
b407ff9003
commit
b1a78149f2
@ -108,9 +108,6 @@ func (s *Search) NAMFilter(keyword string) string {
|
||||
if s.Memo {
|
||||
buf.WriteString(" OR memo LIKE '%" + keyword + "%'")
|
||||
}
|
||||
if s.Custom {
|
||||
buf.WriteString(" OR ial LIKE '%=%" + keyword + "%'")
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -683,6 +683,7 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
|
||||
"fcontent, markdown, length, type, subtype, ial, sort, created, updated"
|
||||
stmt := "SELECT " + projections + " FROM " + table + " WHERE " + table + " MATCH '" + columnFilter() + ":(" + query + ")' AND type IN " + typeFilter
|
||||
stmt += boxFilter + pathFilter
|
||||
stmt += customIALFilter(query)
|
||||
stmt += " " + orderBy
|
||||
stmt += " LIMIT " + strconv.Itoa(Conf.Search.Limit)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
||||
@ -714,6 +715,7 @@ 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 + ")' AND type IN " + typeFilter
|
||||
stmt += boxFilter + pathFilter
|
||||
stmt += customIALFilter(query)
|
||||
result, _ := sql.Query(stmt)
|
||||
if 1 > len(result) {
|
||||
return
|
||||
@ -723,6 +725,20 @@ 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 " AND ial REGEXP '" + reg + "'"
|
||||
}
|
||||
|
||||
func markSearch(text string, keyword string, beforeLen int) (marked string, score float64) {
|
||||
if 0 == len(keyword) {
|
||||
marked = text
|
||||
|
Loading…
Reference in New Issue
Block a user