From bec79ce10098e2a1834a5a32175471e90fc92f40 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 17 Nov 2022 22:39:22 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=8F=8D=E9=93=BE=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=85=B3=E9=94=AE=E5=AD=97=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6178?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- app/src/layout/dock/Backlink.ts | 4 ++-- kernel/api/ref.go | 5 +++-- kernel/model/backlink.go | 27 ++++++++++++++++----------- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index e70d44f35..2f7b66bb2 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 468c3d801..85e57c211 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 a9668bef2..d00cf336b 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 fb2198f05..c2a30d829 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 7f1d1f443..d2d9c1c5b 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 3524d20df..0759462d5 100644 --- a/app/src/layout/dock/Backlink.ts +++ b/app/src/layout/dock/Backlink.ts @@ -84,7 +84,7 @@ export class Backlink extends Model { @@ -107,7 +107,7 @@ export class Backlink extends Model { diff --git a/kernel/api/ref.go b/kernel/api/ref.go index 42f8c440a..4479fbc2c 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 28f14f780..e5cf2602c 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)