Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: `pdf?page` 资源文件链接会被判定为未引用资源 Fix https://github.com/siyuan-note/siyuan/issues/5649

Liang Ding103cbf8d1574
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index b216aad6f3..b3af288118 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 5786de2ada..55768d75b1 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 5e552adc0c..e8cc031dbf 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, '<mark>__r', '</mark>', '...', 64) AS hpath, " +
- "snippet(" + table + ", 7, '<mark>__r', '</mark>', '...', 64) AS name, " +
- "snippet(" + table + ", 8, '<mark>__r', '</mark>', '...', 64) AS alias, " +
- "snippet(" + table + ", 9, '<mark>__r', '</mark>', '...', 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, '<mark>__r', '</mark>', '...', 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, "<mark>__r") { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回
- marked = strings.ReplaceAll(marked, "<mark>__r", "<mark>")
+ marked = html.EscapeString(text)
+
+ if strings.Contains(marked, search.SearchMarkLeft) { // 使用 FTS snippet() 处理过高亮片段,这里简单替换后就返回
+ marked = strings.ReplaceAll(marked, search.SearchMarkLeft, "<mark>")
+ marked = strings.ReplaceAll(marked, search.SearchMarkRight, "</mark>")
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 b3fd6234c6..e16fe6fa43 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)