feat: store data separate from search index
1 file changed, 34 insertions(+), 2 deletions(-)
changed files
M internal/index/search_test.go → internal/index/search_test.go
@@ -12,6 +12,7 @@ "alin.ovh/searchix/internal/config" "alin.ovh/searchix/internal/file" "alin.ovh/searchix/internal/index" "alin.ovh/searchix/internal/nix" + "alin.ovh/searchix/internal/storage" "alin.ovh/x/log" )@@ -27,12 +28,23 @@ t.Fatal(err) } defer root.Close() + store, err := storage.New(&storage.Options{ + Root: root, + Logger: log.Named("storage"), + }) + if err != nil { + t.Fatal(err) + } + defer store.Close() + read, _, exists, err := index.OpenOrCreate(&index.Options{ Logger: log.Named("index"), Root: root, BatchSize: cfg.Importer.BatchSize, Force: false, LowMemory: false, + Store: store, + Config: &cfg, }) if err != nil { t.Fatal(err)@@ -73,7 +85,11 @@ "gitSVN": 0, } var i int for hit := range result.Hits { - data := hit.Data.(nix.Package) + data, ok := hit.Data.(*nix.Package) + if !ok { + t.Fatalf("Expected hit.Data to be *nix.Package, got %T", hit.Data) + } + if _, found := important[data.Attribute]; found { important[data.Attribute] = i }@@ -99,11 +115,23 @@ t.Fatal(err) } defer root.Close() + store, err := storage.New(&storage.Options{ + Root: root, + Logger: log, + }) + if err != nil { + t.Fatal(err) + } + defer store.Close() + read, _, exists, err := index.OpenOrCreate(&index.Options{ Force: false, LowMemory: false, Logger: log.Named("index"), Root: root, + BatchSize: 0, + Store: store, + Config: &cfg, }) if err != nil { t.Fatal(err)@@ -147,7 +175,11 @@ unwanted := "javacc" unwantedIndex := math.MaxInt var i int for hit := range result.Hits { - data := hit.Data.(nix.Package) + data, ok := hit.Data.(*nix.Package) + if !ok { + t.Fatalf("Expected hit.Data to be *nix.Package, got %T", hit.Data) + } + if _, found := important[data.Attribute]; found { matches = append(matches, data.Attribute) } else if data.Attribute == unwanted {