An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: `Replace All` is no longer affected by pagination https://github.com/siyuan-note/siyuan/issues/8265
Danielecd4a58d0323
diff --git a/kernel/api/search.go b/kernel/api/search.goindex 17f33cb209..f99868a7b4 100644--- a/kernel/api/search.go+++ b/kernel/api/search.go@@ -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:查询语法,2:SQL,3:正则表达式- if nil != methodArg {- method = int(methodArg.(float64))- }idsArg := arg["ids"].([]interface{})var ids []stringfor _, 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 = -1ret.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 = 1if 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 []stringif 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)}}++ // method:0:关键字,1:查询语法,2:SQL,3:正则表达式methodArg := arg["method"]- var method int // 0:关键字,1:查询语法,2:SQL,3:正则表达式if nil != methodArg {method = int(methodArg.(float64))}++ // orderBy:0:按块类型(默认),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}diff --git a/kernel/model/search.go b/kernel/model/search.goindex b255b8d28c..fe213b8786 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -207,7 +207,7 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBracketsreturn}-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) {// method:0:文本,1:查询语法,2:SQL,3:正则表达式if 1 == method || 2 == method {err = errors.New(Conf.Language(132))@@ -232,6 +232,13 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err errreturn}+ 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 {bt := treenode.GetBlockTree(id)if nil == bt {