From 1aa991ae1f1a426424549c92060b204114c8b3c2 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 11 May 2024 14:34:15 +0200 Subject: refactor: deduce index path automatically from config.DataPath --- internal/search/indexer.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'internal/search/indexer.go') diff --git a/internal/search/indexer.go b/internal/search/indexer.go index c00c358..87cb12f 100644 --- a/internal/search/indexer.go +++ b/internal/search/indexer.go @@ -28,8 +28,6 @@ type WriteIndex struct { index bleve.Index } -const ExpectedIndexExtension = ".bleve" - func createIndexMapping() (mapping.IndexMapping, error) { indexMapping := bleve.NewIndexMapping() indexMapping.StoreDynamic = false @@ -125,10 +123,14 @@ func createIndex(indexPath string) (bleve.Index, error) { return idx, nil } -func NewIndexer(indexPath string, force bool) (*WriteIndex, error) { +const indexBaseName = "index.bleve" + +func NewIndexer(dataRoot string, force bool) (*WriteIndex, error) { var err error bleve.SetLog(log.Default()) + indexPath := path.Join(dataRoot, indexBaseName) + exists, err := file.Exists(indexPath) if err != nil { return nil, errors.WithMessagef( @@ -141,13 +143,6 @@ func NewIndexer(indexPath string, force bool) (*WriteIndex, error) { var idx bleve.Index if !exists || force { if force { - if path.Ext(indexPath) != ExpectedIndexExtension { - return nil, errors.Errorf( - "cowardly refusing to delete path %s (it doesn't end in '%s')", - indexPath, - ExpectedIndexExtension, - ) - } err := os.RemoveAll(indexPath) if err != nil { return nil, errors.WithMessagef(err, "could not remove index file %s", indexPath) -- cgit 1.4.1