This commit is contained in:
Daniel 2023-08-15 16:32:13 +08:00
parent a169b3913a
commit 4b96ead36a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 15 additions and 4 deletions

View file

@ -365,7 +365,7 @@ func parseSearchAssetContentArgs(arg map[string]interface{}) (page, pageSize int
method = int(methodArg.(float64)) method = int(methodArg.(float64))
} }
// orderBy0相关度默认1按更新时间升序2:按更新时间降序 // orderBy0按相关度降序1按相关度升序2按更新时间升序3:按更新时间降序
orderByArg := arg["orderBy"] orderByArg := arg["orderBy"]
if nil != orderByArg { if nil != orderByArg {
orderBy = int(orderByArg.(float64)) orderBy = int(orderByArg.(float64))

View file

@ -77,7 +77,7 @@ func GetAssetContent(id, query string, queryMethod int) (ret *AssetContent) {
// FullTextSearchAssetContent 搜索资源文件内容。 // FullTextSearchAssetContent 搜索资源文件内容。
// //
// method0关键字1查询语法2SQL3正则表达式 // method0关键字1查询语法2SQL3正则表达式
// 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"