parent
72aa63adce
commit
6e23c8b4c0
@ -143,6 +143,10 @@ func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Del(ctx context.Context, prefix string) error {
|
||||||
|
return instance.Del(ctx, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
func Clear(ctx context.Context) error {
|
func Clear(ctx context.Context) error {
|
||||||
return instance.Clear(ctx)
|
return instance.Clear(ctx)
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ type BuildIndexReq struct {
|
|||||||
Paths []string `json:"paths"`
|
Paths []string `json:"paths"`
|
||||||
MaxDepth int `json:"max_depth"`
|
MaxDepth int `json:"max_depth"`
|
||||||
IgnorePaths []string `json:"ignore_paths"`
|
IgnorePaths []string `json:"ignore_paths"`
|
||||||
|
Clear bool `json:"clear"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildIndex(c *gin.Context) {
|
func BuildIndex(c *gin.Context) {
|
||||||
@ -33,10 +34,21 @@ func BuildIndex(c *gin.Context) {
|
|||||||
ignorePaths = append(ignorePaths, req.IgnorePaths...)
|
ignorePaths = append(ignorePaths, req.IgnorePaths...)
|
||||||
go func() {
|
go func() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err := search.Clear(ctx)
|
var err error
|
||||||
if err != nil {
|
if req.Clear {
|
||||||
log.Errorf("clear index error: %+v", err)
|
err = search.Clear(ctx)
|
||||||
return
|
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)
|
err = search.BuildIndex(context.Background(), req.Paths, ignorePaths, req.MaxDepth, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user