An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve global search type sorting https://github.com/siyuan-note/siyuan/issues/11537
Danielc511795eb559
diff --git a/kernel/model/search.go b/kernel/model/search.goindex 7fc3010449..3faf632ef5 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -853,7 +853,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]bbeforeLen := 36var 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)