From 9f241bff227608dd53a250d012116077dce6dab6 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 17 May 2024 15:51:27 +0200 Subject: feat: automatically add/remove sources to/from index --- internal/index/search.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'internal/index/search.go') diff --git a/internal/index/search.go b/internal/index/search.go index 5c18edb..0b20063 100644 --- a/internal/index/search.go +++ b/internal/index/search.go @@ -29,6 +29,25 @@ type ReadIndex struct { meta *Meta } +func (index *ReadIndex) GetEnabledSources() ([]string, error) { + facet := bleve.NewFacetRequest("Source", 100) + query := bleve.NewMatchAllQuery() + search := bleve.NewSearchRequest(query) + search.AddFacet("Source", facet) + + results, err := index.index.Search(search) + if err != nil { + return nil, errors.WithMessage(err, "could not get list of enabled sources from index") + } + + enabledSources := make([]string, results.Facets["Source"].Terms.Len()) + for i, term := range results.Facets["Source"].Terms.Terms() { + enabledSources[i] = term.Term + } + + return enabledSources, nil +} + func (index *ReadIndex) GetSource(ctx context.Context, name string) (*bleve.SearchResult, error) { query := bleve.NewTermQuery(name) query.SetField("Source") -- cgit 1.4.1