mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-27 20:08:49 +01:00
✨ Support for searching asset content https://github.com/siyuan-note/siyuan/issues/8874
This commit is contained in:
parent
298b95dea3
commit
c96e815aa6
3 changed files with 84 additions and 21 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||
methodArg := arg["method"]
|
||||
if nil != methodArg {
|
||||
method = int(methodArg.(float64))
|
||||
}
|
||||
|
||||
// orderBy:0:相关度(默认),1:按更新时间升序,2:按更新时间降序
|
||||
orderByArg := arg["orderBy"]
|
||||
if nil != orderByArg {
|
||||
orderBy = int(orderByArg.(float64))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue