From 49e9b4147f668eccf8100dfb25b79664b9dbe669 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 2 Dec 2022 17:48:52 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=90=9C=E7=B4=A2=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/6766?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/search.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/kernel/model/search.go b/kernel/model/search.go index 9c8d5c3c5..36d91ca28 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -319,21 +319,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b query = strings.TrimSpace(query) beforeLen := 36 var blocks []*Block - - var orderByClause string - switch orderBy { - case 1: - orderByClause = "ORDER BY created ASC" - case 2: - orderByClause = "ORDER BY created DESC" - case 3: - orderByClause = "ORDER BY updated ASC" - case 4: - orderByClause = "ORDER BY updated DESC" - default: - orderByClause = "ORDER BY sort ASC" - } - + orderByClause := buildOrderBy(orderBy) switch method { case 1: // 查询语法 filter := buildTypeFilter(types) @@ -436,6 +422,21 @@ func buildPathsFilter(paths []string) string { return builder.String() } +func buildOrderBy(orderBy int) string { + switch orderBy { + case 1: + return "ORDER BY created ASC" + case 2: + return "ORDER BY created DESC" + case 3: + return "ORDER BY updated ASC" + case 4: + return "ORDER BY updated DESC" + default: + return "ORDER BY sort ASC" + } +} + func buildTypeFilter(types map[string]bool) string { s := conf.NewSearch() if err := copier.Copy(s, Conf.Search); nil != err {