This commit is contained in:
Daniel 2023-08-11 10:28:32 +08:00
parent 298b95dea3
commit c96e815aa6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 84 additions and 21 deletions

View file

@ -26,6 +26,24 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func fullTextSearchAssetContent(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
page, pageSize, query, types, method, orderBy := parseSearchAssetContentArgs(arg)
assetContents, matchedAssetCount, pageCount := model.FullTextSearchAssetContent(query, types, method, orderBy, page, pageSize)
ret.Data = map[string]interface{}{
"assetContents": assetContents,
"matchedAssetCount": matchedAssetCount,
"pageCount": pageCount,
}
}
func findReplace(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@ -35,7 +53,7 @@ func findReplace(c *gin.Context) {
return
}
_, _, _, paths, boxes, types, method, orderBy, groupBy := parseSearchArgs(arg)
_, _, _, paths, boxes, types, method, orderBy, groupBy := parseSearchBlockArgs(arg)
k := arg["k"].(string)
r := arg["r"].(string)
@ -215,7 +233,7 @@ func fullTextSearchBlock(c *gin.Context) {
return
}
page, pageSize, query, paths, boxes, types, method, orderBy, groupBy := parseSearchArgs(arg)
page, pageSize, query, paths, boxes, types, method, orderBy, groupBy := parseSearchBlockArgs(arg)
blocks, matchedBlockCount, matchedRootCount, pageCount := model.FullTextSearchBlock(query, boxes, paths, types, method, orderBy, groupBy, page, pageSize)
ret.Data = map[string]interface{}{
"blocks": blocks,
@ -225,7 +243,7 @@ func fullTextSearchBlock(c *gin.Context) {
}
}
func parseSearchArgs(arg map[string]interface{}) (page, pageSize int, query string, paths, boxes []string, types map[string]bool, method, orderBy, groupBy int) {
func parseSearchBlockArgs(arg map[string]interface{}) (page, pageSize 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))
@ -291,3 +309,47 @@ func parseSearchArgs(arg map[string]interface{}) (page, pageSize int, query stri
}
return
}
func parseSearchAssetContentArgs(arg map[string]interface{}) (page, pageSize int, query string, types map[string]bool, method, orderBy int) {
page = 1
if nil != arg["page"] {
page = int(arg["page"].(float64))
}
if 0 >= page {
page = 1
}
pageSize = 32
if nil != arg["pageSize"] {
pageSize = int(arg["pageSize"].(float64))
}
if 0 >= pageSize {
pageSize = 32
}
queryArg := arg["query"]
if nil != queryArg {
query = queryArg.(string)
}
if nil != arg["types"] {
typesArg := arg["types"].(map[string]interface{})
types = map[string]bool{}
for t, b := range typesArg {
types[t] = b.(bool)
}
}
// method0关键字1查询语法2SQL3正则表达式
methodArg := arg["method"]
if nil != methodArg {
method = int(methodArg.(float64))
}
// orderBy0相关度默认1按更新时间升序2按更新时间降序
orderByArg := arg["orderBy"]
if nil != orderByArg {
orderBy = int(orderByArg.(float64))
}
return
}