mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
⚡ Return document blocks when search hits different block content https://github.com/siyuan-note/siyuan/issues/10584
This commit is contained in:
parent
7072577328
commit
b599c87112
1 changed files with 8 additions and 7 deletions
|
|
@ -1402,15 +1402,16 @@ func fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignor
|
||||||
" FROM blocks WHERE type IN " + typeFilter + boxFilter + pathFilter + ignoreFilter +
|
" FROM blocks WHERE type IN " + typeFilter + boxFilter + pathFilter + ignoreFilter +
|
||||||
" GROUP BY root_id HAVING " + likeFilter + "ORDER BY " + orderByLike + " DESC, MAX(updated) DESC"
|
" GROUP BY root_id HAVING " + likeFilter + "ORDER BY " + orderByLike + " DESC, MAX(updated) DESC"
|
||||||
cteStmt := "WITH docBlocks AS (" + dMatchStmt + ")"
|
cteStmt := "WITH docBlocks AS (" + dMatchStmt + ")"
|
||||||
pagingStmt := " LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa((page-1)*pageSize)
|
|
||||||
likeFilter = strings.ReplaceAll(likeFilter, "GROUP_CONCAT("+contentField+")", "concatContent")
|
likeFilter = strings.ReplaceAll(likeFilter, "GROUP_CONCAT("+contentField+")", "concatContent")
|
||||||
selectStmt := cteStmt + "\nSELECT *, " +
|
selectStmt := cteStmt + "\nSELECT *, " +
|
||||||
"(content || tag || name || alias || memo) AS concatContent, " +
|
"(content || tag || name || alias || memo) AS concatContent, " +
|
||||||
"(SELECT COUNT(root_id) FROM docBlocks) AS `docs` FROM blocks" +
|
"(SELECT COUNT(root_id) FROM docBlocks) AS docs, " +
|
||||||
" WHERE type IN " + typeFilter + boxFilter + pathFilter + ignoreFilter +
|
"(CASE WHEN (root_id IN (SELECT root_id FROM docBlocks) AND (" + strings.ReplaceAll(likeFilter, "concatContent", contentField) + ")) THEN 1 ELSE 0 END) AS blockSort" +
|
||||||
" AND (id IN (SELECT root_id FROM docBlocks" + pagingStmt + ") OR" +
|
" FROM blocks WHERE type IN " + typeFilter + boxFilter + pathFilter + ignoreFilter +
|
||||||
" (root_id IN (SELECT root_id FROM docBlocks" + pagingStmt + ") AND (" + likeFilter + ")))"
|
" AND (id IN (SELECT root_id FROM docBlocks) OR" +
|
||||||
selectStmt += " " + orderBy + " LIMIT 10240000"
|
" (root_id IN (SELECT root_id FROM docBlocks) AND (" + likeFilter + ")))"
|
||||||
|
selectStmt += " " + strings.Replace(orderBy, "END ASC, ", "END ASC, blockSort DESC, ", 1) +
|
||||||
|
" LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa((page-1)*pageSize)
|
||||||
result, _ := sql.Query(selectStmt, -1)
|
result, _ := sql.Query(selectStmt, -1)
|
||||||
var resultBlocks []*sql.Block
|
var resultBlocks []*sql.Block
|
||||||
for _, row := range result {
|
for _, row := range result {
|
||||||
|
|
@ -1451,7 +1452,7 @@ func fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignor
|
||||||
ret = []*Block{}
|
ret = []*Block{}
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.LogInfof("time cost [all]: %v", time.Since(start))
|
logging.LogInfof("time cost [search]: %v", time.Since(start))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue