diff --git a/internal/search/build.go b/internal/search/build.go index 8156685b..0ab519a0 100644 --- a/internal/search/build.go +++ b/internal/search/build.go @@ -143,6 +143,10 @@ func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth return nil } +func Del(ctx context.Context, prefix string) error { + return instance.Del(ctx, prefix) +} + func Clear(ctx context.Context) error { return instance.Clear(ctx) } diff --git a/server/handles/index.go b/server/handles/index.go index afd5e2c8..5c781066 100644 --- a/server/handles/index.go +++ b/server/handles/index.go @@ -13,6 +13,7 @@ type BuildIndexReq struct { Paths []string `json:"paths"` MaxDepth int `json:"max_depth"` IgnorePaths []string `json:"ignore_paths"` + Clear bool `json:"clear"` } func BuildIndex(c *gin.Context) { @@ -33,10 +34,21 @@ func BuildIndex(c *gin.Context) { ignorePaths = append(ignorePaths, req.IgnorePaths...) go func() { ctx := context.Background() - err := search.Clear(ctx) - if err != nil { - log.Errorf("clear index error: %+v", err) - return + var err error + if req.Clear { + err = search.Clear(ctx) + if err != nil { + log.Errorf("clear index error: %+v", err) + return + } + } else { + for _, path := range req.Paths { + err = search.Del(ctx, path) + if err != nil { + log.Errorf("delete index on %s error: %+v", path, err) + return + } + } } err = search.BuildIndex(context.Background(), req.Paths, ignorePaths, req.MaxDepth, true) if err != nil {