sunspot 2.2.7 → 2.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -8
- data/gemfiles/.gitkeep +0 -0
- data/lib/sunspot/dsl/scope.rb +6 -1
- data/lib/sunspot/field.rb +11 -0
- data/lib/sunspot/field_factory.rb +6 -2
- data/lib/sunspot/query/bbox.rb +5 -1
- data/lib/sunspot/query/restriction.rb +11 -0
- data/lib/sunspot/search/hit_enumerable.rb +4 -1
- data/lib/sunspot/search/standard_search.rb +2 -3
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/adapters_spec.rb +19 -19
- data/spec/api/batcher_spec.rb +15 -15
- data/spec/api/binding_spec.rb +3 -3
- data/spec/api/class_set_spec.rb +3 -3
- data/spec/api/hit_enumerable_spec.rb +32 -9
- data/spec/api/indexer/attributes_spec.rb +31 -31
- data/spec/api/indexer/batch_spec.rb +8 -7
- data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
- data/spec/api/indexer/fixed_fields_spec.rb +12 -12
- data/spec/api/indexer/fulltext_spec.rb +8 -8
- data/spec/api/indexer/removal_spec.rb +14 -14
- data/spec/api/indexer_spec.rb +2 -2
- data/spec/api/query/advanced_manipulation_examples.rb +3 -3
- data/spec/api/query/connectives_examples.rb +26 -14
- data/spec/api/query/dsl_spec.rb +17 -9
- data/spec/api/query/dynamic_fields_examples.rb +18 -18
- data/spec/api/query/faceting_examples.rb +62 -62
- data/spec/api/query/fulltext_examples.rb +56 -55
- data/spec/api/query/function_spec.rb +26 -26
- data/spec/api/query/geo_examples.rb +6 -6
- data/spec/api/query/group_spec.rb +6 -6
- data/spec/api/query/highlighting_examples.rb +26 -26
- data/spec/api/query/join_spec.rb +2 -2
- data/spec/api/query/more_like_this_spec.rb +29 -29
- data/spec/api/query/ordering_pagination_examples.rb +25 -25
- data/spec/api/query/scope_examples.rb +39 -39
- data/spec/api/query/spatial_examples.rb +3 -3
- data/spec/api/query/spellcheck_examples.rb +3 -3
- data/spec/api/query/standard_spec.rb +1 -1
- data/spec/api/query/stats_examples.rb +8 -8
- data/spec/api/query/text_field_scoping_examples.rb +5 -5
- data/spec/api/query/types_spec.rb +4 -4
- data/spec/api/search/cursor_paginated_collection_spec.rb +12 -12
- data/spec/api/search/dynamic_fields_spec.rb +4 -4
- data/spec/api/search/faceting_spec.rb +55 -52
- data/spec/api/search/highlighting_spec.rb +7 -7
- data/spec/api/search/hits_spec.rb +29 -29
- data/spec/api/search/paginated_collection_spec.rb +18 -18
- data/spec/api/search/results_spec.rb +13 -13
- data/spec/api/search/search_spec.rb +3 -3
- data/spec/api/search/stats_spec.rb +10 -10
- data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +19 -18
- data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +9 -9
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
- data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +10 -10
- data/spec/api/session_proxy/sharding_session_proxy_spec.rb +14 -13
- data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +2 -2
- data/spec/api/session_proxy/spec_helper.rb +1 -1
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +9 -5
- data/spec/api/session_spec.rb +42 -42
- data/spec/api/sunspot_spec.rb +4 -4
- data/spec/integration/atomic_updates_spec.rb +25 -11
- data/spec/integration/dynamic_fields_spec.rb +10 -10
- data/spec/integration/faceting_spec.rb +39 -39
- data/spec/integration/field_grouping_spec.rb +16 -16
- data/spec/integration/field_lists_spec.rb +41 -0
- data/spec/integration/geospatial_spec.rb +19 -8
- data/spec/integration/highlighting_spec.rb +5 -5
- data/spec/integration/indexing_spec.rb +5 -5
- data/spec/integration/keyword_search_spec.rb +47 -45
- data/spec/integration/local_search_spec.rb +4 -4
- data/spec/integration/more_like_this_spec.rb +7 -7
- data/spec/integration/scoped_search_spec.rb +107 -107
- data/spec/integration/spellcheck_spec.rb +52 -7
- data/spec/integration/stats_spec.rb +10 -10
- data/spec/integration/stored_fields_spec.rb +1 -1
- data/spec/integration/test_pagination.rb +4 -4
- data/spec/integration/unicode_spec.rb +1 -1
- data/spec/mocks/post.rb +5 -1
- data/spec/spec_helper.rb +11 -6
- data/sunspot.gemspec +3 -1
- metadata +40 -7
data/spec/api/indexer_spec.rb
CHANGED
@@ -7,8 +7,8 @@ describe 'indexer', :type => :indexer do
|
|
7
7
|
Object.class_eval { remove_const(:ReloadableClass) }
|
8
8
|
Object::ReloadableClass = Class.new(MockRecord)
|
9
9
|
Sunspot.setup(ReloadableClass) {}
|
10
|
-
|
10
|
+
expect do
|
11
11
|
Sunspot.search(ReloadableClass) { with(:title, 'title') }
|
12
|
-
end.
|
12
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
13
13
|
end
|
14
14
|
end
|
@@ -12,11 +12,11 @@ shared_examples_for "query with advanced manipulation" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "modifies existing param" do
|
15
|
-
connection.
|
15
|
+
expect(connection).to have_last_search_with(:rows => 40)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "adds new param" do
|
19
|
-
connection.
|
19
|
+
expect(connection).to have_last_search_with(:qt => 'complicated')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -29,7 +29,7 @@ shared_examples_for "query with advanced manipulation" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should use specified request handler' do
|
32
|
-
connection.
|
32
|
+
expect(connection).to have_last_search_with({})
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -6,7 +6,7 @@ shared_examples_for "query with connective scope" do
|
|
6
6
|
with :blog_id, 2
|
7
7
|
end
|
8
8
|
end
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_including(
|
10
10
|
:fq, '(category_ids_im:1 OR blog_id_i:2)'
|
11
11
|
)
|
12
12
|
end
|
@@ -21,7 +21,7 @@ shared_examples_for "query with connective scope" do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
connection.
|
24
|
+
expect(connection).to have_last_search_including(
|
25
25
|
:fq,
|
26
26
|
'(blog_id_i:2 OR (category_ids_im:1 AND average_rating_ft:{3\.0 TO *}))'
|
27
27
|
)
|
@@ -37,7 +37,7 @@ shared_examples_for "query with connective scope" do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
connection.
|
40
|
+
expect(connection).to have_last_search_including(
|
41
41
|
:fq, '(category_ids_im:1 OR (-average_rating_ft:{3\.0 TO *} AND blog_id_i:1))'
|
42
42
|
)
|
43
43
|
end
|
@@ -49,7 +49,7 @@ shared_examples_for "query with connective scope" do
|
|
49
49
|
with :category_ids, 1
|
50
50
|
end
|
51
51
|
end
|
52
|
-
connection.
|
52
|
+
expect(connection).to have_last_search_including(
|
53
53
|
:fq, 'blog_id_i:2', 'category_ids_im:1'
|
54
54
|
)
|
55
55
|
end
|
@@ -61,7 +61,7 @@ shared_examples_for "query with connective scope" do
|
|
61
61
|
without(:average_rating).greater_than(3.0)
|
62
62
|
end
|
63
63
|
end
|
64
|
-
connection.
|
64
|
+
expect(connection).to have_last_search_including(
|
65
65
|
:fq, '-(-category_ids_im:1 AND average_rating_ft:{3\.0 TO *})'
|
66
66
|
)
|
67
67
|
end
|
@@ -79,7 +79,7 @@ shared_examples_for "query with connective scope" do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
82
|
-
connection.
|
82
|
+
expect(connection).to have_last_search_including(
|
83
83
|
:fq, '-(title_ss:Yes AND -(blog_id_i:1 AND -(-category_ids_im:4 AND average_rating_ft:2\.0)))'
|
84
84
|
)
|
85
85
|
end
|
@@ -96,7 +96,7 @@ shared_examples_for "query with connective scope" do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
connection.
|
99
|
+
expect(connection).to have_last_search_including(
|
100
100
|
:fq, '(title_ss:Yes OR (blog_id_i:1 AND -(-category_ids_im:4 AND average_rating_ft:2\.0)))'
|
101
101
|
)
|
102
102
|
end
|
@@ -123,7 +123,7 @@ shared_examples_for "query with connective scope" do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
-
connection.
|
126
|
+
expect(connection).to have_last_search_including(
|
127
127
|
:fq, '(title_ss:Yes OR blog_id_i:1 OR category_ids_im:4)'
|
128
128
|
)
|
129
129
|
end
|
@@ -136,7 +136,7 @@ shared_examples_for "query with connective scope" do
|
|
136
136
|
with(:category_ids, 1)
|
137
137
|
end
|
138
138
|
end
|
139
|
-
connection.
|
139
|
+
expect(connection).to have_last_search_including(
|
140
140
|
:fq, "-(id:(Post\\ #{post.id}) AND -category_ids_im:1)"
|
141
141
|
)
|
142
142
|
end
|
@@ -148,7 +148,7 @@ shared_examples_for "query with connective scope" do
|
|
148
148
|
with(:average_rating).greater_than(3.0)
|
149
149
|
end
|
150
150
|
end
|
151
|
-
connection.
|
151
|
+
expect(connection).to have_last_search_including(
|
152
152
|
:fq, '-(average_rating_ft:[* TO *] AND -average_rating_ft:{3\.0 TO *})'
|
153
153
|
)
|
154
154
|
end
|
@@ -161,7 +161,7 @@ shared_examples_for "query with connective scope" do
|
|
161
161
|
with(:average_rating).greater_than(3.0)
|
162
162
|
end
|
163
163
|
end
|
164
|
-
connection.
|
164
|
+
expect(connection).to have_last_search_including(
|
165
165
|
:fq, "(id:(Post\\ #{post.id}) OR average_rating_ft:{3\\.0 TO *})"
|
166
166
|
)
|
167
167
|
end
|
@@ -175,7 +175,7 @@ shared_examples_for "query with connective scope" do
|
|
175
175
|
with(:blog_id, 1)
|
176
176
|
end
|
177
177
|
end
|
178
|
-
connection.
|
178
|
+
expect(connection).to have_last_search_including(
|
179
179
|
:fq, '(title_text:test* OR blog_id_i:1)'
|
180
180
|
)
|
181
181
|
end
|
@@ -184,7 +184,7 @@ shared_examples_for "query with connective scope" do
|
|
184
184
|
search do
|
185
185
|
any_of {}
|
186
186
|
end
|
187
|
-
connection.
|
187
|
+
expect(connection).not_to have_last_search_including(:fq, '')
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'creates a conjunction of in_radius queries' do
|
@@ -194,8 +194,20 @@ shared_examples_for "query with connective scope" do
|
|
194
194
|
with(:coordinates_new).in_radius(42, 56, 50)
|
195
195
|
end
|
196
196
|
end
|
197
|
-
connection.
|
197
|
+
expect(connection).to have_last_search_including(
|
198
198
|
:fq, '(_query_:"{!geofilt sfield=coordinates_new_ll pt=23,-46 d=100}" OR _query_:"{!geofilt sfield=coordinates_new_ll pt=42,56 d=50}")'
|
199
199
|
)
|
200
200
|
end
|
201
|
+
|
202
|
+
it 'creates a conjunction of in_bounding_box queries' do
|
203
|
+
search do
|
204
|
+
any_of do
|
205
|
+
with(:coordinates_new).in_bounding_box([23, -46], [25, -44])
|
206
|
+
with(:coordinates_new).in_bounding_box([42, 56], [43, 58])
|
207
|
+
end
|
208
|
+
end
|
209
|
+
expect(connection).to have_last_search_including(
|
210
|
+
:fq, '(coordinates_new_ll:[23,-46 TO 25,-44] OR coordinates_new_ll:[42,56 TO 43,58])'
|
211
|
+
)
|
212
|
+
end
|
201
213
|
end
|
data/spec/api/query/dsl_spec.rb
CHANGED
@@ -1,28 +1,36 @@
|
|
1
1
|
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
3
|
describe 'query DSL', :type => :query do
|
4
|
+
let(:blog_id) { 1 }
|
5
|
+
|
4
6
|
it 'should allow building search using block argument rather than instance_eval' do
|
5
|
-
@blog_id = 1
|
6
7
|
session.search Post do |query|
|
7
8
|
query.field_list [:blog_id, :title]
|
8
|
-
query.with(:blog_id,
|
9
|
+
query.with(:blog_id, blog_id)
|
9
10
|
end
|
10
|
-
connection.
|
11
|
-
connection.
|
11
|
+
expect(connection).to have_last_search_including(:fq, 'blog_id_i:1')
|
12
|
+
expect(connection).to have_last_search_with(fl: [:id, :blog_id_i, :title_ss])
|
12
13
|
end
|
13
14
|
|
14
15
|
it 'should allow field_list specified as arguments' do
|
15
|
-
@blog_id = 1
|
16
16
|
session.search Post do |query|
|
17
17
|
query.field_list :blog_id, :title
|
18
|
-
query.with(:blog_id,
|
18
|
+
query.with(:blog_id, blog_id)
|
19
|
+
end
|
20
|
+
expect(connection).to have_last_search_with(fl: [:id, :blog_id_i, :title_ss])
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow to skip stored fields retrieval' do
|
24
|
+
session.search Post do |query|
|
25
|
+
query.with(:blog_id, blog_id)
|
26
|
+
query.without_stored_fields
|
19
27
|
end
|
20
|
-
connection.
|
28
|
+
expect(connection).to have_last_search_with(fl: [:id])
|
21
29
|
end
|
22
30
|
|
23
31
|
it 'should accept a block in the #new_search method' do
|
24
|
-
search = session.new_search(Post) { with(:blog_id,
|
32
|
+
search = session.new_search(Post) { with(:blog_id, blog_id) }
|
25
33
|
search.execute
|
26
|
-
connection.
|
34
|
+
expect(connection).to have_last_search_including(:fq, 'blog_id_i:1')
|
27
35
|
end
|
28
36
|
end
|
@@ -5,7 +5,7 @@ shared_examples_for "query with dynamic field support" do
|
|
5
5
|
with :test, 'string'
|
6
6
|
end
|
7
7
|
end
|
8
|
-
connection.
|
8
|
+
expect(connection).to have_last_search_including(:fq, 'custom_string\:test_ss:string')
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'restricts by dynamic integer field with less than restriction' do
|
@@ -14,7 +14,7 @@ shared_examples_for "query with dynamic field support" do
|
|
14
14
|
with(:test).less_than(1)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
connection.
|
17
|
+
expect(connection).to have_last_search_including(:fq, 'custom_integer\:test_i:{* TO 1}')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'restricts by dynamic float field with between restriction' do
|
@@ -23,7 +23,7 @@ shared_examples_for "query with dynamic field support" do
|
|
23
23
|
with(:test).between(2.2..3.3)
|
24
24
|
end
|
25
25
|
end
|
26
|
-
connection.
|
26
|
+
expect(connection).to have_last_search_including(:fq, 'custom_float\:test_fm:[2\.2 TO 3\.3]')
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'restricts by dynamic time field with any of restriction' do
|
@@ -33,7 +33,7 @@ shared_examples_for "query with dynamic field support" do
|
|
33
33
|
Time.parse('2009-02-13 18:00:00 UTC')])
|
34
34
|
end
|
35
35
|
end
|
36
|
-
connection.
|
36
|
+
expect(connection).to have_last_search_including(:fq, 'custom_time\:test_d:(2009\-02\-10T14\:00\:00Z OR 2009\-02\-13T18\:00\:00Z)')
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'restricts by dynamic boolean field with equality restriction' do
|
@@ -42,7 +42,7 @@ shared_examples_for "query with dynamic field support" do
|
|
42
42
|
with :test, false
|
43
43
|
end
|
44
44
|
end
|
45
|
-
connection.
|
45
|
+
expect(connection).to have_last_search_including(:fq, 'custom_boolean\:test_b:false')
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'negates a dynamic field restriction' do
|
@@ -51,7 +51,7 @@ shared_examples_for "query with dynamic field support" do
|
|
51
51
|
without :test, 'foo'
|
52
52
|
end
|
53
53
|
end
|
54
|
-
connection.
|
54
|
+
expect(connection).to have_last_search_including(:fq, '-custom_string\:test_ss:foo')
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'scopes by a dynamic field inside a disjunction' do
|
@@ -63,7 +63,7 @@ shared_examples_for "query with dynamic field support" do
|
|
63
63
|
with :title, 'bar'
|
64
64
|
end
|
65
65
|
end
|
66
|
-
connection.
|
66
|
+
expect(connection).to have_last_search_including(
|
67
67
|
:fq, '(custom_string\:test_ss:foo OR title_ss:bar)'
|
68
68
|
)
|
69
69
|
end
|
@@ -74,7 +74,7 @@ shared_examples_for "query with dynamic field support" do
|
|
74
74
|
order_by :test, :desc
|
75
75
|
end
|
76
76
|
end
|
77
|
-
connection.
|
77
|
+
expect(connection).to have_last_search_with(:sort => 'custom_integer:test_i desc')
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'orders by a dynamic field and static field, with given precedence' do
|
@@ -84,25 +84,25 @@ shared_examples_for "query with dynamic field support" do
|
|
84
84
|
end
|
85
85
|
order_by :sort_title, :asc
|
86
86
|
end
|
87
|
-
connection.
|
87
|
+
expect(connection).to have_last_search_with(:sort => 'custom_integer:test_i desc, sort_title_s asc')
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'raises an UnrecognizedFieldError if an unknown dynamic field is searched by' do
|
91
|
-
|
91
|
+
expect do
|
92
92
|
search do
|
93
93
|
dynamic(:bogus) { with :some, 'value' }
|
94
94
|
end
|
95
|
-
end.
|
95
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'raises a NoMethodError if pagination is attempted in a dynamic query' do
|
99
|
-
|
99
|
+
expect do
|
100
100
|
search do
|
101
101
|
dynamic :custom_string do
|
102
102
|
paginate :page => 3, :per_page => 10
|
103
103
|
end
|
104
104
|
end
|
105
|
-
end.
|
105
|
+
end.to raise_error(NoMethodError)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'requests field facet on dynamic field' do
|
@@ -111,7 +111,7 @@ shared_examples_for "query with dynamic field support" do
|
|
111
111
|
facet(:test)
|
112
112
|
end
|
113
113
|
end
|
114
|
-
connection.
|
114
|
+
expect(connection).to have_last_search_including(:"facet.field", 'custom_string:test_ss')
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'requests named field facet on dynamic field' do
|
@@ -120,7 +120,7 @@ shared_examples_for "query with dynamic field support" do
|
|
120
120
|
facet(:test, :name => :bogus)
|
121
121
|
end
|
122
122
|
end
|
123
|
-
connection.
|
123
|
+
expect(connection).to have_last_search_including(:"facet.field", '{!key=bogus}custom_string:test_ss')
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'requests query facet with internal dynamic field' do
|
@@ -133,7 +133,7 @@ shared_examples_for "query with dynamic field support" do
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
136
|
-
connection.
|
136
|
+
expect(connection).to have_last_search_with(
|
137
137
|
:"facet.query" => 'custom_string\:test_ss:foo'
|
138
138
|
)
|
139
139
|
end
|
@@ -148,7 +148,7 @@ shared_examples_for "query with dynamic field support" do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
151
|
-
connection.
|
151
|
+
expect(connection).to have_last_search_including(
|
152
152
|
:"facet.query",
|
153
153
|
'custom_string\:test_ss:foo'
|
154
154
|
)
|
@@ -160,6 +160,6 @@ shared_examples_for "query with dynamic field support" do
|
|
160
160
|
with(:test, 1.23)
|
161
161
|
end
|
162
162
|
end
|
163
|
-
connection.
|
163
|
+
expect(connection).to have_last_search_including(:fq, 'custom_float\\:test_fm:1\\.23')
|
164
164
|
end
|
165
165
|
end
|
@@ -2,114 +2,114 @@ shared_examples_for "facetable query" do
|
|
2
2
|
describe 'on fields' do
|
3
3
|
it 'does not turn faceting on if no facet requested' do
|
4
4
|
search
|
5
|
-
connection.
|
5
|
+
expect(connection).not_to have_last_search_with('facet')
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'turns faceting on if facet is requested' do
|
9
9
|
search do
|
10
10
|
facet :category_ids
|
11
11
|
end
|
12
|
-
connection.
|
12
|
+
expect(connection).to have_last_search_with(:facet => 'true')
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'requests single field facet' do
|
16
16
|
search do
|
17
17
|
facet :category_ids
|
18
18
|
end
|
19
|
-
connection.
|
19
|
+
expect(connection).to have_last_search_with(:"facet.field" => %w(category_ids_im))
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'requests multiple field facets' do
|
23
23
|
search do
|
24
24
|
facet :category_ids, :blog_id
|
25
25
|
end
|
26
|
-
connection.
|
26
|
+
expect(connection).to have_last_search_with(:"facet.field" => %w(category_ids_im blog_id_i))
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'sets facet sort by count' do
|
30
30
|
search do
|
31
31
|
facet :category_ids, :sort => :count
|
32
32
|
end
|
33
|
-
connection.
|
33
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.sort" => 'true')
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'sets facet sort by index' do
|
37
37
|
search do
|
38
38
|
facet :category_ids, :sort => :index
|
39
39
|
end
|
40
|
-
connection.
|
40
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.sort" => 'false')
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'raises ArgumentError if bogus facet sort provided' do
|
44
|
-
|
44
|
+
expect do
|
45
45
|
search do
|
46
46
|
facet :category_ids, :sort => :sideways
|
47
47
|
end
|
48
|
-
end.
|
48
|
+
end.to raise_error(ArgumentError)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'sets the facet limit' do
|
52
52
|
search do
|
53
53
|
facet :category_ids, :limit => 10
|
54
54
|
end
|
55
|
-
connection.
|
55
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.limit" => 10)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'sets the facet offset' do
|
59
59
|
search do
|
60
60
|
facet :category_ids, :offset => 10
|
61
61
|
end
|
62
|
-
connection.
|
62
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.offset" => 10)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'sets the facet minimum count' do
|
66
66
|
search do
|
67
67
|
facet :category_ids, :minimum_count => 5
|
68
68
|
end
|
69
|
-
connection.
|
69
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.mincount" => 5)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'sets the facet minimum count to zero if zeros are allowed' do
|
73
73
|
search do
|
74
74
|
facet :category_ids, :zeros => true
|
75
75
|
end
|
76
|
-
connection.
|
76
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.mincount" => 0)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'sets the facet minimum count to one by default' do
|
80
80
|
search do
|
81
81
|
facet :category_ids
|
82
82
|
end
|
83
|
-
connection.
|
83
|
+
expect(connection).to have_last_search_with(:"f.category_ids_im.facet.mincount" => 1)
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'sets the facet prefix' do
|
87
87
|
search do
|
88
88
|
facet :title, :prefix => 'Test'
|
89
89
|
end
|
90
|
-
connection.
|
90
|
+
expect(connection).to have_last_search_with(:"f.title_ss.facet.prefix" => 'Test')
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'sends a query facet for :any extra' do
|
94
94
|
search do
|
95
95
|
facet :category_ids, :extra => :any
|
96
96
|
end
|
97
|
-
connection.
|
97
|
+
expect(connection).to have_last_search_with(:"facet.query" => "category_ids_im:[* TO *]")
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'sends a query facet for :none extra' do
|
101
101
|
search do
|
102
102
|
facet :category_ids, :extra => :none
|
103
103
|
end
|
104
|
-
connection.
|
104
|
+
expect(connection).to have_last_search_with(:"facet.query" => "-category_ids_im:[* TO *]")
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'raises an ArgumentError if bogus extra is passed' do
|
108
|
-
|
108
|
+
expect do
|
109
109
|
search do
|
110
110
|
facet :category_ids, :extra => :bogus
|
111
111
|
end
|
112
|
-
end.
|
112
|
+
end.to raise_error(ArgumentError)
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'tags and excludes a geofilt in a field facet' do
|
@@ -126,7 +126,7 @@ shared_examples_for "facetable query" do
|
|
126
126
|
else
|
127
127
|
filter_tag = get_filter_tag('{!geofilt sfield=coordinates_new_ll pt=32,-68 d=1}')
|
128
128
|
end
|
129
|
-
connection.
|
129
|
+
expect(connection).to have_last_search_with(
|
130
130
|
:"facet.query" => "{!ex=#{filter_tag}}_query_:\"{!geofilt sfield=coordinates_new_ll pt=32,-68 d=10}\""
|
131
131
|
)
|
132
132
|
end
|
@@ -137,7 +137,7 @@ shared_examples_for "facetable query" do
|
|
137
137
|
facet(:blog_id, :exclude => blog_filter)
|
138
138
|
end
|
139
139
|
filter_tag = get_filter_tag('blog_id_i:1')
|
140
|
-
connection.
|
140
|
+
expect(connection).to have_last_search_with(
|
141
141
|
:"facet.field" => %W({!ex=#{filter_tag}}blog_id_i)
|
142
142
|
)
|
143
143
|
end
|
@@ -151,7 +151,7 @@ shared_examples_for "facetable query" do
|
|
151
151
|
facet(:blog_id, :exclude => blog_filter)
|
152
152
|
end
|
153
153
|
filter_tag = get_filter_tag('(blog_id_i:1 OR blog_id_i:2)')
|
154
|
-
connection.
|
154
|
+
expect(connection).to have_last_search_with(
|
155
155
|
:"facet.field" => %W({!ex=#{filter_tag}}blog_id_i)
|
156
156
|
)
|
157
157
|
end
|
@@ -165,7 +165,7 @@ shared_examples_for "facetable query" do
|
|
165
165
|
filter_tags = %w(blog_id_i:1 category_ids_im:2).map do |phrase|
|
166
166
|
get_filter_tag(phrase)
|
167
167
|
end.join(',')
|
168
|
-
connection.
|
168
|
+
expect(connection).to have_last_search_with(
|
169
169
|
:"facet.field" => %W({!ex=#{filter_tags}}blog_id_i)
|
170
170
|
)
|
171
171
|
end
|
@@ -174,39 +174,39 @@ shared_examples_for "facetable query" do
|
|
174
174
|
search do
|
175
175
|
with(:blog_id, 1)
|
176
176
|
end
|
177
|
-
connection.
|
177
|
+
expect(connection).to have_last_search_including(:fq, "blog_id_i:1")
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'names a field facet' do
|
181
181
|
search do
|
182
182
|
facet(:blog_id, :name => :blog)
|
183
183
|
end
|
184
|
-
connection.
|
184
|
+
expect(connection).to have_last_search_including(:"facet.field", "{!key=blog}blog_id_i")
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'uses the custom field facet name in facet option parameters' do
|
188
188
|
search do
|
189
189
|
facet(:blog_id, :name => :blog, :sort => :count)
|
190
190
|
end
|
191
|
-
connection.
|
191
|
+
expect(connection).to have_last_search_with(:"f.blog.facet.sort" => 'true')
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'raises an ArgumentError if exclusion attempted on a restricted field facet' do
|
195
|
-
|
195
|
+
expect do
|
196
196
|
search do
|
197
197
|
blog_filter = with(:blog_id, 1)
|
198
198
|
facet(:blog_id, :only => 1, :exclude => blog_filter)
|
199
199
|
end
|
200
|
-
end.
|
200
|
+
end.to raise_error(ArgumentError)
|
201
201
|
end
|
202
202
|
|
203
203
|
it 'raises an ArgumentError if exclusion attempted on a facet with :extra' do
|
204
|
-
|
204
|
+
expect do
|
205
205
|
search do
|
206
206
|
blog_filter = with(:blog_id, 1)
|
207
207
|
facet(:blog_id, :extra => :all, :exclude => blog_filter)
|
208
208
|
end
|
209
|
-
end.
|
209
|
+
end.to raise_error(ArgumentError)
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -220,21 +220,21 @@ shared_examples_for "facetable query" do
|
|
220
220
|
search do |query|
|
221
221
|
query.facet :published_at
|
222
222
|
end
|
223
|
-
connection.
|
223
|
+
expect(connection).not_to have_last_search_with(:"facet.date")
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'sets the facet to a date facet if time range is specified' do
|
227
227
|
search do |query|
|
228
228
|
query.facet :published_at, :time_range => @time_range
|
229
229
|
end
|
230
|
-
connection.
|
230
|
+
expect(connection).to have_last_search_with(:"facet.date" => ['published_at_dt'])
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'sets the facet start and end' do
|
234
234
|
search do |query|
|
235
235
|
query.facet :published_at, :time_range => @time_range
|
236
236
|
end
|
237
|
-
connection.
|
237
|
+
expect(connection).to have_last_search_with(
|
238
238
|
:"f.published_at_dt.facet.date.start" => '2009-06-01T04:00:00Z',
|
239
239
|
:"f.published_at_dt.facet.date.end" => '2009-07-01T04:00:00Z'
|
240
240
|
)
|
@@ -244,22 +244,22 @@ shared_examples_for "facetable query" do
|
|
244
244
|
search do |query|
|
245
245
|
query.facet :published_at, :time_range => @time_range
|
246
246
|
end
|
247
|
-
connection.
|
247
|
+
expect(connection).to have_last_search_with(:"f.published_at_dt.facet.date.gap" => "+86400SECONDS")
|
248
248
|
end
|
249
249
|
|
250
250
|
it 'uses custom time interval' do
|
251
251
|
search do |query|
|
252
252
|
query.facet :published_at, :time_range => @time_range, :time_interval => 3600
|
253
253
|
end
|
254
|
-
connection.
|
254
|
+
expect(connection).to have_last_search_with(:"f.published_at_dt.facet.date.gap" => "+3600SECONDS")
|
255
255
|
end
|
256
256
|
|
257
257
|
it 'does not allow date faceting on a non-date field' do
|
258
|
-
|
258
|
+
expect do
|
259
259
|
search do |query|
|
260
260
|
query.facet :blog_id, :time_range => @time_range
|
261
261
|
end
|
262
|
-
end.
|
262
|
+
end.to raise_error(ArgumentError)
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
@@ -272,21 +272,21 @@ shared_examples_for "facetable query" do
|
|
272
272
|
search do |query|
|
273
273
|
query.facet :average_rating
|
274
274
|
end
|
275
|
-
connection.
|
275
|
+
expect(connection).not_to have_last_search_with(:"facet.range")
|
276
276
|
end
|
277
277
|
|
278
278
|
it 'sets the facet to a range facet if the range is specified' do
|
279
279
|
search do |query|
|
280
280
|
query.facet :average_rating, :range => @range
|
281
281
|
end
|
282
|
-
connection.
|
282
|
+
expect(connection).to have_last_search_with(:"facet.range" => ['average_rating_ft'])
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'sets the facet start and end' do
|
286
286
|
search do |query|
|
287
287
|
query.facet :average_rating, :range => @range
|
288
288
|
end
|
289
|
-
connection.
|
289
|
+
expect(connection).to have_last_search_with(
|
290
290
|
:"f.average_rating_ft.facet.range.start" => '2.0',
|
291
291
|
:"f.average_rating_ft.facet.range.end" => '4.0'
|
292
292
|
)
|
@@ -296,14 +296,14 @@ shared_examples_for "facetable query" do
|
|
296
296
|
search do |query|
|
297
297
|
query.facet :average_rating, :range => @range
|
298
298
|
end
|
299
|
-
connection.
|
299
|
+
expect(connection).to have_last_search_with(:"f.average_rating_ft.facet.range.gap" => "10")
|
300
300
|
end
|
301
301
|
|
302
302
|
it 'uses custom range interval' do
|
303
303
|
search do |query|
|
304
304
|
query.facet :average_rating, :range => @range, :range_interval => 1
|
305
305
|
end
|
306
|
-
connection.
|
306
|
+
expect(connection).to have_last_search_with(:"f.average_rating_ft.facet.range.gap" => "1")
|
307
307
|
end
|
308
308
|
|
309
309
|
it 'tags and excludes a scope filter in a range facet' do
|
@@ -312,7 +312,7 @@ shared_examples_for "facetable query" do
|
|
312
312
|
query.facet(:average_rating, :range => @range, :exclude => blog_filter)
|
313
313
|
end
|
314
314
|
filter_tag = get_filter_tag('blog_id_i:1')
|
315
|
-
connection.
|
315
|
+
expect(connection).to have_last_search_with(
|
316
316
|
:"facet.range" => %W({!ex=#{filter_tag}}average_rating_ft)
|
317
317
|
)
|
318
318
|
end
|
@@ -321,15 +321,15 @@ shared_examples_for "facetable query" do
|
|
321
321
|
search do |query|
|
322
322
|
query.facet :average_rating, :range => @range, :include => :edge
|
323
323
|
end
|
324
|
-
connection.
|
324
|
+
expect(connection).to have_last_search_with(:"f.average_rating_ft.facet.range.include" => "edge")
|
325
325
|
end
|
326
326
|
|
327
327
|
it 'does not allow date faceting on a non-continuous field' do
|
328
|
-
|
328
|
+
expect do
|
329
329
|
search do |query|
|
330
330
|
query.facet :title, :range => @range
|
331
331
|
end
|
332
|
-
end.
|
332
|
+
end.to raise_error(ArgumentError)
|
333
333
|
end
|
334
334
|
end
|
335
335
|
|
@@ -342,7 +342,7 @@ shared_examples_for "facetable query" do
|
|
342
342
|
end
|
343
343
|
end
|
344
344
|
end
|
345
|
-
connection.
|
345
|
+
expect(connection).to have_last_search_with(:facet => 'true')
|
346
346
|
end
|
347
347
|
|
348
348
|
it 'facets by query' do
|
@@ -353,7 +353,7 @@ shared_examples_for "facetable query" do
|
|
353
353
|
end
|
354
354
|
end
|
355
355
|
end
|
356
|
-
connection.
|
356
|
+
expect(connection).to have_last_search_with(:"facet.query" => 'average_rating_ft:[4\.0 TO 5\.0]')
|
357
357
|
end
|
358
358
|
|
359
359
|
it 'requests multiple query facets' do
|
@@ -367,7 +367,7 @@ shared_examples_for "facetable query" do
|
|
367
367
|
end
|
368
368
|
end
|
369
369
|
end
|
370
|
-
connection.
|
370
|
+
expect(connection).to have_last_search_with(
|
371
371
|
:"facet.query" => [
|
372
372
|
'average_rating_ft:[3\.0 TO 4\.0]',
|
373
373
|
'average_rating_ft:[4\.0 TO 5\.0]'
|
@@ -384,7 +384,7 @@ shared_examples_for "facetable query" do
|
|
384
384
|
end
|
385
385
|
end
|
386
386
|
end
|
387
|
-
connection.
|
387
|
+
expect(connection).to have_last_search_with(
|
388
388
|
:"facet.query" => '(category_ids_im:1 AND blog_id_i:2)'
|
389
389
|
)
|
390
390
|
end
|
@@ -400,7 +400,7 @@ shared_examples_for "facetable query" do
|
|
400
400
|
end
|
401
401
|
end
|
402
402
|
end
|
403
|
-
connection.
|
403
|
+
expect(connection).to have_last_search_with(
|
404
404
|
:"facet.query" => '(category_ids_im:1 OR blog_id_i:2)'
|
405
405
|
)
|
406
406
|
end
|
@@ -409,7 +409,7 @@ shared_examples_for "facetable query" do
|
|
409
409
|
search do
|
410
410
|
facet :category_ids, :only => [1, 3]
|
411
411
|
end
|
412
|
-
connection.
|
412
|
+
expect(connection).to have_last_search_with(
|
413
413
|
:"facet.query" => ['category_ids_im:1', 'category_ids_im:3']
|
414
414
|
)
|
415
415
|
end
|
@@ -418,7 +418,7 @@ shared_examples_for "facetable query" do
|
|
418
418
|
search do
|
419
419
|
facet :published_at, :only => [Time.utc(2009, 8, 28, 15, 33), Time.utc(2008,8, 28, 15, 33)]
|
420
420
|
end
|
421
|
-
connection.
|
421
|
+
expect(connection).to have_last_search_with(
|
422
422
|
:"facet.query" => [
|
423
423
|
'published_at_dt:2009\-08\-28T15\:33\:00Z',
|
424
424
|
'published_at_dt:2008\-08\-28T15\:33\:00Z'
|
@@ -430,7 +430,7 @@ shared_examples_for "facetable query" do
|
|
430
430
|
search do
|
431
431
|
facet(:foo) {}
|
432
432
|
end
|
433
|
-
connection.
|
433
|
+
expect(connection).not_to have_last_search_with(:"facet.query")
|
434
434
|
end
|
435
435
|
|
436
436
|
it 'ignores facet query row with no restrictions' do
|
@@ -442,7 +442,7 @@ shared_examples_for "facetable query" do
|
|
442
442
|
row(:baz) {}
|
443
443
|
end
|
444
444
|
end
|
445
|
-
connection.searches.last[:"facet.query"].
|
445
|
+
expect(connection.searches.last[:"facet.query"]).to be_a(String)
|
446
446
|
end
|
447
447
|
|
448
448
|
it 'tags and excludes a scope filter in a query facet' do
|
@@ -455,7 +455,7 @@ shared_examples_for "facetable query" do
|
|
455
455
|
end
|
456
456
|
end
|
457
457
|
filter_tag = get_filter_tag('blog_id_i:1')
|
458
|
-
connection.
|
458
|
+
expect(connection).to have_last_search_with(
|
459
459
|
:"facet.query" => "{!ex=#{filter_tag}}category_ids_im:1"
|
460
460
|
)
|
461
461
|
end
|
@@ -473,7 +473,7 @@ shared_examples_for "facetable query" do
|
|
473
473
|
end
|
474
474
|
end
|
475
475
|
filter_tag = get_filter_tag('(blog_id_i:1 OR blog_id_i:2)')
|
476
|
-
connection.
|
476
|
+
expect(connection).to have_last_search_with(
|
477
477
|
:"facet.query" => "{!ex=#{filter_tag}}category_ids_im:1"
|
478
478
|
)
|
479
479
|
end
|
@@ -491,7 +491,7 @@ shared_examples_for "facetable query" do
|
|
491
491
|
filter_tags = %w(blog_id_i:1 category_ids_im:2).map do |phrase|
|
492
492
|
get_filter_tag(phrase)
|
493
493
|
end.join(',')
|
494
|
-
connection.
|
494
|
+
expect(connection).to have_last_search_with(
|
495
495
|
:"facet.query" => "{!ex=#{filter_tags}}category_ids_im:1"
|
496
496
|
)
|
497
497
|
end
|
@@ -503,25 +503,25 @@ shared_examples_for "facetable query" do
|
|
503
503
|
row(:bar) {}
|
504
504
|
end
|
505
505
|
end
|
506
|
-
connection.
|
506
|
+
expect(connection).not_to have_last_search_with(:"facet.query")
|
507
507
|
end
|
508
508
|
|
509
509
|
it 'does not allow 0 arguments to facet method with block' do
|
510
|
-
|
510
|
+
expect do
|
511
511
|
search do
|
512
512
|
facet do
|
513
513
|
end
|
514
514
|
end
|
515
|
-
end.
|
515
|
+
end.to raise_error(ArgumentError)
|
516
516
|
end
|
517
517
|
|
518
518
|
it 'does not allow more than 1 argument to facet method with block' do
|
519
|
-
|
519
|
+
expect do
|
520
520
|
search do
|
521
521
|
facet :foo, :bar do
|
522
522
|
end
|
523
523
|
end
|
524
|
-
end.
|
524
|
+
end.to raise_error(ArgumentError)
|
525
525
|
end
|
526
526
|
end
|
527
527
|
end
|