-
Notifications
You must be signed in to change notification settings - Fork 10
/
facet_test.go
70 lines (61 loc) · 1.56 KB
/
facet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package solr_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stevenferrer/solr-go"
)
func TestFacets(t *testing.T) {
t.Run("terms facet", func(t *testing.T) {
queryFacet := solr.NewQueryFacet("high_popularity").
Query("popularity:[8 TO 10]")
facet := solr.NewTermsFacet("categories").
Field("cat").Limit(5).Offset(1).Sort("price asc").
MinCount(1).AddFacets(queryFacet).
AddToFacet("average_price", "avg(price)").
AddToDomain("excludeTags", "top")
got := facet.BuildFacet()
expect := solr.M{
"type": "terms",
"field": "cat",
"limit": 5,
"offset": 1,
"sort": "price asc",
"mincount": 1,
"facet": solr.M{
"average_price": "avg(price)",
"high_popularity": solr.M{
"type": "query",
"q": "popularity:[8 TO 10]",
},
},
"domain": solr.M{
"excludeTags": "top",
},
}
assert.Equal(t, "categories", facet.Name())
assert.Equal(t, expect, got)
})
t.Run("query facet", func(f *testing.T) {
termsFacet := solr.NewTermsFacet("categories").
Field("cat").Limit(5)
facet := solr.NewQueryFacet("high_popularity").
Query("popularity:[8 TO 10]").
AddFacet(termsFacet).
AddToFacet("average_price", "avg(price)")
got := facet.BuildFacet()
expect := solr.M{
"type": "query",
"q": "popularity:[8 TO 10]",
"facet": solr.M{
"average_price": "avg(price)",
"categories": solr.M{
"type": "terms",
"field": "cat",
"limit": 5,
},
},
}
assert.Equal(t, "high_popularity", facet.Name())
assert.Equal(t, expect, got)
})
}