mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 08:30:42 +02:00
🎨 SQL 搜索支持多个搜索关键字匹配文档 Fix https://github.com/siyuan-note/siyuan/issues/7350
This commit is contained in:
parent
a335da26df
commit
1754dee724
1 changed files with 6 additions and 1 deletions
|
@ -544,6 +544,7 @@ func buildTypeFilter(types map[string]bool) string {
|
||||||
|
|
||||||
func searchBySQL(stmt string, beforeLen int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
func searchBySQL(stmt string, beforeLen int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||||
stmt = gulu.Str.RemoveInvisible(stmt)
|
stmt = gulu.Str.RemoveInvisible(stmt)
|
||||||
|
stmt = strings.TrimSpace(stmt)
|
||||||
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
||||||
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
|
@ -552,7 +553,11 @@ func searchBySQL(stmt string, beforeLen int) (ret []*Block, matchedBlockCount, m
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = strings.ToLower(stmt)
|
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)
|
result, _ := sql.Query(stmt)
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue