Skip to content

Commit

Permalink
Fixed opening an existing index
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony V. Ozdemir committed May 31, 2023
1 parent 35550c9 commit f6dbf62
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions internal/task_handlers/indexers/basic_indexer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indexers

import (
"os"
"strings"

"github.com/blevesearch/bleve/v2"
Expand All @@ -15,12 +16,21 @@ type BasicIndexer struct {
}

func (b *BasicIndexer) Initialize(config config.TaskHandlerOptions, baseFolder string, outputLimit int64) error {
// Configure default indexing mapping
indexMapping := bleve.NewIndexMapping()
index, err := bleve.New(baseFolder, indexMapping)

// Try to open an existing index
index, err := bleve.Open(baseFolder)

// If the index doesn't exist, create a new one
if err != nil {
return err
if os.IsNotExist(err) {
indexMapping := bleve.NewIndexMapping()
index, err = bleve.New(baseFolder, indexMapping)
if err != nil {
return err
}
} else {
return err
}
}

b.index = index
Expand Down

0 comments on commit f6dbf62

Please sign in to comment.