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:
16
internal/search/db/init.go
Normal file
16
internal/search/db/init.go
Normal file
@ -0,0 +1,16 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/search/searcher"
|
||||
)
|
||||
|
||||
var config = searcher.Config{
|
||||
Name: "database",
|
||||
AutoUpdate: true,
|
||||
}
|
||||
|
||||
func init() {
|
||||
searcher.RegisterSearcher(config, func() (searcher.Searcher, error) {
|
||||
return &DB{}, nil
|
||||
})
|
||||
}
|
46
internal/search/db/search.go
Normal file
46
internal/search/db/search.go
Normal file
@ -0,0 +1,46 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/search/searcher"
|
||||
)
|
||||
|
||||
type DB struct{}
|
||||
|
||||
func (D DB) Config() searcher.Config {
|
||||
return config
|
||||
}
|
||||
|
||||
func (D DB) Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64, error) {
|
||||
return db.SearchNode(req)
|
||||
}
|
||||
|
||||
func (D DB) Index(ctx context.Context, parent string, obj model.Obj) error {
|
||||
return db.CreateSearchNode(&model.SearchNode{
|
||||
Parent: parent,
|
||||
Name: obj.GetName(),
|
||||
IsDir: obj.IsDir(),
|
||||
Size: obj.GetSize(),
|
||||
})
|
||||
}
|
||||
|
||||
func (D DB) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {
|
||||
return db.GetSearchNodesByParent(parent)
|
||||
}
|
||||
|
||||
func (D DB) Del(ctx context.Context, prefix string) error {
|
||||
return db.DeleteSearchNodesByParent(prefix)
|
||||
}
|
||||
|
||||
func (D DB) Release(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (D DB) Clear(ctx context.Context) error {
|
||||
return db.ClearSearchNodes()
|
||||
}
|
||||
|
||||
var _ searcher.Searcher = (*DB)(nil)
|
Reference in New Issue
Block a user