From 07e74577ffafe1e6187a439e230eb63601757625 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 29 Aug 2022 00:17:29 +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=E5=92=8C=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=E5=92=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/4901?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/history.go | 29 +++++++++++++++++++++++++++++ kernel/api/router.go | 2 ++ kernel/model/history.go | 5 +++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/kernel/api/history.go b/kernel/api/history.go index bf64d1800..28feb9ce6 100644 --- a/kernel/api/history.go +++ b/kernel/api/history.go @@ -26,6 +26,35 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func searchHistory(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + query := arg["query"].(string) + page := int(arg["page"].(float64)) + histories := model.FullTextSearchHistory(query, page) + ret.Data = map[string]interface{}{ + "histories": histories, + } +} + +func reindexHistory(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + err := model.ReindexHistory() + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } +} + func getNotebookHistory(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index 5e3f24e94..2c851eb9e 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -101,6 +101,8 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/history/getDocHistoryContent", model.CheckAuth, getDocHistoryContent) ginServer.Handle("POST", "/api/history/rollbackDocHistory", model.CheckAuth, model.CheckReadonly, rollbackDocHistory) ginServer.Handle("POST", "/api/history/clearWorkspaceHistory", model.CheckAuth, model.CheckReadonly, clearWorkspaceHistory) + ginServer.Handle("POST", "/api/history/reindexHistory", model.CheckAuth, model.CheckReadonly, reindexHistory) + ginServer.Handle("POST", "/api/history/searchHistory", model.CheckAuth, model.CheckReadonly, searchHistory) ginServer.Handle("POST", "/api/outline/getDocOutline", model.CheckAuth, getDocOutline) ginServer.Handle("POST", "/api/bookmark/getBookmark", model.CheckAuth, getBookmark) diff --git a/kernel/model/history.go b/kernel/model/history.go index ed1e12538..0ac0e6139 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -611,7 +611,7 @@ func GetHistoryDir(suffix string) (ret string, err error) { return } -func indexHistory() { +func ReindexHistory() (err error) { historyDirs, err := os.ReadDir(util.HistoryDir) if nil != err { logging.LogErrorf("read history dir [%s] failed: %s", util.HistoryDir, err) @@ -630,6 +630,7 @@ func indexHistory() { return } } + return } var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat} @@ -713,7 +714,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) (err error) { return } -func fullTextSearchHistory(query string, page int) (ret []*History, matchedBlockCount, matchedRootCount int) { +func FullTextSearchHistory(query string, page int) (ret []*History) { query = gulu.Str.RemoveInvisible(query) query = stringQuery(query)