feat: multiple search indexes (#2514)
* refactor: abstract search interface * wip: ~ * fix cycle import * objs update hook * wip: ~ * Delete search/none * auto update index while cache changed * db searcher TODO: bleve init issue cannot open index, metadata missing * fix size type why float64?? * fix typo * fix nil pointer using * api adapt ui * bleve: fix clear & change struct
This commit is contained in:
9
internal/search/searcher/manage.go
Normal file
9
internal/search/searcher/manage.go
Normal file
@ -0,0 +1,9 @@
|
||||
package searcher
|
||||
|
||||
type New func() (Searcher, error)
|
||||
|
||||
var NewMap = map[string]New{}
|
||||
|
||||
func RegisterSearcher(config Config, searcher New) {
|
||||
NewMap[config.Name] = searcher
|
||||
}
|
29
internal/search/searcher/searcher.go
Normal file
29
internal/search/searcher/searcher.go
Normal file
@ -0,0 +1,29 @@
|
||||
package searcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
AutoUpdate bool
|
||||
}
|
||||
|
||||
type Searcher interface {
|
||||
// Config of the searcher
|
||||
Config() Config
|
||||
// Search specific keywords in specific path
|
||||
Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64, error)
|
||||
// Index obj with parent
|
||||
Index(ctx context.Context, parent string, obj model.Obj) error
|
||||
// Get by parent
|
||||
Get(ctx context.Context, parent string) ([]model.SearchNode, error)
|
||||
// Del with prefix
|
||||
Del(ctx context.Context, prefix string) error
|
||||
// Release resource
|
||||
Release(ctx context.Context) error
|
||||
// Clear all index
|
||||
Clear(ctx context.Context) error
|
||||
}
|
Reference in New Issue
Block a user