-
Notifications
You must be signed in to change notification settings - Fork 11
/
query_test.go
68 lines (62 loc) · 1.41 KB
/
query_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
package solr_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stevenferrer/solr-go"
)
func TestQuery(t *testing.T) {
a := assert.New(t)
got := solr.NewQuery(solr.NewDisMaxQueryParser().
Query("'solr rocks'").BuildParser()).
Queries(solr.M{
"query_filters": []solr.M{
{
"#size_tag": solr.M{
"field": solr.M{
"f": "size",
"query": "XL",
},
},
},
{
"#color_tag": solr.M{
"field": solr.M{
"f": "color",
"query": "Red",
},
},
},
},
}).
Facets(
solr.NewTermsFacet("categories").
Field("cat").Limit(10),
solr.NewQueryFacet("high_popularity").
Query("popularity:[8 TO 10]"),
).
Sort("score").
Offset(1).
Limit(10).
Filters("inStock:true").
Fields("name", "price").
BuildQuery()
expect := solr.M{
"facet": solr.M{
"categories": solr.M{"field": "cat", "limit": 10, "type": "terms"},
"high_popularity": solr.M{"q": "popularity:[8 TO 10]", "type": "query"},
},
"fields": []string{"name", "price"},
"filter": []string{"inStock:true"},
"limit": 10,
"offset": 1,
"queries": solr.M{
"query_filters": []solr.M{
{"#size_tag": solr.M{"field": solr.M{"f": "size", "query": "XL"}}},
{"#color_tag": solr.M{"field": solr.M{"f": "color", "query": "Red"}}},
},
},
"query": "{!dismax v='solr rocks'}",
"sort": "score",
}
a.Equal(expect, got)
}