mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 01:21:14 +08:00
🎨 SQL 搜索支持多个搜索关键字匹配文档 Fix https://github.com/siyuan-note/siyuan/issues/7350
This commit is contained in:
parent
a335da26df
commit
1754dee724
@ -544,6 +544,7 @@ func buildTypeFilter(types map[string]bool) string {
|
||||
|
||||
func searchBySQL(stmt string, beforeLen int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||
stmt = gulu.Str.RemoveInvisible(stmt)
|
||||
stmt = strings.TrimSpace(stmt)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
||||
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
||||
if 1 > len(ret) {
|
||||
@ -552,7 +553,11 @@ func searchBySQL(stmt string, beforeLen int) (ret []*Block, matchedBlockCount, m
|
||||
}
|
||||
|
||||
stmt = strings.ToLower(stmt)
|
||||
stmt = strings.ReplaceAll(stmt, "select * ", "select COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` ")
|
||||
if strings.HasPrefix(stmt, "select a.* ") { // 多个搜索关键字匹配文档 https://github.com/siyuan-note/siyuan/issues/7350
|
||||
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` ")
|
||||
}
|
||||
result, _ := sql.Query(stmt)
|
||||
if 1 > len(ret) {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user