From 103cbf8d15741f319b69ba44676b983613cee4bd Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 16 Aug 2022 10:24:38 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20`pdf=3Fpage`=20=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=93=BE=E6=8E=A5=E4=BC=9A=E8=A2=AB=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E4=B8=BA=E6=9C=AA=E5=BC=95=E7=94=A8=E8=B5=84=E6=BA=90?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/5649?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 5 +++++ kernel/model/file.go | 2 +- kernel/model/search.go | 34 +++++++++++++++++++--------------- kernel/search/mark.go | 6 +++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index b216aad6f..b3af28811 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -573,6 +573,11 @@ func UnusedAssets() (ret []string) { continue } + if idx := strings.Index(dest, "?"); 0 < idx { + // `pdf?page` 资源文件链接会被判定为未引用资源 https://github.com/siyuan-note/siyuan/issues/5649 + dest = dest[:idx] + } + if "" == assetsPathMap[dest] { continue } diff --git a/kernel/model/file.go b/kernel/model/file.go index 5786de2ad..55768d75b 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -629,7 +629,7 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size // 支持代码块搜索定位 https://github.com/siyuan-note/siyuan/issues/5520 if ast.NodeCodeBlockCode == n.Type && 0 < len(keywords) && !render.IsChartCodeBlockCode(n) { text := string(n.Tokens) - text = search.EncloseHighlighting(text, keywords, "__@mark__", "__mark@__", Conf.Search.CaseSensitive) + text = search.EncloseHighlighting(text, keywords, search.SearchMarkLeft, search.SearchMarkRight, Conf.Search.CaseSensitive) n.Tokens = gulu.Str.ToBytes(text) } diff --git a/kernel/model/search.go b/kernel/model/search.go index 5e552adc0..e8cc031db 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -26,6 +26,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" + "github.com/88250/lute/html" "github.com/88250/lute/parse" "github.com/jinzhu/copier" "github.com/siyuan-note/logging" @@ -268,12 +269,12 @@ func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) { } projections := "id, parent_id, root_id, hash, box, path, " + - "snippet(" + table + ", 6, '__r', '', '...', 64) AS hpath, " + - "snippet(" + table + ", 7, '__r', '', '...', 64) AS name, " + - "snippet(" + table + ", 8, '__r', '', '...', 64) AS alias, " + - "snippet(" + table + ", 9, '__r', '', '...', 64) AS memo, " + + "snippet(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS hpath, " + + "snippet(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS name, " + + "snippet(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS alias, " + + "snippet(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "', '...', 64) AS memo, " + "tag, " + - "snippet(" + table + ", 11, '__r', '', '...', 64) AS content, " + + "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() orderBy := ` order by case @@ -345,12 +346,12 @@ func fullTextSearch(query, box, path, filter string, beforeLen int, querySyntax table = "blocks_fts_case_insensitive" } projections := "id, parent_id, root_id, hash, box, path, " + - "highlight(" + table + ", 6, '__@mark__', '__mark@__') AS hpath, " + - "highlight(" + table + ", 7, '__@mark__', '__mark@__') AS name, " + - "highlight(" + table + ", 8, '__@mark__', '__mark@__') AS alias, " + - "highlight(" + table + ", 9, '__@mark__', '__mark@__') AS memo, " + + "highlight(" + table + ", 6, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS hpath, " + + "highlight(" + table + ", 7, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS name, " + + "highlight(" + table + ", 8, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS alias, " + + "highlight(" + table + ", 9, '" + search.SearchMarkLeft + "', '" + search.SearchMarkRight + "') AS memo, " + "tag, " + - "highlight(" + table + ", 11, '__@mark__', '__mark@__') AS content, " + + "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 " + filter if "" != box { @@ -439,16 +440,19 @@ func markSearch(text string, keyword string, beforeLen int) (marked string, scor marked = gulu.Str.SubStr(marked, maxLen) + "..." } - if strings.Contains(marked, "__r") { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回 - marked = strings.ReplaceAll(marked, "__r", "") + marked = html.EscapeString(text) + + if strings.Contains(marked, search.SearchMarkLeft) { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回 + marked = strings.ReplaceAll(marked, search.SearchMarkLeft, "") + marked = strings.ReplaceAll(marked, search.SearchMarkRight, "") return } - keywords := gulu.Str.SubstringsBetween(marked, "__@mark__", "__mark@__") + keywords := gulu.Str.SubstringsBetween(marked, search.SearchMarkLeft, search.SearchMarkRight) keywords = gulu.Str.RemoveDuplicatedElem(keywords) keyword = strings.Join(keywords, search.TermSep) - marked = strings.ReplaceAll(marked, "__@mark__", "") - marked = strings.ReplaceAll(marked, "__mark@__", "") + marked = strings.ReplaceAll(marked, search.SearchMarkLeft, "") + marked = strings.ReplaceAll(marked, search.SearchMarkRight, "") _, marked = search.MarkText(marked, keyword, beforeLen, Conf.Search.CaseSensitive) return } diff --git a/kernel/search/mark.go b/kernel/search/mark.go index b3fd6234c..e16fe6fa4 100644 --- a/kernel/search/mark.go +++ b/kernel/search/mark.go @@ -53,7 +53,11 @@ func MarkText(text string, keyword string, beforeLen int, caseSensitive bool) (p return } -const TermSep = "__term@sep__" +const ( + TermSep = "__term@sep__" + SearchMarkLeft = "__@mark__" + SearchMarkRight = "__mark@__" +) func SplitKeyword(keyword string) (keywords []string) { keyword = strings.TrimSpace(keyword)