mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve the SQL method in the global search https://github.com/siyuan-note/siyuan/issues/14641
This commit is contained in:
parent
f60a8d641a
commit
a5eab97728
1 changed files with 22 additions and 7 deletions
|
|
@ -1406,19 +1406,34 @@ func searchBySQL(stmt string, beforeLen, page, pageSize int) (ret []*Block, matc
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = strings.ToLower(stmt)
|
stmt = strings.ToLower(stmt)
|
||||||
if strings.HasPrefix(stmt, "select a.* ") { // 多个搜索关键字匹配文档 https://github.com/siyuan-note/siyuan/issues/7350
|
stdQuery := !strings.Contains(stmt, "with recursive") && !strings.Contains(stmt, "union")
|
||||||
stmt = strings.ReplaceAll(stmt, "select a.* ", "select COUNT(a.id) AS `matches`, COUNT(DISTINCT(a.root_id)) AS `docs` ")
|
if stdQuery {
|
||||||
} else {
|
if strings.HasPrefix(stmt, "select a.* ") { // 多个搜索关键字匹配文档 https://github.com/siyuan-note/siyuan/issues/7350
|
||||||
stmt = strings.ReplaceAll(stmt, "select * ", "select COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` ")
|
stmt = strings.ReplaceAll(stmt, "select a.* ", "select COUNT(a.id) AS `matches`, COUNT(DISTINCT(a.root_id)) AS `docs` ")
|
||||||
|
} else {
|
||||||
|
stmt = strings.ReplaceAll(stmt, "select * ", "select COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stmt = removeLimitClause(stmt)
|
stmt = removeLimitClause(stmt)
|
||||||
result, _ := sql.QueryNoLimit(stmt)
|
result, _ := sql.QueryNoLimit(stmt)
|
||||||
if 1 > len(ret) {
|
if 1 > len(result) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
matchedBlockCount = int(result[0]["matches"].(int64))
|
if !stdQuery {
|
||||||
matchedRootCount = int(result[0]["docs"].(int64))
|
var rootIDs, blockIDs []string
|
||||||
|
for _, queryResult := range result {
|
||||||
|
rootIDs = append(rootIDs, queryResult["root_id"].(string))
|
||||||
|
blockIDs = append(blockIDs, queryResult["id"].(string))
|
||||||
|
}
|
||||||
|
rootIDs = gulu.Str.RemoveDuplicatedElem(rootIDs)
|
||||||
|
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
||||||
|
matchedRootCount = len(rootIDs)
|
||||||
|
matchedBlockCount = len(blockIDs)
|
||||||
|
} else {
|
||||||
|
matchedBlockCount = int(result[0]["matches"].(int64))
|
||||||
|
matchedRootCount = int(result[0]["docs"].(int64))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue