From 5371da84aae02d85f6404ec33639e505f30237f0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 15 Feb 2023 13:05:07 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=89=93=E5=BC=80=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=B1=9E=E6=80=A7=E6=90=9C=E7=B4=A2=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=90=8E=E5=87=BA=E7=8E=B0=E5=A4=9A=E4=BD=99=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=20Fix=20https://github.com/siyuan-note/siyua?= =?UTF-8?q?n/issues/7367?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/search.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/model/search.go b/kernel/model/search.go index 0b62bd1fc..2a722ea80 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -591,6 +591,7 @@ 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 @@ -681,9 +682,10 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin "tag, " + "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 + ")' AND type IN " + typeFilter - stmt += boxFilter + pathFilter + stmt := "SELECT " + projections + " FROM " + table + " WHERE (`" + table + "` MATCH '" + columnFilter() + ":(" + query + ")'" stmt += customIALFilter(query) + stmt += ") AND type IN " + typeFilter + stmt += boxFilter + pathFilter stmt += " " + orderBy stmt += " LIMIT " + strconv.Itoa(Conf.Search.Limit) blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit) @@ -713,9 +715,10 @@ func fullTextSearchCount(query, boxFilter, pathFilter, typeFilter string) (match table = "blocks_fts_case_insensitive" } - 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 := "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) if 1 > len(result) { return @@ -735,8 +738,8 @@ func customIALFilter(query string) string { reg := strings.TrimPrefix(query, "\"") reg = strings.TrimSuffix(reg, "\"") reg = regexp.QuoteMeta(reg) - reg = "custom\\-.*" + reg + ".*" - return " AND ial REGEXP '" + reg + "'" + reg = "custom-.*" + reg + ".*" + return " OR ial REGEXP '" + reg + "'" } func markSearch(text string, keyword string, beforeLen int) (marked string, score float64) { @@ -903,9 +906,6 @@ func columnFilter() string { if Conf.Search.Memo { buf.WriteString(" memo") } - if Conf.Search.Custom { - buf.WriteString(" ial") - } buf.WriteString(" tag}") return buf.String() }