mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-29 12:58:48 +01:00
⚡ 使用 AC 算法优化虚拟引用匹配性能
This commit is contained in:
parent
5f72a7b2cd
commit
72631ad0e9
3 changed files with 8 additions and 4 deletions
|
|
@ -27,7 +27,7 @@ import (
|
|||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
ahocorasick "github.com/BobuSumisu/aho-corasick"
|
||||
ahocorasick "github.com/ClarkThan/ahocorasick"
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -82,10 +82,11 @@ func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []s
|
|||
}
|
||||
}
|
||||
|
||||
trie := ahocorasick.NewTrieBuilder().AddStrings(keywordsTmp).Build()
|
||||
hits := trie.MatchString(contentTmp)
|
||||
m := ahocorasick.NewMatcher()
|
||||
m.BuildWithPatterns(keywordsTmp)
|
||||
hits := m.Search(contentTmp)
|
||||
for _, hit := range hits {
|
||||
ret = append(ret, hit.MatchString())
|
||||
ret = append(ret, hit)
|
||||
}
|
||||
|
||||
if 1 > len(ret) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue