mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
✨ Support for searching asset content https://github.com/siyuan-note/siyuan/issues/8874
This commit is contained in:
parent
a169b3913a
commit
4b96ead36a
2 changed files with 15 additions and 4 deletions
|
|
@ -365,7 +365,7 @@ func parseSearchAssetContentArgs(arg map[string]interface{}) (page, pageSize int
|
||||||
method = int(methodArg.(float64))
|
method = int(methodArg.(float64))
|
||||||
}
|
}
|
||||||
|
|
||||||
// orderBy:0:相关度(默认),1:按更新时间升序,2:按更新时间降序
|
// orderBy:0:按相关度降序,1:按相关度升序,2:按更新时间升序,3:按更新时间降序
|
||||||
orderByArg := arg["orderBy"]
|
orderByArg := arg["orderBy"]
|
||||||
if nil != orderByArg {
|
if nil != orderByArg {
|
||||||
orderBy = int(orderByArg.(float64))
|
orderBy = int(orderByArg.(float64))
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ func GetAssetContent(id, query string, queryMethod int) (ret *AssetContent) {
|
||||||
// FullTextSearchAssetContent 搜索资源文件内容。
|
// FullTextSearchAssetContent 搜索资源文件内容。
|
||||||
//
|
//
|
||||||
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||||
// orderBy: 0:相关度(默认),1:按更新时间升序,2:按更新时间降序
|
// orderBy: 0:按相关度降序,1:按相关度升序,2:按更新时间升序,3:按更新时间降序
|
||||||
func FullTextSearchAssetContent(query string, types map[string]bool, method, orderBy, page, pageSize int) (ret []*AssetContent, matchedAssetCount, pageCount int) {
|
func FullTextSearchAssetContent(query string, types map[string]bool, method, orderBy, page, pageSize int) (ret []*AssetContent, matchedAssetCount, pageCount int) {
|
||||||
query = strings.TrimSpace(query)
|
query = strings.TrimSpace(query)
|
||||||
beforeLen := 36
|
beforeLen := 36
|
||||||
|
|
@ -238,11 +238,20 @@ func buildAssetContentTypeFilter(types map[string]bool) string {
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("(")
|
buf.WriteString("(")
|
||||||
for k, _ := range types {
|
for k, enabled := range types {
|
||||||
|
if !enabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
buf.WriteString("'")
|
buf.WriteString("'")
|
||||||
buf.WriteString(k)
|
buf.WriteString(k)
|
||||||
buf.WriteString("',")
|
buf.WriteString("',")
|
||||||
}
|
}
|
||||||
|
if 1 == buf.Len() {
|
||||||
|
buf.WriteString(")")
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
buf.Truncate(buf.Len() - 1)
|
buf.Truncate(buf.Len() - 1)
|
||||||
buf.WriteString(")")
|
buf.WriteString(")")
|
||||||
return buf.String()
|
return buf.String()
|
||||||
|
|
@ -253,8 +262,10 @@ func buildAssetContentOrderBy(orderBy int) string {
|
||||||
case 0:
|
case 0:
|
||||||
return "ORDER BY rank DESC"
|
return "ORDER BY rank DESC"
|
||||||
case 1:
|
case 1:
|
||||||
return "ORDER BY updated ASC"
|
return "ORDER BY rank ASC"
|
||||||
case 2:
|
case 2:
|
||||||
|
return "ORDER BY updated ASC"
|
||||||
|
case 3:
|
||||||
return "ORDER BY updated DESC"
|
return "ORDER BY updated DESC"
|
||||||
default:
|
default:
|
||||||
return "ORDER BY rank DESC"
|
return "ORDER BY rank DESC"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue