From b1a78149f2c72d0f198f71ec6c8f64eb8de1fbc6 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 15 Feb 2023 11:13:02 +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/conf/search.go | 3 --- kernel/model/search.go | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/kernel/conf/search.go b/kernel/conf/search.go index da9cd05c9..eecf421f3 100644 --- a/kernel/conf/search.go +++ b/kernel/conf/search.go @@ -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() } diff --git a/kernel/model/search.go b/kernel/model/search.go index ee6fa12b4..ad0abc480 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -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