Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-11-14 11:54:31 +08:00
commit 1ac5d5a235

View file

@ -90,9 +90,7 @@ func GetBackmentionDoc(defID, refTreeID, keyword string, containChildren bool) (
}
mentionBlockIDs = gulu.Str.RemoveDuplicatedElem(mentionBlockIDs)
if "" != keyword {
mentionKeywords = append(mentionKeywords, keyword)
}
mentionKeywords = strings.Split(keyword, " ")
mentionKeywords = gulu.Str.RemoveDuplicatedElem(mentionKeywords)
var refTree *parse.Tree
@ -141,10 +139,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret
luteEngine := util.NewLute()
for _, linkRef := range linkRefs {
var keywords []string
if "" != keyword {
keywords = append(keywords, keyword)
}
keywords := strings.Split(keyword, " ")
backlink := buildBacklink(linkRef.ID, refTree, keywords, luteEngine)
if nil != backlink {
ret = append(ret, backlink)
@ -571,8 +566,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
if nil != refBlock && p.FContent == refBlock.Content { // 使用内容判断是否是列表项下第一个子块
// 如果是列表项下第一个子块,则后续会通过列表项传递或关联处理,所以这里就不处理这个段落了
processedParagraphs.Add(p.ID)
if !strings.Contains(p.Content, keyword) && !strings.Contains(path.Base(p.HPath), keyword) &&
!strings.Contains(p.Name, keyword) && !strings.Contains(p.Alias, keyword) && !strings.Contains(p.Memo, keyword) && !strings.Contains(p.Tag, keyword) {
if !matchBacklinkKeyword(p, keyword) {
refsCount--
continue
}
@ -588,8 +582,7 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
}
}
if !strings.Contains(ref.Content, keyword) && !strings.Contains(path.Base(ref.HPath), keyword) &&
!strings.Contains(ref.Name, keyword) && !strings.Contains(ref.Alias, keyword) && !strings.Contains(ref.Memo, keyword) && !strings.Contains(ref.Tag, keyword) {
if !matchBacklinkKeyword(ref, keyword) {
refsCount--
continue
}
@ -602,6 +595,22 @@ func buildLinkRefs(defRootID string, refs []*sql.Ref, keyword string) (ret []*Bl
return
}
func matchBacklinkKeyword(block *Block, keyword string) bool {
keywords := strings.Split(keyword, " ")
for _, k := range keywords {
k = strings.ToLower(k)
if strings.Contains(strings.ToLower(block.Content), k) ||
strings.Contains(strings.ToLower(path.Base(block.HPath)), k) ||
strings.Contains(strings.ToLower(block.Name), k) ||
strings.Contains(strings.ToLower(block.Alias), k) ||
strings.Contains(strings.ToLower(block.Memo), k) ||
strings.Contains(strings.ToLower(block.Tag), k) {
return true
}
}
return false
}
func removeDuplicatedRefs(refs []*sql.Ref) (ret []*sql.Ref) {
// 同一个块中引用多个块后反链去重
// De-duplication of backlinks after referencing multiple blocks in the same block https://github.com/siyuan-note/siyuan/issues/12147