This commit is contained in:
Liang Ding 2022-12-09 12:08:07 +08:00
parent dd617d6089
commit 167b0fda6f
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
9 changed files with 37 additions and 7 deletions

View file

@ -314,8 +314,8 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
// FullTextSearchBlock 搜索内容块。
//
// method0文本1查询语法2SQL3正则表达式
// orderBy: 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时
// method0关键字1查询语法2SQL3正则表达式
// orderBy: 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序
// groupBy0不分组1按文档分组
func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
query = strings.TrimSpace(query)
@ -335,7 +335,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
boxFilter := buildBoxesFilter(boxes)
pathFilter := buildPathsFilter(paths)
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByRegexp(query, boxFilter, pathFilter, typeFilter, orderByClause, beforeLen)
default: // 文本
default: // 关键字
filter := buildTypeFilter(types)
boxFilter := buildBoxesFilter(boxes)
pathFilter := buildPathsFilter(paths)
@ -411,7 +411,9 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
case 4: // 按更新时间降序
sort.Slice(roots, func(i, j int) bool { return roots[i].Updated > roots[j].Updated })
case 5: // 按内容顺序(仅在按文档分组时)
// 都是文档,不需要再次排序
// 都是文档,不需要再次排序
case 6, 7: // 按相关度
// 已在 ORDER BY 中处理
default: // 按块类型(默认)
// 都是文档,不需要再次排序
}
@ -467,6 +469,10 @@ func buildOrderBy(orderBy int) string {
return "ORDER BY updated ASC"
case 4:
return "ORDER BY updated DESC"
case 6:
return "ORDER BY rank DESC" // 默认是按相关度降序,所以按相关度升序要反过来使用 DESC
case 7:
return "ORDER BY rank" // 默认是按相关度降序
default:
return "ORDER BY sort ASC"
}