mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-21 06:24:06 +01:00
🎨 Global search supports pagination to display results https://github.com/siyuan-note/siyuan/issues/7948
This commit is contained in:
parent
685b7e1383
commit
1eba131624
6 changed files with 21 additions and 12 deletions
|
|
@ -409,7 +409,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
|
|||
pathFilter := buildPathsFilter(paths)
|
||||
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, filter, orderByClause, beforeLen, page)
|
||||
case 2: // SQL
|
||||
blocks, matchedBlockCount, matchedRootCount = searchBySQL(query, beforeLen)
|
||||
blocks, matchedBlockCount, matchedRootCount = searchBySQL(query, beforeLen, page)
|
||||
case 3: // 正则表达式
|
||||
typeFilter := buildTypeFilter(types)
|
||||
boxFilter := buildBoxesFilter(boxes)
|
||||
|
|
@ -600,10 +600,10 @@ func buildTypeFilter(types map[string]bool) string {
|
|||
return s.TypeFilter()
|
||||
}
|
||||
|
||||
func searchBySQL(stmt string, beforeLen int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||
func searchBySQL(stmt string, beforeLen, page int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||
stmt = gulu.Str.RemoveInvisible(stmt)
|
||||
stmt = strings.TrimSpace(stmt)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, page, Conf.Search.Limit)
|
||||
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
||||
if 1 > len(ret) {
|
||||
ret = []*Block{}
|
||||
|
|
@ -630,7 +630,7 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []
|
|||
keyword = gulu.Str.RemoveInvisible(keyword)
|
||||
|
||||
if ast.IsNodeIDPattern(keyword) {
|
||||
ret, _, _ = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+keyword+"'", 36)
|
||||
ret, _, _ = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+keyword+"'", 36, 1)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -682,7 +682,7 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []
|
|||
func fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, orderBy string, beforeLen, page int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||
query = gulu.Str.RemoveInvisible(query)
|
||||
if ast.IsNodeIDPattern(query) {
|
||||
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen)
|
||||
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page)
|
||||
return
|
||||
}
|
||||
return fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy, beforeLen, page)
|
||||
|
|
@ -691,7 +691,7 @@ func fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, order
|
|||
func fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter string, orderBy string, beforeLen, page int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||
query = gulu.Str.RemoveInvisible(query)
|
||||
if ast.IsNodeIDPattern(query) {
|
||||
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen)
|
||||
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page)
|
||||
return
|
||||
}
|
||||
query = stringQuery(query)
|
||||
|
|
@ -747,7 +747,7 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
|
|||
stmt += boxFilter + pathFilter
|
||||
stmt += " " + orderBy
|
||||
stmt += " LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa((page-1)*pageSize)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, Conf.Search.Limit)
|
||||
blocks := sql.SelectBlocksRawStmt(stmt, page, Conf.Search.Limit)
|
||||
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
||||
if 1 > len(ret) {
|
||||
ret = []*Block{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue