diff --git a/solr/query.go b/solr/query.go index 22f75c9..834dd34 100644 --- a/solr/query.go +++ b/solr/query.go @@ -62,6 +62,13 @@ func (q *Query) AddFacet(f string) { q.params.Add("facet.field", f) } +// fq (FacetQuery) https://wiki.apache.org/solr/SimpleFacetParameters#facet.query_:_Arbitrary_Query_Faceting +// Example: price:[* TO 500] +func (q *Query) AddFacetQuery(fq string) { + q.params.Set("facet", "true") + q.params.Add("facet.query", fq) +} + // mc (Facet min count) https://cwiki.apache.org/confluence/display/solr/Faceting#Faceting-Thefacet.mincountParameter // Example: 5 func (q *Query) SetFacetMinCount(mc int) { diff --git a/solr/query_test.go b/solr/query_test.go index ac18199..fda7195 100644 --- a/solr/query_test.go +++ b/solr/query_test.go @@ -169,6 +169,17 @@ func TestSolrQueryAddFacet(t *testing.T) { } } +func TestSolrQueryAddFacetQuery(t *testing.T) { + q := NewQuery() + q.AddFacetQuery("price:[* TO 500]") + q.AddFacetQuery("price:[501 TO *]") + expected := "facet=true&facet.query=price%3A%5B%2A+TO+500%5D&facet.query=price%3A%5B501+TO+%2A%5D" + result := q.String() + if result != expected { + t.Errorf("expected '%s' but got '%s'", expected, result) + } +} + func TestSolrQuerySetFacetMinCount(t *testing.T) { q := NewQuery() q.SetFacetMinCount(10)