feat: add database non full text index (close #2916)

This commit is contained in:
BoYanZh
2023-01-07 01:40:49 +08:00
committed by GitHub
parent 1c453ae147
commit 7902b646ff
5 changed files with 74 additions and 11 deletions

View File

@ -0,0 +1,16 @@
package db
import (
"github.com/alist-org/alist/v3/internal/search/searcher"
)
var config = searcher.Config{
Name: "database_non_full_text",
AutoUpdate: true,
}
func init() {
searcher.RegisterSearcher(config, func() (searcher.Searcher, error) {
return &DB{}, nil
})
}

View File

@ -0,0 +1,45 @@
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, false)
}
func (D DB) Index(ctx context.Context, node model.SearchNode) error {
return db.CreateSearchNode(&node)
}
func (D DB) BatchIndex(ctx context.Context, nodes []model.SearchNode) error {
return db.BatchCreateSearchNodes(&nodes)
}
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)