Skip to content

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

:art: 反链面板支持关键字过滤 https://github.com/siyuan-note/siyuan/issues/6178

Liang Dingbec79ce10098
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index e70d44f350..2f7b66bb22 100644
--- a/app/appearance/langs/en_US.json
+++ b/app/appearance/langs/en_US.json
@@ -38,7 +38,7 @@
"generateConflictDoc": "Generate conflict documentation when syncing conflicts",
"generateConflictDocTip": "After enabling, a conflict document will be generated when a synchronization conflict occurs, so that it can be opened and viewed directly. Whether enabled or not, the data history will record the conflict document",
"deleteOpConfirm": "⚠️ Delete operation confirmation",
- "filterDocNameEnter": "Filter doc name Enter",
+ "filterKeywordEnter": "Keyword filtering Enter",
"defBlock": "Def block",
"defBlockChildren": "Define block and its children",
"filter": "Filter",
diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json
index 468c3d8013..85e57c2118 100644
--- a/app/appearance/langs/es_ES.json
+++ b/app/appearance/langs/es_ES.json
@@ -38,7 +38,7 @@
"generateConflictDoc": "Generar documentación de conflicto al sincronizar conflictos",
"generateConflictDocTip": "Cuando está habilitado, se generará un documento de conflicto cuando ocurra un conflicto de sincronización, para que pueda abrirse y verse directamente. Ya sea que esté habilitado o no, el historial de datos registrará el documento de conflicto",
"deleteOpConfirm": "⚠️ Confirmación de operación de eliminación",
- "filterDocNameEnter": "Filtrar doc name Enter",
+ "filterKeywordEnter": "Filtrado de palabras clave Entrar",
"defBlock": "Definir bloque",
"defBlockChildren": "Definir bloque y sus hijos",
"filter": "Filtro",
diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json
index a9668bef2f..d00cf336bf 100644
--- a/app/appearance/langs/fr_FR.json
+++ b/app/appearance/langs/fr_FR.json
@@ -38,7 +38,7 @@
"generateConflictDoc": "Générer une documentation sur les conflits lors de la synchronisation des conflits",
"generateConflictDocTip": "Lorsqu'il est activé, un document de conflit sera généré lorsqu'un conflit de synchronisation se produit, afin qu'il puisse être ouvert et visualisé directement. Qu'il soit activé ou non, l'historique des données enregistrera le document de conflit",
"deleteOpConfirm": "⚠️ Supprimer la confirmation de l'opération",
- "filterDocNameEnter": "Filtre doc name Enter",
+ "filterKeywordEnter": "Filtrage des mots-clés Entrée",
"defBlock": "Définir le bloc",
"defBlockChildren": "Définir le bloc et ses enfants",
"filter": "Filtre",
diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json
index fb2198f058..c2a30d8293 100644
--- a/app/appearance/langs/zh_CHT.json
+++ b/app/appearance/langs/zh_CHT.json
@@ -38,7 +38,7 @@
"generateConflictDoc": "同步衝突時生成衝突文檔",
"generateConflictDocTip": "啟用後當同步發生衝突時會生成衝突文檔,以便直接打開查看。無論是否啟用,數據歷史都會記錄衝突文檔",
"deleteOpConfirm": "⚠️ Delete operation confirmation",
- "filterDocNameEnter": "過濾文檔名 Enter",
+ "filterKeywordEnter": "關鍵字過濾 Enter",
"defBlock": "定義塊",
"defBlockChildren": "定義塊及其子塊",
"filter": "過濾",
diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json
index 7f1d1f443a..d2d9c1c5b0 100644
--- a/app/appearance/langs/zh_CN.json
+++ b/app/appearance/langs/zh_CN.json
@@ -38,7 +38,7 @@
"generateConflictDoc": "同步冲突时生成冲突文档",
"generateConflictDocTip": "启用后当同步发生冲突时会生成冲突文档,以便直接打开查看。无论是否启用,数据历史都会记录冲突文档",
"deleteOpConfirm": "⚠️ 删除操作确认",
- "filterDocNameEnter": "过滤文档名 Enter",
+ "filterKeywordEnter": "关键字过滤 Enter",
"defBlock": "定义块",
"defBlockChildren": "定义块及其子块",
"filter": "过滤",
diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.ts
index 3524d20dfd..0759462d55 100644
--- a/app/src/layout/dock/Backlink.ts
+++ b/app/src/layout/dock/Backlink.ts
@@ -84,7 +84,7 @@ export class Backlink extends Model {
<span class="fn__space"></span>
<label class="b3-form__icon b3-form__icon--small search__label">
<svg class="b3-form__icon-icon"><use xlink:href="#iconFilter"></use></svg>
- <input class="b3-text-field b3-text-field--small b3-form__icon-input" placeholder="${window.siyuan.languages.filterDocNameEnter}" />
+ <input class="b3-text-field b3-text-field--small b3-form__icon-input" placeholder="${window.siyuan.languages.filterKeywordEnter}" />
</label>
<span class="fn__space"></span>
<span data-type="refresh" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.refresh}"><svg><use xlink:href='#iconRefresh'></use></svg></span>
@@ -107,7 +107,7 @@ export class Backlink extends Model {
<span class="fn__space"></span>
<label class="b3-form__icon b3-form__icon--small search__label">
<svg class="b3-form__icon-icon"><use xlink:href="#iconFilter"></use></svg>
- <input class="b3-text-field b3-text-field--small b3-form__icon-input" placeholder="${window.siyuan.languages.filterDocNameEnter}" />
+ <input class="b3-text-field b3-text-field--small b3-form__icon-input" placeholder="${window.siyuan.languages.filterKeywordEnter}" />
</label>
<span class="fn__space"></span>
<span data-type="mSort" data-sort="3" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.sort}"><svg><use xlink:href='#iconSort'></use></svg></span>
diff --git a/kernel/api/ref.go b/kernel/api/ref.go
index 42f8c440a7..4479fbc2c7 100644
--- a/kernel/api/ref.go
+++ b/kernel/api/ref.go
@@ -50,7 +50,7 @@ func getBackmentionDoc(c *gin.Context) {
defID := arg["defID"].(string)
refTreeID := arg["refTreeID"].(string)
- keyword := ""
+ keyword := arg["keyword"].(string)
backlinks := model.GetBackmentionDoc(defID, refTreeID, keyword)
ret.Data = map[string]interface{}{
"backmentions": backlinks,
@@ -68,7 +68,8 @@ func getBacklinkDoc(c *gin.Context) {
defID := arg["defID"].(string)
refTreeID := arg["refTreeID"].(string)
- backlinks := model.GetBacklinkDoc(defID, refTreeID)
+ keyword := arg["keyword"].(string)
+ backlinks := model.GetBacklinkDoc(defID, refTreeID, keyword)
ret.Data = map[string]interface{}{
"backlinks": backlinks,
}
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index 28f14f7807..e5cf2602c9 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -178,7 +178,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
refs := sql.QueryRefsByDefID(defID, true)
refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
- linkRefs, _, excludeBacklinkIDs := buildLinkRefs(rootID, refs)
+ linkRefs, _, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keyword)
tmpMentions, mentionKeywords := buildTreeBackmention(sqlBlock, linkRefs, keyword, excludeBacklinkIDs, beforeLen)
luteEngine := NewLute()
treeCache := map[string]*parse.Tree{}
@@ -206,7 +206,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
return
}
-func GetBacklinkDoc(defID, refTreeID string) (ret []*Backlink) {
+func GetBacklinkDoc(defID, refTreeID, keyword string) (ret []*Backlink) {
ret = []*Backlink{}
sqlBlock := sql.GetBlock(defID)
if nil == sqlBlock {
@@ -223,7 +223,7 @@ func GetBacklinkDoc(defID, refTreeID string) (ret []*Backlink) {
}
refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
- linkRefs, _, _ := buildLinkRefs(rootID, refs)
+ linkRefs, _, _ := buildLinkRefs(rootID, refs, keyword)
refTree, err := loadTreeByBlockID(refTreeID)
if nil != err {
logging.LogWarnf("load ref tree [%s] failed: %s", refTreeID, err)
@@ -353,16 +353,11 @@ func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode
refs := sql.QueryRefsByDefID(id, true)
refs = removeDuplicatedRefs(refs) // 同一个块中引用多个相同块时反链去重 https://github.com/siyuan-note/siyuan/issues/3317
- linkRefs, linkRefsCount, excludeBacklinkIDs := buildLinkRefs(rootID, refs)
+ linkRefs, linkRefsCount, excludeBacklinkIDs := buildLinkRefs(rootID, refs, keyword)
tmpBacklinks := toFlatTree(linkRefs, 0, "backlink")
for _, l := range tmpBacklinks {
l.Blocks = nil
- if "" != keyword {
- if !strings.Contains(l.Name, keyword) {
- continue
- }
- }
backlinks = append(backlinks, l)
}
@@ -558,7 +553,7 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int) (boxID strin
return
}
-func buildLinkRefs(defRootID string, refs []*sql.Ref) (ret []*Block, refsCount int, excludeBacklinkIDs *hashset.Set) {
+func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Block, refsCount int, excludeBacklinkIDs *hashset.Set) {
// 为了减少查询,组装好 IDs 后一次查出
defSQLBlockIDs, refSQLBlockIDs := map[string]bool{}, map[string]bool{}
var queryBlockIDs []string
@@ -627,8 +622,13 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref) (ret []*Block, refsCount i
paragraphParents := sql.GetBlocks(paragraphParentIDs)
for _, p := range paragraphParents {
if "i" == p.Type || "h" == p.Type {
- ret = append(ret, fromSQLBlock(p, "", 12))
processedParagraphs.Add(p.ID)
+
+ if !strings.Contains(p.Content, keyword) {
+ refsCount--
+ continue
+ }
+ ret = append(ret, fromSQLBlock(p, "", 12))
}
}
for _, link := range links {
@@ -639,6 +639,11 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref) (ret []*Block, refsCount i
}
}
+ if !strings.Contains(ref.Content, keyword) {
+ refsCount--
+ continue
+ }
+
ref.DefID = link.ID
ref.DefPath = link.Path
ret = append(ret, ref)