all repos — searchix @ 12a29a55fe895a964d8d317857ee7fb87d4071f1

Search engine for NixOS, nix-darwin, home-manager and NUR users

fix: always re-index if storage is (re-)created

Alan Pearce
commit

12a29a55fe895a964d8d317857ee7fb87d4071f1

parent

15a5b3210a073c83dbd1ace8969df83c53dac755

1 file changed, 14 insertions(+), 8 deletions(-)

changed files
M internal/index/indexer.gointernal/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 {