fix: filename char mapping while build index
This commit is contained in:
parent
76f37373e0
commit
e98561ceb1
@ -45,13 +45,8 @@ func (b *Bleve) Search(ctx context.Context, req model.SearchReq) ([]model.Search
|
|||||||
return res, int64(len(res)), nil
|
return res, int64(len(res)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bleve) Index(ctx context.Context, parent string, obj model.Obj) error {
|
func (b *Bleve) Index(ctx context.Context, node model.SearchNode) error {
|
||||||
return b.BIndex.Index(uuid.NewString(), model.SearchNode{
|
return b.BIndex.Index(uuid.NewString(), node)
|
||||||
Parent: parent,
|
|
||||||
Name: obj.GetName(),
|
|
||||||
IsDir: obj.IsDir(),
|
|
||||||
Size: obj.GetSize(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bleve) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {
|
func (b *Bleve) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {
|
||||||
|
@ -63,7 +63,7 @@ func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth
|
|||||||
if indexPath == "/" {
|
if indexPath == "/" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err = instance.Index(ctx, path.Dir(indexPath), info)
|
err = Index(ctx, path.Dir(indexPath), info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,13 +18,8 @@ func (D DB) Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode
|
|||||||
return db.SearchNode(req)
|
return db.SearchNode(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (D DB) Index(ctx context.Context, parent string, obj model.Obj) error {
|
func (D DB) Index(ctx context.Context, node model.SearchNode) error {
|
||||||
return db.CreateSearchNode(&model.SearchNode{
|
return db.CreateSearchNode(&node)
|
||||||
Parent: parent,
|
|
||||||
Name: obj.GetName(),
|
|
||||||
IsDir: obj.IsDir(),
|
|
||||||
Size: obj.GetSize(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (D DB) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {
|
func (D DB) Get(ctx context.Context, parent string) ([]model.SearchNode, error) {
|
||||||
|
@ -6,8 +6,10 @@ import (
|
|||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"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/model"
|
||||||
"github.com/alist-org/alist/v3/internal/search/searcher"
|
"github.com/alist-org/alist/v3/internal/search/searcher"
|
||||||
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
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)
|
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() {
|
func init() {
|
||||||
db.RegisterSettingItemHook(conf.SearchIndex, func(item *model.SettingItem) error {
|
db.RegisterSettingItemHook(conf.SearchIndex, func(item *model.SettingItem) error {
|
||||||
log.Debugf("searcher init, mode: %s", item.Value)
|
log.Debugf("searcher init, mode: %s", item.Value)
|
||||||
|
@ -17,7 +17,7 @@ type Searcher interface {
|
|||||||
// Search specific keywords in specific path
|
// Search specific keywords in specific path
|
||||||
Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64, error)
|
Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64, error)
|
||||||
// Index obj with parent
|
// 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 by parent
|
||||||
Get(ctx context.Context, parent string) ([]model.SearchNode, error)
|
Get(ctx context.Context, parent string) ([]model.SearchNode, error)
|
||||||
// Del with prefix
|
// Del with prefix
|
||||||
|
@ -51,7 +51,7 @@ func Update(parent string, objs []model.Obj) {
|
|||||||
}
|
}
|
||||||
for i := range objs {
|
for i := range objs {
|
||||||
if toAdd.Contains(objs[i].GetName()) {
|
if toAdd.Contains(objs[i].GetName()) {
|
||||||
err = instance.Index(ctx, parent, objs[i])
|
err = Index(ctx, parent, objs[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("update search index error while index new node: %+v", err)
|
log.Errorf("update search index error while index new node: %+v", err)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user