🎨 Replace All is no longer affected by pagination https://github.com/siyuan-note/siyuan/issues/8265

This commit is contained in:
Daniel 2023-06-29 18:06:04 +08:00
parent dce9d4da54
commit ecd4a58d03
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 36 additions and 21 deletions

View file

@ -35,19 +35,16 @@ func findReplace(c *gin.Context) {
return
}
_, _, paths, boxes, types, method, orderBy, groupBy := parseSearchArgs(arg)
k := arg["k"].(string)
r := arg["r"].(string)
methodArg := arg["method"]
var method int // 0文本1查询语法2SQL3正则表达式
if nil != methodArg {
method = int(methodArg.(float64))
}
idsArg := arg["ids"].([]interface{})
var ids []string
for _, id := range idsArg {
ids = append(ids, id.(string))
}
err := model.FindReplace(k, r, ids, method)
err := model.FindReplace(k, r, ids, paths, boxes, types, method, orderBy, groupBy)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
@ -218,7 +215,18 @@ func fullTextSearchBlock(c *gin.Context) {
return
}
page := 1
page, query, paths, boxes, types, method, orderBy, groupBy := parseSearchArgs(arg)
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,
}
}
func parseSearchArgs(arg map[string]interface{}) (page int, query string, paths, boxes []string, types map[string]bool, method, orderBy, groupBy int) {
page = 1
if nil != arg["page"] {
page = int(arg["page"].(float64))
}
@ -226,9 +234,12 @@ func fullTextSearchBlock(c *gin.Context) {
page = 1
}
query := arg["query"].(string)
queryArg := arg["query"]
if nil != queryArg {
query = queryArg.(string)
}
pathsArg := arg["paths"]
var paths, boxes []string
if nil != pathsArg {
for _, p := range pathsArg.([]interface{}) {
path := p.(string)
@ -244,7 +255,7 @@ func fullTextSearchBlock(c *gin.Context) {
paths = gulu.Str.RemoveDuplicatedElem(paths)
boxes = gulu.Str.RemoveDuplicatedElem(boxes)
}
var types map[string]bool
if nil != arg["types"] {
typesArg := arg["types"].(map[string]interface{})
types = map[string]bool{}
@ -252,26 +263,23 @@ func fullTextSearchBlock(c *gin.Context) {
types[t] = b.(bool)
}
}
// method0关键字1查询语法2SQL3正则表达式
methodArg := arg["method"]
var method int // 0关键字1查询语法2SQL3正则表达式
if nil != methodArg {
method = int(methodArg.(float64))
}
// orderBy0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序
orderByArg := arg["orderBy"]
var orderBy int // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序
if nil != orderByArg {
orderBy = int(orderByArg.(float64))
}
// groupBy 0不分组1按文档分组
groupByArg := arg["groupBy"]
var groupBy int // 0不分组1按文档分组
if nil != groupByArg {
groupBy = int(groupByArg.(float64))
}
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,
}
return
}