An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Add configuration item `Editor` - `[[ Only search doc block` Fix https://github.com/siyuan-note/siyuan/issues/8077
Liang Ding4ec4e1d88214
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.jsonindex 150a17b93a..9949269d33 100644--- a/app/appearance/langs/en_US.json+++ b/app/appearance/langs/en_US.json@@ -1,4 +1,6 @@{+ "onlySearchForDoc": "<code class='fn__code'>[[</code> only search documents",+ "onlySearchForDocTip": "After enabling, [[ to search for block references only in doc blocks","ocrResult": "OCR result text","reOCR": "Re OCR","continueReview1": "Continue Review",diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.jsonindex 618692ad81..bbb1c0869e 100644--- a/app/appearance/langs/es_ES.json+++ b/app/appearance/langs/es_ES.json@@ -1,4 +1,6 @@{+ "onlySearchForDoc": "<code class='fn__code'>[[</code> solo buscar documentos",+ "onlySearchForDocTip": "Después de habilitar, [[ para buscar referencias de bloque solo en bloques de documentos","ocrResult": "Texto de resultado de OCR","reOCR": "Re-OCR","continueReview1": "Continuar revisión",diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.jsonindex 527e99499d..d1270e0cb4 100644--- a/app/appearance/langs/fr_FR.json+++ b/app/appearance/langs/fr_FR.json@@ -1,4 +1,6 @@{+ "onlySearchForDoc": "<code class='fn__code'>[[</code> rechercher uniquement les documents",+ "onlySearchForDocTip": "Après l'activation, [[ pour rechercher des références de bloc uniquement dans les blocs doc","reOCR": "ReOCR","continueReview1": "Continuer la révision","continueReview2": "Il reste encore des fiches <code class='fn__code'>${count}</code> à examiner, continuer ?",diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.jsonindex 8744a0784d..24d9cdfb2c 100644--- a/app/appearance/langs/zh_CHT.json+++ b/app/appearance/langs/zh_CHT.json@@ -1,4 +1,6 @@{+ "onlySearchForDoc": "<code class='fn__code'>[[</code> 僅搜索文檔",+ "onlySearchForDocTip": "啟用後使用 [[ 搜索塊引用時將只在文檔塊中進行搜索","ocrResult": "OCR 結果文本","reOCR": "重新 OCR","continueReview1": "繼續複習",diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.jsonindex cba1ce2f8a..c9c123644a 100644--- a/app/appearance/langs/zh_CN.json+++ b/app/appearance/langs/zh_CN.json@@ -1,4 +1,6 @@{+ "onlySearchForDoc": "<code class='fn__code'>[[</code> 仅搜索文档",+ "onlySearchForDocTip": "启用后使用 [[ 搜索块引用时将只在文档块中进行搜索","ocrResult": "OCR 结果文本","reOCR": "重新 OCR","continueReview1": "继续复习",diff --git a/app/src/config/editor.ts b/app/src/config/editor.tsindex 5e5829639d..73ea97eed9 100644--- a/app/src/config/editor.ts+++ b/app/src/config/editor.ts@@ -98,6 +98,14 @@ export const editor = {<span class="fn__space"></span><input class="b3-switch fn__flex-center" id="spellcheck" type="checkbox"${window.siyuan.config.editor.spellcheck ? " checked" : ""}/></label>+<label class="fn__flex b3-label">+ <div class="fn__flex-1">+ ${window.siyuan.languages.onlySearchForDoc}+ <div class="b3-label__text">${window.siyuan.languages.onlySearchForDocTip}</div>+ </div>+ <span class="fn__space"></span>+ <input class="b3-switch fn__flex-center" id="onlySearchForDoc" type="checkbox"${window.siyuan.config.editor.onlySearchForDoc ? " checked" : ""}/>+</label><label class="fn__flex b3-label"><div class="fn__flex-1">${window.siyuan.languages.md31}@@ -280,6 +288,7 @@ export const editor = {embedBlockBreadcrumb: (editor.element.querySelector("#embedBlockBreadcrumb") as HTMLInputElement).checked,listLogicalOutdent: (editor.element.querySelector("#listLogicalOutdent") as HTMLInputElement).checked,spellcheck: (editor.element.querySelector("#spellcheck") as HTMLInputElement).checked,+ onlySearchForDoc: (editor.element.querySelector("#onlySearchForDoc") as HTMLInputElement).checked,floatWindowMode: (editor.element.querySelector("#floatWindowMode") as HTMLInputElement).checked ? 0 : 1,plantUMLServePath: (editor.element.querySelector("#plantUMLServePath") as HTMLInputElement).value,katexMacros: (editor.element.querySelector("#katexMacros") as HTMLTextAreaElement).value,diff --git a/app/src/config/search.ts b/app/src/config/search.tsindex c26acd0ae5..5d414d1295 100644--- a/app/src/config/search.ts+++ b/app/src/config/search.ts@@ -19,7 +19,7 @@ export const initConfigSearch = (element: HTMLElement) => {"historyRetentionDays", "historyRetentionDaysTip", "clearHistory", "katexMacros", "katexMacrosTip","editReadonly", "editReadonlyTip", "embedBlockBreadcrumb", "embedBlockBreadcrumbTip", "outlineOutdentTip","outdent", "floatWindowMode", "floatWindowModeTip", "justify", "justifyTip", "rtl", "rtlTip", "spellcheck",- "spellcheckTip", "backlinkExpand", "backlinkExpandTip"+ "spellcheckTip", "backlinkExpand", "backlinkExpandTip", "onlySearchForDocTip"]),// 文档树diff --git a/app/src/mobile/settings/editor.ts b/app/src/mobile/settings/editor.tsindex b35eb80041..bf1c298de2 100644--- a/app/src/mobile/settings/editor.ts+++ b/app/src/mobile/settings/editor.ts@@ -29,6 +29,7 @@ const setEditor = (modelMainElement: Element) => {window.siyuan.config.editor.embedBlockBreadcrumb = (modelMainElement.querySelector("#embedBlockBreadcrumb") as HTMLInputElement).checked;window.siyuan.config.editor.listLogicalOutdent = (modelMainElement.querySelector("#listLogicalOutdent") as HTMLInputElement).checked;window.siyuan.config.editor.spellcheck = (modelMainElement.querySelector("#spellcheck") as HTMLInputElement).checked;+ window.siyuan.config.editor.onlySearchForDoc = (modelMainElement.querySelector("#onlySearchForDoc") as HTMLInputElement).checked;window.siyuan.config.editor.plantUMLServePath = (modelMainElement.querySelector("#plantUMLServePath") as HTMLInputElement).value;window.siyuan.config.editor.katexMacros = (modelMainElement.querySelector("#katexMacros") as HTMLTextAreaElement).value;window.siyuan.config.editor.codeLineWrap = (modelMainElement.querySelector("#codeLineWrap") as HTMLInputElement).checked;@@ -108,6 +109,14 @@ export const initEditor = () => {<span class="fn__space"></span><input class="b3-switch fn__flex-center" id="spellcheck" type="checkbox"${window.siyuan.config.editor.spellcheck ? " checked" : ""}/></label>+<label class="fn__flex b3-label">+ <div class="fn__flex-1">+ ${window.siyuan.languages.onlySearchForDoc}+ <div class="b3-label__text">${window.siyuan.languages.onlySearchForDocTip}</div>+ </div>+ <span class="fn__space"></span>+ <input class="b3-switch fn__flex-center" id="onlySearchForDoc" type="checkbox"${window.siyuan.config.editor.spellcheck ? " checked" : ""}/>+</label><label class="fn__flex b3-label"><div class="fn__flex-1">${window.siyuan.languages.md31}diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex e9b244efa6..ef7a282b82 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -200,7 +200,7 @@ interface ISiyuan {mobile?: {editor?: import("../protyle").ProtylepopEditor?: import("../protyle").Protyle- files?: import("../mobile/util/MobileFiles").MobileFiles+ files?: import("../mobile/dock/MobileFiles").MobileFiles},user?: {userId: string@@ -332,6 +332,7 @@ declare interface IEditor {readOnly: boolean;listLogicalOutdent: boolean;spellcheck: boolean;+ onlySearchForDoc: boolean;katexMacros: string;fullWidth: boolean;floatWindowMode: number;diff --git a/kernel/api/search.go b/kernel/api/search.goindex dc8fc57e7a..d9806e8a0b 100644--- a/kernel/api/search.go+++ b/kernel/api/search.go@@ -191,16 +191,11 @@ func searchRefBlock(c *gin.Context) {return}- onlyDoc := false- if nil != arg["onlyDoc"] {- onlyDoc = arg["onlyDoc"].(bool)- }-rootID := arg["rootID"].(string)id := arg["id"].(string)keyword := arg["k"].(string)beforeLen := int(arg["beforeLen"].(float64))- blocks, newDoc := model.SearchRefBlock(id, rootID, keyword, beforeLen, onlyDoc)+ blocks, newDoc := model.SearchRefBlock(id, rootID, keyword, beforeLen)ret.Data = map[string]interface{}{"blocks": blocks,"newDoc": newDoc,diff --git a/kernel/conf/editor.go b/kernel/conf/editor.goindex 7f83c57669..32bba1df2f 100644--- a/kernel/conf/editor.go+++ b/kernel/conf/editor.go@@ -43,6 +43,7 @@ type Editor struct {Justify bool `json:"justify"` // 是否两端对齐RTL bool `json:"rtl"` // 是否从右到左显示Spellcheck bool `json:"spellcheck"` // 是否启用拼写检查+ OnlySearchForDoc bool `json:"onlySearchForDoc"` // 是否启用 [[ 仅搜索文档块BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量}diff --git a/kernel/model/search.go b/kernel/model/search.goindex 5c95b7d0bc..54beed227e 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -121,12 +121,12 @@ func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingModreturn}-func SearchRefBlock(id, rootID, keyword string, beforeLen int, onlyDoc bool) (ret []*Block, newDoc bool) {+func SearchRefBlock(id, rootID, keyword string, beforeLen int) (ret []*Block, newDoc bool) {cachedTrees := map[string]*parse.Tree{}if "" == keyword {// 查询为空时默认的块引排序规则按最近使用优先 https://github.com/siyuan-note/siyuan/issues/3218- refs := sql.QueryRefsRecent(onlyDoc)+ refs := sql.QueryRefsRecent(Conf.Editor.OnlySearchForDoc)for _, ref := range refs {tree := cachedTrees[ref.DefBlockRootID]if nil == tree {@@ -158,7 +158,7 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, onlyDoc bool) (rereturn}- ret = fullTextSearchRefBlock(keyword, beforeLen, onlyDoc)+ ret = fullTextSearchRefBlock(keyword, beforeLen)tmp := ret[:0]for _, b := range ret {tree := cachedTrees[b.RootID]@@ -646,7 +646,7 @@ func removeLimitClause(stmt string) string {return stmt}-func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []*Block) {+func fullTextSearchRefBlock(keyword string, beforeLen int) (ret []*Block) {keyword = gulu.Str.RemoveInvisible(keyword)if ast.IsNodeIDPattern(keyword) {@@ -669,7 +669,7 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []"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"- if onlyDoc {+ if Conf.Editor.OnlySearchForDoc {stmt += " = 'd'"} else {stmt += " IN " + Conf.Search.TypeFilter()