Skip to content

Commit 6e23c8b

Browse files
authored
feat: partial update index (close #2593 close #2621 pr #2624)
1 parent 72aa63a commit 6e23c8b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

internal/search/build.go

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth
143143
return nil
144144
}
145145

146+
func Del(ctx context.Context, prefix string) error {
147+
return instance.Del(ctx, prefix)
148+
}
149+
146150
func Clear(ctx context.Context) error {
147151
return instance.Clear(ctx)
148152
}

server/handles/index.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type BuildIndexReq struct {
1313
Paths []string `json:"paths"`
1414
MaxDepth int `json:"max_depth"`
1515
IgnorePaths []string `json:"ignore_paths"`
16+
Clear bool `json:"clear"`
1617
}
1718

1819
func BuildIndex(c *gin.Context) {
@@ -33,10 +34,21 @@ func BuildIndex(c *gin.Context) {
3334
ignorePaths = append(ignorePaths, req.IgnorePaths...)
3435
go func() {
3536
ctx := context.Background()
36-
err := search.Clear(ctx)
37-
if err != nil {
38-
log.Errorf("clear index error: %+v", err)
39-
return
37+
var err error
38+
if req.Clear {
39+
err = search.Clear(ctx)
40+
if err != nil {
41+
log.Errorf("clear index error: %+v", err)
42+
return
43+
}
44+
} else {
45+
for _, path := range req.Paths {
46+
err = search.Del(ctx, path)
47+
if err != nil {
48+
log.Errorf("delete index on %s error: %+v", path, err)
49+
return
50+
}
51+
}
4052
}
4153
err = search.BuildIndex(context.Background(), req.Paths, ignorePaths, req.MaxDepth, true)
4254
if err != nil {

0 commit comments

Comments
 (0)