|
@@ -853,7 +853,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
|
|
|
|
|
|
beforeLen := 36
|
|
|
var blocks []*Block
|
|
|
- orderByClause := buildOrderBy(method, orderBy)
|
|
|
+ orderByClause := buildOrderBy(query, method, orderBy)
|
|
|
switch method {
|
|
|
case 1: // 查询语法
|
|
|
filter := buildTypeFilter(types)
|
|
@@ -992,7 +992,7 @@ func buildPathsFilter(paths []string) string {
|
|
|
return builder.String()
|
|
|
}
|
|
|
|
|
|
-func buildOrderBy(method, orderBy int) string {
|
|
|
+func buildOrderBy(query string, method, orderBy int) string {
|
|
|
switch orderBy {
|
|
|
case 1:
|
|
|
return "ORDER BY created ASC"
|
|
@@ -1014,7 +1014,14 @@ func buildOrderBy(method, orderBy int) string {
|
|
|
}
|
|
|
return "ORDER BY rank" // 默认是按相关度降序
|
|
|
default:
|
|
|
- return "ORDER BY sort ASC, updated DESC" // Improve search default sort https://github.com/siyuan-note/siyuan/issues/8624
|
|
|
+ clause := "ORDER BY CASE " +
|
|
|
+ "WHEN name = '${keyword}' THEN 10 " +
|
|
|
+ "WHEN alias = '${keyword}' THEN 20 " +
|
|
|
+ "WHEN name LIKE '%${keyword}%' THEN 50 " +
|
|
|
+ "WHEN alias LIKE '%${keyword}%' THEN 60 " +
|
|
|
+ "ELSE 65535 END ASC, sort ASC, updated DESC"
|
|
|
+ clause = strings.ReplaceAll(clause, "${keyword}", strings.ReplaceAll(query, "'", "''"))
|
|
|
+ return clause
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1146,21 +1153,21 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []
|
|
|
stmt += notLike.String()
|
|
|
}
|
|
|
|
|
|
- orderBy := ` order by case
|
|
|
- when name = '${keyword}' then 10
|
|
|
- when alias = '${keyword}' then 20
|
|
|
- when memo = '${keyword}' then 30
|
|
|
- when content = '${keyword}' and type = 'd' then 40
|
|
|
- when content LIKE '%${keyword}%' and type = 'd' then 41
|
|
|
- when name LIKE '%${keyword}%' then 50
|
|
|
- when alias LIKE '%${keyword}%' then 60
|
|
|
- when content = '${keyword}' and type = 'h' then 70
|
|
|
- when content LIKE '%${keyword}%' and type = 'h' then 71
|
|
|
- when fcontent = '${keyword}' and type = 'i' then 80
|
|
|
- when fcontent LIKE '%${keyword}%' and type = 'i' then 81
|
|
|
- when memo LIKE '%${keyword}%' then 90
|
|
|
- when content LIKE '%${keyword}%' and type != 'i' and type != 'l' then 100
|
|
|
- else 65535 end ASC, sort ASC, length ASC`
|
|
|
+ orderBy := ` ORDER BY CASE
|
|
|
+ WHEN name = '${keyword}' THEN 10
|
|
|
+ WHEN alias = '${keyword}' THEN 20
|
|
|
+ WHEN memo = '${keyword}' THEN 30
|
|
|
+ WHEN content = '${keyword}' and type = 'd' THEN 40
|
|
|
+ WHEN content LIKE '%${keyword}%' and type = 'd' THEN 41
|
|
|
+ WHEN name LIKE '%${keyword}%' THEN 50
|
|
|
+ WHEN alias LIKE '%${keyword}%' THEN 60
|
|
|
+ WHEN content = '${keyword}' and type = 'h' THEN 70
|
|
|
+ WHEN content LIKE '%${keyword}%' and type = 'h' THEN 71
|
|
|
+ WHEN fcontent = '${keyword}' and type = 'i' THEN 80
|
|
|
+ WHEN fcontent LIKE '%${keyword}%' and type = 'i' THEN 81
|
|
|
+ WHEN memo LIKE '%${keyword}%' THEN 90
|
|
|
+ WHEN content LIKE '%${keyword}%' and type != 'i' and type != 'l' THEN 100
|
|
|
+ ELSE 65535 END ASC, sort ASC, length ASC`
|
|
|
orderBy = strings.ReplaceAll(orderBy, "${keyword}", strings.ReplaceAll(keyword, "'", "''"))
|
|
|
stmt += orderBy + " LIMIT " + strconv.Itoa(Conf.Search.Limit)
|
|
|
blocks := sql.SelectBlocksRawStmtNoParse(stmt, Conf.Search.Limit)
|