fix: filename char mapping while build index

This commit is contained in:
Noah Hsu 2022-11-28 21:08:11 +08:00
parent 76f37373e0
commit e98561ceb1
6 changed files with 21 additions and 17 deletions

View File

@ -45,13 +45,8 @@ func (b *Bleve) Search(ctx context.Context, req model.SearchReq) ([]model.Search
return res, int64(len(res)), nil
}
func (b *Bleve) Index(ctx context.Context, parent string, obj model.Obj) error {
return b.BIndex.Index(uuid.NewString(), model.SearchNode{
Parent: parent,
Name: obj.GetName(),
IsDir: obj.IsDir(),
Size: obj.GetSize(),
})
func (b *Bleve) Index(ctx context.Context, node model.SearchNode) error {
return b.BIndex.Index(uuid.NewString(), node)
}
func (b *Bleve) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {

View File

@ -63,7 +63,7 @@ func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth
if indexPath == "/" {
return nil
}
err = instance.Index(ctx, path.Dir(indexPath), info)
err = Index(ctx, path.Dir(indexPath), info)
if err != nil {
return err
} else {

View File

@ -18,13 +18,8 @@ func (D DB) Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode
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) Index(ctx context.Context, node model.SearchNode) error {
return db.CreateSearchNode(&node)
}
func (D DB) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {

View File

@ -6,8 +6,10 @@ import (
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/search/searcher"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
)
@ -46,6 +48,18 @@ func Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64
return instance.Search(ctx, req)
}
func Index(ctx context.Context, parent string, obj model.Obj) error {
if instance == nil {
return errs.SearchNotAvailable
}
return instance.Index(ctx, model.SearchNode{
Parent: parent,
Name: utils.MappingName(obj.GetName(), conf.FilenameCharMap),
IsDir: obj.IsDir(),
Size: obj.GetSize(),
})
}
func init() {
db.RegisterSettingItemHook(conf.SearchIndex, func(item *model.SettingItem) error {
log.Debugf("searcher init, mode: %s", item.Value)

View File

@ -17,7 +17,7 @@ type Searcher interface {
// 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
Index(ctx context.Context, node model.SearchNode) error
// Get by parent
Get(ctx context.Context, parent string) ([]model.SearchNode, error)
// Del with prefix

View File

@ -51,7 +51,7 @@ func Update(parent string, objs []model.Obj) {
}
for i := range objs {
if toAdd.Contains(objs[i].GetName()) {
err = instance.Index(ctx, parent, objs[i])
err = Index(ctx, parent, objs[i])
if err != nil {
log.Errorf("update search index error while index new node: %+v", err)
return