about summary refs log tree commit diff stats
path: root/internal/index
diff options
context:
space:
mode:
authorAlan Pearce2024-05-16 20:22:42 +0200
committerAlan Pearce2024-05-16 20:31:03 +0200
commitc51ca7c62e08f43ef9974af35886d30ce54a1f22 (patch)
tree6779f521c289d1750ceb35b57fbb0d3acad20385 /internal/index
parent0ef52f2f82c62694c5420f7f6c82fb8c45900d1d (diff)
downloadsearchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.tar.lz
searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.tar.zst
searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.zip
refactor: use interface to unify Options and Packages
Diffstat (limited to 'internal/index')
-rw-r--r--internal/index/indexer.go22
-rw-r--r--internal/index/search.go4
2 files changed, 13 insertions, 13 deletions
diff --git a/internal/index/indexer.go b/internal/index/indexer.go
index 63cf1a6..e1de710 100644
--- a/internal/index/indexer.go
+++ b/internal/index/indexer.go
@@ -10,7 +10,7 @@ import (
 	"os"
 	"path"
 	"searchix/internal/file"
-	"searchix/internal/options"
+	"searchix/internal/nix"
 	"slices"
 
 	"github.com/blevesearch/bleve/v2"
@@ -225,9 +225,9 @@ func OpenOrCreate(dataRoot string, force bool) (*ReadIndex, *WriteIndex, bool, e
 		nil
 }
 
-func (i *WriteIndex) ImportOptions(
+func (i *WriteIndex) Import(
 	ctx context.Context,
-	objects <-chan *options.NixOption,
+	objects <-chan nix.Importable,
 ) <-chan error {
 	var err error
 	errs := make(chan error)
@@ -238,7 +238,7 @@ func (i *WriteIndex) ImportOptions(
 		indexMapping := i.index.Mapping()
 
 	outer:
-		for opt := range objects {
+		for obj := range objects {
 			select {
 			case <-ctx.Done():
 				slog.Debug("context cancelled")
@@ -247,30 +247,30 @@ func (i *WriteIndex) ImportOptions(
 			default:
 			}
 
-			doc := document.NewDocument(opt.Source + "/" + opt.Name)
-			err = indexMapping.MapDocument(doc, opt)
+			doc := document.NewDocument(nix.GetKey(obj))
+			err = indexMapping.MapDocument(doc, obj)
 			if err != nil {
-				errs <- errors.WithMessagef(err, "could not map document for option: %s", opt.Name)
+				errs <- errors.WithMessagef(err, "could not map document for object: %s", obj.GetName())
 
 				continue
 			}
 
 			var data bytes.Buffer
 			enc := gob.NewEncoder(&data)
-			err = enc.Encode(opt)
+			err = enc.Encode(obj)
 			if err != nil {
-				errs <- errors.WithMessage(err, "could not store option in search index")
+				errs <- errors.WithMessage(err, "could not store object in search index")
 
 				continue
 			}
 			field := document.NewTextFieldWithIndexingOptions("_data", nil, data.Bytes(), indexAPI.StoreField)
 			newDoc := doc.AddField(field)
 
-			// slog.Debug("adding option to index", "name", opt.Name)
+			// slog.Debug("adding object to index", "name", opt.Name)
 			err = batch.IndexAdvanced(newDoc)
 
 			if err != nil {
-				errs <- errors.WithMessagef(err, "could not index option %s", opt.Name)
+				errs <- errors.WithMessagef(err, "could not index object %s", obj.GetName())
 
 				continue
 			}
diff --git a/internal/index/search.go b/internal/index/search.go
index d069510..a86cc02 100644
--- a/internal/index/search.go
+++ b/internal/index/search.go
@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"context"
 	"encoding/gob"
-	"searchix/internal/options"
+	"searchix/internal/nix"
 
 	"github.com/blevesearch/bleve/v2"
 	"github.com/blevesearch/bleve/v2/search"
@@ -15,7 +15,7 @@ const ResultsPerPage = 20
 
 type DocumentMatch struct {
 	search.DocumentMatch
-	Data options.NixOption
+	Data nix.Option
 }
 
 type Result struct {