From c5c24994a8654be5c6ee5a1b99fd722e7278861b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 21 Apr 2023 10:03:05 +0800 Subject: [PATCH] :art: Global search supports pagination to display results https://github.com/siyuan-note/siyuan/issues/7948 --- kernel/api/search.go | 3 +-- kernel/model/search.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/api/search.go b/kernel/api/search.go index 204158ffd..dc8fc57e7 100644 --- a/kernel/api/search.go +++ b/kernel/api/search.go @@ -267,12 +267,11 @@ func fullTextSearchBlock(c *gin.Context) { if nil != groupByArg { groupBy = int(groupByArg.(float64)) } - blocks, matchedBlockCount, matchedRootCount, pageCount, totalCount := model.FullTextSearchBlock(query, boxes, paths, types, method, orderBy, groupBy, page) + blocks, matchedBlockCount, matchedRootCount, pageCount := model.FullTextSearchBlock(query, boxes, paths, types, method, orderBy, groupBy, page) ret.Data = map[string]interface{}{ "blocks": blocks, "matchedBlockCount": matchedBlockCount, "matchedRootCount": matchedRootCount, "pageCount": pageCount, - "totalCount": totalCount, } } diff --git a/kernel/model/search.go b/kernel/model/search.go index 87a0e38ec..4e72e182d 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -397,7 +397,7 @@ const pageSize = 32 // method:0:关键字,1:查询语法,2:SQL,3:正则表达式 // orderBy: 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序 // groupBy:0:不分组,1:按文档分组 -func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy, page int) (ret []*Block, matchedBlockCount, matchedRootCount, pageCount, totalCount int) { +func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy, page int) (ret []*Block, matchedBlockCount, matchedRootCount, pageCount int) { query = strings.TrimSpace(query) beforeLen := 36 var blocks []*Block @@ -421,6 +421,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b pathFilter := buildPathsFilter(paths) blocks, matchedBlockCount, matchedRootCount = fullTextSearchByKeyword(query, boxFilter, pathFilter, filter, orderByClause, beforeLen, page) } + pageCount = (matchedBlockCount + pageSize - 1) / pageSize switch groupBy { case 0: // 不分组