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

View file

@ -207,7 +207,7 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets
return return
} }
func FindReplace(keyword, replacement string, ids []string, method int) (err error) { func FindReplace(keyword, replacement string, ids []string, paths, boxes []string, types map[string]bool, method, orderBy, groupBy int) (err error) {
// method0文本1查询语法2SQL3正则表达式 // method0文本1查询语法2SQL3正则表达式
if 1 == method || 2 == method { if 1 == method || 2 == method {
err = errors.New(Conf.Language(132)) err = errors.New(Conf.Language(132))
@ -232,6 +232,13 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
return return
} }
if 1 > len(ids) {
blocks, _, _, _ := FullTextSearchBlock(keyword, boxes, paths, types, method, orderBy, groupBy, 1)
for _, block := range blocks {
ids = append(ids, block.ID)
}
}
for _, id := range ids { for _, id := range ids {
bt := treenode.GetBlockTree(id) bt := treenode.GetBlockTree(id)
if nil == bt { if nil == bt {