From 190ab07b9815b6bdc73a8a4f5e7661e56710e7d3 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 1 Dec 2025 18:58:53 +0800 Subject: [PATCH] :art: Improve searching for move blocks Signed-off-by: Daniel <845765@qq.com> --- kernel/api/filetree.go | 10 +++++++++- kernel/model/file.go | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index 170bee298..39fdff05c 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -1034,8 +1034,16 @@ func searchDocs(c *gin.Context) { flashcard = arg["flashcard"].(bool) } + var excludeIDs []string + if arg["excludeIDs"] != nil { + excludeIDsArg := arg["excludeIDs"].([]interface{}) + for _, excludeID := range excludeIDsArg { + excludeIDs = append(excludeIDs, excludeID.(string)) + } + } + k := arg["k"].(string) - ret.Data = model.SearchDocsByKeyword(k, flashcard) + ret.Data = model.SearchDocsByKeyword(k, flashcard, excludeIDs) } func listDocsByPath(c *gin.Context) { diff --git a/kernel/model/file.go b/kernel/model/file.go index 5e1f3c2ab..c53f3d5eb 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -139,7 +139,7 @@ func (box *Box) moveCorruptedData(filePath string) { logging.LogWarnf("moved corrupted data file [%s] to [%s]", filePath, to) } -func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]string) { +func SearchDocsByKeyword(keyword string, flashcard bool, excludeIDs []string) (ret []map[string]string) { ret = []map[string]string{} var deck *riff.Deck @@ -187,6 +187,10 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin } } + if 0 < len(excludeIDs) { + condition += fmt.Sprintf(" AND root_id NOT IN ('%s')", strings.Join(excludeIDs, "', '")) + } + rootBlocks = sql.QueryRootBlockByCondition(condition, Conf.Search.Limit) } else { for _, box := range boxes {