🎨 Improve block ref search ID extraction https://github.com/siyuan-note/siyuan/issues/10848

This commit is contained in:
Daniel 2024-04-03 11:12:48 +08:00
parent eae61fd4a7
commit 455f348e91
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1045,8 +1045,8 @@ func removeLimitClause(stmt string) string {
func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []*Block) {
keyword = filterQueryInvisibleChars(keyword)
if ast.IsNodeIDPattern(keyword) {
ret, _, _ = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+keyword+"'", 36, 1, 32)
if id := extractID(keyword); "" != id {
ret, _, _ = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+id+"'", 36, 1, 32)
return
}
@ -1106,6 +1106,21 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []
return
}
func extractID(content string) (ret string) {
if 22 > len(content) {
return
}
// 从第一个字符开始循环,直到找到一个合法的 ID 为止
for i := 0; i < len(content)-21; i++ {
if ast.IsNodeIDPattern(content[i : i+22]) {
ret = content[i : i+22]
return
}
}
return
}
func fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
query = filterQueryInvisibleChars(query)
if ast.IsNodeIDPattern(query) {