about summary refs log tree commit diff stats
path: root/internal/index/search.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/index/search.go')
-rw-r--r--internal/index/search.go19
1 files changed, 19 insertions, 0 deletions
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")