feat: partial update index (close #2593 close #2621 pr #2624)

This commit is contained in:
BoYanZh 2022-12-07 10:41:52 +08:00 committed by GitHub
parent 72aa63adce
commit 6e23c8b4c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -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)
}

View File

@ -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 {