refactor: use options struct for all arguments to index constructor
5 files changed, 18 insertions(+), 10 deletions(-)
M cmd/searchix-web/main.go → cmd/searchix-web/main.go
@@ -108,12 +108,12 @@ } defer root.Close() read, write, exists, err := index.OpenOrCreate( - root, - *replace, &index.Options{ + Force: *replace, LowMemory: cfg.Importer.LowMemory, BatchSize: cfg.Importer.BatchSize, Logger: logger.Named("index"), + Root: root, }, ) if err != nil {
M internal/importer/main.go → internal/importer/main.go
@@ -24,6 +24,7 @@ ) type Options struct { LowMemory bool + Offline bool Logger *log.Logger WriteIndex *index.WriteIndex Manpages *manpages.URLMap
M internal/importer/main_test.go → internal/importer/main_test.go
@@ -20,10 +20,12 @@ b.Fatal(err) } logger := log.Configure(false) - _, write, _, err := index.OpenOrCreate(tmp, false, &index.Options{ + _, write, _, err := index.OpenOrCreate(&index.Options{ + Force: false, LowMemory: true, BatchSize: cfg.Importer.BatchSize, Logger: logger.Named("index"), + Root: tmp, }) if err != nil { b.Fatal(err)
M internal/index/indexer.go → internal/index/indexer.go
@@ -34,9 +34,11 @@ var idAnalyzer analysis.Analyzer type Options struct { + Force bool LowMemory bool BatchSize int Logger *log.Logger + Root *file.Root } type WriteIndex struct {@@ -223,13 +225,12 @@ return nil } func OpenOrCreate( - root *file.Root, - force bool, options *Options, ) (*ReadIndex, *WriteIndex, bool, 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(@@ -238,8 +239,8 @@ } var idx bleve.Index var meta *Meta - if !exists || force { - if force { + if !exists || options.Force { + if options.Force { err = deleteIndex(root) if err != nil { return nil, nil, false, err
M internal/index/search_test.go → internal/index/search_test.go
@@ -27,9 +27,11 @@ t.Fatal(err) } defer root.Close() - read, _, exists, err := index.OpenOrCreate(root, false, &index.Options{ + read, _, exists, err := index.OpenOrCreate(&index.Options{ Logger: log.Named("index"), + Root: root, BatchSize: cfg.Importer.BatchSize, + Force: false, LowMemory: false, }) if err != nil {@@ -97,9 +99,11 @@ t.Fatal(err) } defer root.Close() - read, _, exists, err := index.OpenOrCreate(root, false, &index.Options{ - Logger: log.Named("index"), + read, _, exists, err := index.OpenOrCreate(&index.Options{ + Force: false, LowMemory: false, + Logger: log.Named("index"), + Root: root, }) if err != nil { t.Fatal(err)