From bd0ec0dcf2dc4168745b29613d293846f679a63a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 29 Aug 2022 21:37:56 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=95=B0=E6=8D=AE=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E6=94=AF=E6=8C=81=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BF=87=E6=BB=A4=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/5754?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/history.go | 6 +++++- kernel/model/history.go | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/api/history.go b/kernel/api/history.go index 4f1c50274..813f677f0 100644 --- a/kernel/api/history.go +++ b/kernel/api/history.go @@ -40,7 +40,11 @@ func searchHistory(c *gin.Context) { if nil != arg["page"] { page = int(arg["page"].(float64)) } - histories := model.FullTextSearchHistory(query, page) + op := "all" + if nil != arg["op"] { + op = arg["op"].(string) + } + histories := model.FullTextSearchHistory(query, op, page) ret.Data = map[string]interface{}{ "histories": histories, } diff --git a/kernel/model/history.go b/kernel/model/history.go index f52a9e4a2..e99a14b5c 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -275,7 +275,7 @@ func GetDocHistory(boxID string, page int) (ret []*History, err error) { return } -func FullTextSearchHistory(query string, page int) (ret []*History) { +func FullTextSearchHistory(query, op string, page int) (ret []*History) { query = gulu.Str.RemoveInvisible(query) query = stringQuery(query) @@ -284,8 +284,10 @@ func FullTextSearchHistory(query string, page int) (ret []*History) { to := page * pageSize table := "histories_fts_case_insensitive" - projections := "type, op, title, content, path, created" - stmt := "SELECT " + projections + " FROM " + table + " WHERE " + table + " MATCH '{title content}:(" + query + ")'" + stmt := "SELECT * FROM " + table + " WHERE " + table + " MATCH '{title content}:(" + query + ")'" + if "all" != op { + stmt += " AND op = '" + op + "'" + } stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(from) + ", " + strconv.Itoa(to) sqlHistories := sql.SelectHistoriesRawStmt(stmt) ret = fromSQLHistories(sqlHistories)