mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 搜索支持按相关度排序 https://github.com/siyuan-note/siyuan/issues/6827
This commit is contained in:
parent
dd617d6089
commit
167b0fda6f
9 changed files with 37 additions and 7 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"sortByRankDesc": "Relevance DESC",
|
||||||
|
"sortByRankAsc": "Relevance ASC",
|
||||||
"saveCriterion": "Save named criterion",
|
"saveCriterion": "Save named criterion",
|
||||||
"useCriterion": "Use named criterion",
|
"useCriterion": "Use named criterion",
|
||||||
"group": "Group",
|
"group": "Group",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"sortByRankDesc": "Relevancia DESC",
|
||||||
|
"sortByRankAsc": "Relevancia ASC",
|
||||||
"saveCriterion": "Guardar criterio nombrado",
|
"saveCriterion": "Guardar criterio nombrado",
|
||||||
"useCriterion": "Usar criterio con nombre",
|
"useCriterion": "Usar criterio con nombre",
|
||||||
"grupo": "Grupo",
|
"grupo": "Grupo",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"sortByRankDesc": "DESC de pertinence",
|
||||||
|
"sortByRankAsc": "ASC de pertinence",
|
||||||
"saveCriterion": "Enregistrer le critère nommé",
|
"saveCriterion": "Enregistrer le critère nommé",
|
||||||
"useCriterion": "Utiliser le critère nommé",
|
"useCriterion": "Utiliser le critère nommé",
|
||||||
"groupe": "Groupe",
|
"groupe": "Groupe",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"sortByRankDesc": "按相關度降序",
|
||||||
|
"sortByRankAsc": "按相關度升序",
|
||||||
"saveCriterion": "保存命名查詢",
|
"saveCriterion": "保存命名查詢",
|
||||||
"useCriterion": "使用命名查詢",
|
"useCriterion": "使用命名查詢",
|
||||||
"group": "分組",
|
"group": "分組",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
|
"sortByRankDesc": "按相关度降序",
|
||||||
|
"sortByRankAsc": "按相关度升序",
|
||||||
"saveCriterion": "保存命名查询",
|
"saveCriterion": "保存命名查询",
|
||||||
"useCriterion": "使用命名查询",
|
"useCriterion": "使用命名查询",
|
||||||
"group": "分组",
|
"group": "分组",
|
||||||
|
|
|
||||||
|
|
@ -597,6 +597,20 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
|
||||||
config.sort = 4;
|
config.sort = 4;
|
||||||
inputEvent(element, config, undefined, edit);
|
inputEvent(element, config, undefined, edit);
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
label: window.siyuan.languages.sortByRankAsc,
|
||||||
|
current: config.sort === 6,
|
||||||
|
click() {
|
||||||
|
config.sort = 6;
|
||||||
|
inputEvent(element, config, undefined, edit);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
label: window.siyuan.languages.sortByRankDesc,
|
||||||
|
current: config.sort === 7,
|
||||||
|
click() {
|
||||||
|
config.sort = 7;
|
||||||
|
inputEvent(element, config, undefined, edit);
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
if (config.group === 1) {
|
if (config.group === 1) {
|
||||||
sortMenu.push({
|
sortMenu.push({
|
||||||
|
|
|
||||||
2
app/src/types/index.d.ts
vendored
2
app/src/types/index.d.ts
vendored
|
|
@ -53,7 +53,7 @@ interface Window {
|
||||||
|
|
||||||
interface ISearchOption {
|
interface ISearchOption {
|
||||||
name?: string
|
name?: string
|
||||||
sort: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时)
|
sort: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序
|
||||||
group: number, // 0:不分组,1:按文档分组
|
group: number, // 0:不分组,1:按文档分组
|
||||||
layout: number // 0:上下,1:左右
|
layout: number // 0:上下,1:左右
|
||||||
hasReplace: boolean,
|
hasReplace: boolean,
|
||||||
|
|
|
||||||
|
|
@ -219,12 +219,12 @@ func fullTextSearchBlock(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
methodArg := arg["method"]
|
methodArg := arg["method"]
|
||||||
var method int // 0:文本,1:查询语法,2:SQL,3:正则表达式
|
var method int // 0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||||
if nil != methodArg {
|
if nil != methodArg {
|
||||||
method = int(methodArg.(float64))
|
method = int(methodArg.(float64))
|
||||||
}
|
}
|
||||||
orderByArg := arg["orderBy"]
|
orderByArg := arg["orderBy"]
|
||||||
var orderBy int // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时)
|
var orderBy int // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序
|
||||||
if nil != orderByArg {
|
if nil != orderByArg {
|
||||||
orderBy = int(orderByArg.(float64))
|
orderBy = int(orderByArg.(float64))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -314,8 +314,8 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
||||||
|
|
||||||
// FullTextSearchBlock 搜索内容块。
|
// FullTextSearchBlock 搜索内容块。
|
||||||
//
|
//
|
||||||
// method:0:文本,1:查询语法,2:SQL,3:正则表达式
|
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||||
// orderBy: 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时)
|
// orderBy: 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序
|
||||||
// groupBy:0:不分组,1:按文档分组
|
// groupBy:0:不分组,1:按文档分组
|
||||||
func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bool, method, orderBy, groupBy int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||||
query = strings.TrimSpace(query)
|
query = strings.TrimSpace(query)
|
||||||
|
|
@ -335,7 +335,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
|
||||||
boxFilter := buildBoxesFilter(boxes)
|
boxFilter := buildBoxesFilter(boxes)
|
||||||
pathFilter := buildPathsFilter(paths)
|
pathFilter := buildPathsFilter(paths)
|
||||||
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByRegexp(query, boxFilter, pathFilter, typeFilter, orderByClause, beforeLen)
|
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByRegexp(query, boxFilter, pathFilter, typeFilter, orderByClause, beforeLen)
|
||||||
default: // 文本
|
default: // 关键字
|
||||||
filter := buildTypeFilter(types)
|
filter := buildTypeFilter(types)
|
||||||
boxFilter := buildBoxesFilter(boxes)
|
boxFilter := buildBoxesFilter(boxes)
|
||||||
pathFilter := buildPathsFilter(paths)
|
pathFilter := buildPathsFilter(paths)
|
||||||
|
|
@ -411,7 +411,9 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
|
||||||
case 4: // 按更新时间降序
|
case 4: // 按更新时间降序
|
||||||
sort.Slice(roots, func(i, j int) bool { return roots[i].Updated > roots[j].Updated })
|
sort.Slice(roots, func(i, j int) bool { return roots[i].Updated > roots[j].Updated })
|
||||||
case 5: // 按内容顺序(仅在按文档分组时)
|
case 5: // 按内容顺序(仅在按文档分组时)
|
||||||
// 都是文档,不需要再次排序
|
// 都是文档,不需要再次排序
|
||||||
|
case 6, 7: // 按相关度
|
||||||
|
// 已在 ORDER BY 中处理
|
||||||
default: // 按块类型(默认)
|
default: // 按块类型(默认)
|
||||||
// 都是文档,不需要再次排序
|
// 都是文档,不需要再次排序
|
||||||
}
|
}
|
||||||
|
|
@ -467,6 +469,10 @@ func buildOrderBy(orderBy int) string {
|
||||||
return "ORDER BY updated ASC"
|
return "ORDER BY updated ASC"
|
||||||
case 4:
|
case 4:
|
||||||
return "ORDER BY updated DESC"
|
return "ORDER BY updated DESC"
|
||||||
|
case 6:
|
||||||
|
return "ORDER BY rank DESC" // 默认是按相关度降序,所以按相关度升序要反过来使用 DESC
|
||||||
|
case 7:
|
||||||
|
return "ORDER BY rank" // 默认是按相关度降序
|
||||||
default:
|
default:
|
||||||
return "ORDER BY sort ASC"
|
return "ORDER BY sort ASC"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue