all repos — searchix @ 13c673dab5bd4e3a23c89304635034137fdbc78f

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

refactor: move interfaces closer to usage

Alan Pearce
commit

13c673dab5bd4e3a23c89304635034137fdbc78f

parent

40f7fe5cb75c254cf595b9ad50de6de99fd78c7b

1 file changed, 16 insertions(+), 6 deletions(-)

changed files
M internal/index/indexer.gointernal/index/indexer.go
@@ -10,7 +10,6 @@ "alin.ovh/searchix/internal/config"
"alin.ovh/searchix/internal/file" "alin.ovh/searchix/internal/index/meta" "alin.ovh/searchix/internal/index/nixattr" - "alin.ovh/searchix/internal/nix" "alin.ovh/x/log" "github.com/Southclaws/fault"
@@ -50,6 +49,17 @@ }
type BatchError struct { error +} + +type Indexable interface { + ImporterType() string + BleveType() string + GetName() string + GetSource() string +} + +func GetKey(i Indexable) string { + return i.ImporterType() + "/" + i.GetSource() + "/" + i.GetName() } var idAnalyzer analysis.Analyzer
@@ -317,13 +327,13 @@ }
func (i *WriteIndex) Import( ctx context.Context, - objects <-chan nix.Importable, + objects <-chan Indexable, errs chan<- error, ) error { indexMapping := i.index.Mapping() - return i.WithBatchObjects(ctx, objects, errs, func(batch *bleve.Batch, obj nix.Importable) error { - doc := document.NewDocument(nix.GetKey(obj)) + return i.WithBatchObjects(ctx, objects, errs, func(batch *bleve.Batch, obj Indexable) error { + doc := document.NewDocument(GetKey(obj)) if err := indexMapping.MapDocument(doc, obj); err != nil { return fault.Wrap(err, fmsg.Withf("could not map document for object: %s", obj.GetName())) }
@@ -369,9 +379,9 @@ }
func (i *WriteIndex) WithBatchObjects( ctx context.Context, - objects <-chan nix.Importable, + objects <-chan Indexable, errs chan<- error, - processor func(batch *bleve.Batch, obj nix.Importable) error, + processor func(batch *bleve.Batch, obj Indexable) error, ) error { k := 0 batch := i.index.NewBatch()