fix: always re-index if storage is (re-)created
1 file changed, 14 insertions(+), 8 deletions(-)
changed files
M internal/index/indexer.go → internal/index/indexer.go
@@ -42,6 +42,7 @@ batchSize int index bleve.Index log *log.Logger store *storage.Store + exists bool Meta *Meta }@@ -220,14 +221,14 @@ return nil } -func OpenOrCreate(options *Options) (*ReadIndex, *WriteIndex, bool, error) { +func OpenOrCreate(options *Options) (*ReadIndex, *WriteIndex, error) { var err error bleve.SetLog(zap.NewStdLog(options.Logger.Named("bleve").GetLogger())) root := options.Root exists, err := root.Exists(indexBaseName) if err != nil { - return nil, nil, exists, fault.Wrap( + return nil, nil, fault.Wrap( err, fmsg.Withf("could not check if index exists at path %s", indexBaseName)) }@@ -237,17 +238,17 @@ if !exists || options.Force { if options.Force { err = deleteIndex(root) if err != nil { - return nil, nil, false, err + return nil, nil, err } } idx, err = createIndex(root, options) if err != nil { - return nil, nil, false, err + return nil, nil, err } meta, err = createMeta(root, options.Logger) if err != nil { - return nil, nil, false, err + return nil, nil, err } } else {@@ -256,12 +257,12 @@ //nolint:forbidigo // external package indexPath := root.JoinPath(indexBaseName) idx, baseErr = bleve.Open(indexPath) if baseErr != nil { - return nil, nil, exists, fault.Wrap(baseErr, fmsg.Withf("could not open index at path %s", indexPath)) + return nil, nil, fault.Wrap(baseErr, fmsg.Withf("could not open index at path %s", indexPath)) } meta, err = openMeta(root, options.Logger) if err != nil { - return nil, nil, exists, err + return nil, nil, err } }@@ -277,18 +278,23 @@ return &ReadIndex{ config: options.Config, log: options.Logger, store: options.Store, + exists: exists, index: idx, meta: meta, }, &WriteIndex{ + exists: exists, index: idx, batchSize: options.BatchSize, log: options.Logger, store: options.Store, Meta: meta, }, - exists, nil +} + +func (i *WriteIndex) Exists() bool { + return i.exists } func (i *WriteIndex) SaveMeta() error {