sunspot 2.2.7 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -8
- data/lib/sunspot/adapters.rb +4 -1
- data/lib/sunspot/configuration.rb +1 -0
- data/lib/sunspot/data_extractor.rb +36 -6
- data/lib/sunspot/dsl/field_query.rb +11 -0
- data/lib/sunspot/dsl/field_stats.rb +7 -0
- data/lib/sunspot/dsl/fields.rb +16 -0
- data/lib/sunspot/dsl/group.rb +10 -0
- data/lib/sunspot/dsl/scope.rb +23 -18
- data/lib/sunspot/field.rb +11 -0
- data/lib/sunspot/field_factory.rb +6 -2
- data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
- data/lib/sunspot/query/bbox.rb +5 -1
- data/lib/sunspot/query/date_field_json_facet.rb +25 -0
- data/lib/sunspot/query/field_json_facet.rb +19 -0
- data/lib/sunspot/query/field_stats.rb +35 -2
- data/lib/sunspot/query/group.rb +4 -5
- data/lib/sunspot/query/join.rb +2 -4
- data/lib/sunspot/query/range_json_facet.rb +28 -0
- data/lib/sunspot/query/restriction.rb +19 -4
- data/lib/sunspot/query.rb +3 -3
- data/lib/sunspot/schema.rb +10 -2
- data/lib/sunspot/search/abstract_search.rb +14 -1
- data/lib/sunspot/search/field_json_facet.rb +33 -0
- data/lib/sunspot/search/hit.rb +6 -1
- data/lib/sunspot/search/hit_enumerable.rb +4 -1
- data/lib/sunspot/search/json_facet_row.rb +40 -0
- data/lib/sunspot/search/json_facet_stats.rb +23 -0
- data/lib/sunspot/search/standard_search.rb +2 -3
- data/lib/sunspot/search/stats_json_row.rb +82 -0
- data/lib/sunspot/search/stats_row.rb +3 -1
- data/lib/sunspot/search.rb +4 -3
- data/lib/sunspot/session.rb +13 -5
- data/lib/sunspot/setup.rb +31 -0
- data/lib/sunspot/util.rb +23 -0
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/adapters_spec.rb +32 -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/data_extractor_spec.rb +39 -0
- 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 +63 -58
- 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 +43 -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 +7 -4
- data/spec/helpers/integration_helper.rb +1 -0
- data/spec/integration/atomic_updates_spec.rb +25 -11
- data/spec/integration/dynamic_fields_spec.rb +10 -10
- data/spec/integration/faceting_spec.rb +252 -39
- data/spec/integration/field_grouping_spec.rb +35 -16
- data/spec/integration/field_lists_spec.rb +57 -0
- data/spec/integration/geospatial_spec.rb +34 -8
- data/spec/integration/highlighting_spec.rb +5 -5
- data/spec/integration/indexing_spec.rb +5 -5
- data/spec/integration/join_spec.rb +45 -0
- 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 +108 -108
- data/spec/integration/spellcheck_spec.rb +52 -7
- data/spec/integration/stats_spec.rb +54 -13
- 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/adapters.rb +33 -0
- data/spec/mocks/photo.rb +14 -4
- data/spec/mocks/post.rb +9 -1
- data/spec/spec_helper.rb +11 -10
- data/sunspot.gemspec +3 -1
- metadata +49 -6
@@ -3,14 +3,14 @@ shared_examples_for "scoped query" do
|
|
3
3
|
search do
|
4
4
|
with :title, 'My Pet Post'
|
5
5
|
end
|
6
|
-
connection.
|
6
|
+
expect(connection).to have_last_search_including(:fq, 'title_ss:My\ Pet\ Post')
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'scopes by exact match with a special string' do
|
10
10
|
search do
|
11
11
|
with :title, 'OR'
|
12
12
|
end
|
13
|
-
connection.
|
13
|
+
expect(connection).to have_last_search_including(:fq, 'title_ss:"OR"')
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'scopes by exact match with time' do
|
@@ -18,7 +18,7 @@ shared_examples_for "scoped query" do
|
|
18
18
|
search do
|
19
19
|
with :published_at, time
|
20
20
|
end
|
21
|
-
connection.
|
21
|
+
expect(connection).to have_last_search_including(
|
22
22
|
:fq,
|
23
23
|
'published_at_dt:1983\-07\-08T09\:00\:00Z'
|
24
24
|
)
|
@@ -29,7 +29,7 @@ shared_examples_for "scoped query" do
|
|
29
29
|
search do
|
30
30
|
with :expire_date, date
|
31
31
|
end
|
32
|
-
connection.
|
32
|
+
expect(connection).to have_last_search_including(
|
33
33
|
:fq,
|
34
34
|
'expire_date_d:1983\-07\-08T00\:00\:00Z'
|
35
35
|
)
|
@@ -39,133 +39,133 @@ shared_examples_for "scoped query" do
|
|
39
39
|
search do
|
40
40
|
with :featured, false
|
41
41
|
end
|
42
|
-
connection.
|
42
|
+
expect(connection).to have_last_search_including(:fq, 'featured_bs:false')
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'scopes by less than match with float' do
|
46
46
|
search do
|
47
47
|
with(:average_rating).less_than 3.0
|
48
48
|
end
|
49
|
-
connection.
|
49
|
+
expect(connection).to have_last_search_including(:fq, 'average_rating_ft:{* TO 3\.0}')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should quote string with space in a less than match' do
|
53
53
|
search do
|
54
54
|
with(:title).less_than('test value')
|
55
55
|
end
|
56
|
-
connection.
|
56
|
+
expect(connection).to have_last_search_including(:fq, 'title_ss:{* TO "test\ value"}')
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'scopes by greater than match with float' do
|
60
60
|
search do
|
61
61
|
with(:average_rating).greater_than 3.0
|
62
62
|
end
|
63
|
-
connection.
|
63
|
+
expect(connection).to have_last_search_including(:fq, 'average_rating_ft:{3\.0 TO *}')
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'scopes by short-form between match with integers' do
|
67
67
|
search do
|
68
68
|
with :blog_id, 2..4
|
69
69
|
end
|
70
|
-
connection.
|
70
|
+
expect(connection).to have_last_search_including(:fq, 'blog_id_i:[2 TO 4]')
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'scopes by between match with float' do
|
74
74
|
search do
|
75
75
|
with(:average_rating).between 2.0..4.0
|
76
76
|
end
|
77
|
-
connection.
|
77
|
+
expect(connection).to have_last_search_including(:fq, 'average_rating_ft:[2\.0 TO 4\.0]')
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'scopes by any match with integer' do
|
81
81
|
search do
|
82
82
|
with(:category_ids).any_of [2, 7, 12]
|
83
83
|
end
|
84
|
-
connection.
|
84
|
+
expect(connection).to have_last_search_including(:fq, 'category_ids_im:(2 OR 7 OR 12)')
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'scopes by short-form any-of match with integers' do
|
88
88
|
search do
|
89
89
|
with :category_ids, [2, 7, 12]
|
90
90
|
end
|
91
|
-
connection.
|
91
|
+
expect(connection).to have_last_search_including(:fq, 'category_ids_im:(2 OR 7 OR 12)')
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'scopes by all match with integer' do
|
95
95
|
search do
|
96
96
|
with(:category_ids).all_of [2, 7, 12]
|
97
97
|
end
|
98
|
-
connection.
|
98
|
+
expect(connection).to have_last_search_including(:fq, 'category_ids_im:(2 AND 7 AND 12)')
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'scopes by prefix match with string' do
|
102
102
|
search do
|
103
103
|
with(:title).starting_with('tes')
|
104
104
|
end
|
105
|
-
connection.
|
105
|
+
expect(connection).to have_last_search_including(:fq, 'title_ss:tes*')
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'scopes by not equal match with string' do
|
109
109
|
search do
|
110
110
|
without :title, 'Bad Post'
|
111
111
|
end
|
112
|
-
connection.
|
112
|
+
expect(connection).to have_last_search_including(:fq, '-title_ss:Bad\ Post')
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'scopes by not less than match with float' do
|
116
116
|
search do
|
117
117
|
without(:average_rating).less_than 3.0
|
118
118
|
end
|
119
|
-
connection.
|
119
|
+
expect(connection).to have_last_search_including(:fq, '-average_rating_ft:{* TO 3\.0}')
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'scopes by not greater than match with float' do
|
123
123
|
search do
|
124
124
|
without(:average_rating).greater_than 3.0
|
125
125
|
end
|
126
|
-
connection.
|
126
|
+
expect(connection).to have_last_search_including(:fq, '-average_rating_ft:{3\.0 TO *}')
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'scopes by not between match with shorthand' do
|
130
130
|
search do
|
131
131
|
without(:blog_id, 2..4)
|
132
132
|
end
|
133
|
-
connection.
|
133
|
+
expect(connection).to have_last_search_including(:fq, '-blog_id_i:[2 TO 4]')
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'scopes by not between match with float' do
|
137
137
|
search do
|
138
138
|
without(:average_rating).between 2.0..4.0
|
139
139
|
end
|
140
|
-
connection.
|
140
|
+
expect(connection).to have_last_search_including(:fq, '-average_rating_ft:[2\.0 TO 4\.0]')
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'scopes by not any match with integer' do
|
144
144
|
search do
|
145
145
|
without(:category_ids).any_of [2, 7, 12]
|
146
146
|
end
|
147
|
-
connection.
|
147
|
+
expect(connection).to have_last_search_including(:fq, '-category_ids_im:(2 OR 7 OR 12)')
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'scopes by not all match with integer' do
|
151
151
|
search do
|
152
152
|
without(:category_ids).all_of [2, 7, 12]
|
153
153
|
end
|
154
|
-
connection.
|
154
|
+
expect(connection).to have_last_search_including(:fq, '-category_ids_im:(2 AND 7 AND 12)')
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'scopes by empty field' do
|
158
158
|
search do
|
159
159
|
with :average_rating, nil
|
160
160
|
end
|
161
|
-
connection.
|
161
|
+
expect(connection).to have_last_search_including(:fq, '-average_rating_ft:[* TO *]')
|
162
162
|
end
|
163
163
|
|
164
164
|
it 'scopes by non-empty field' do
|
165
165
|
search do
|
166
166
|
without :average_rating, nil
|
167
167
|
end
|
168
|
-
connection.
|
168
|
+
expect(connection).to have_last_search_including(:fq, 'average_rating_ft:[* TO *]')
|
169
169
|
end
|
170
170
|
|
171
171
|
it 'includes by object identity' do
|
@@ -173,7 +173,7 @@ shared_examples_for "scoped query" do
|
|
173
173
|
search do
|
174
174
|
with post
|
175
175
|
end
|
176
|
-
connection.
|
176
|
+
expect(connection).to have_last_search_including(:fq, "id:(Post\\ #{post.id})")
|
177
177
|
end
|
178
178
|
|
179
179
|
it 'includes multiple objects passed as varargs by object identity' do
|
@@ -181,7 +181,7 @@ shared_examples_for "scoped query" do
|
|
181
181
|
search do
|
182
182
|
with post1, post2
|
183
183
|
end
|
184
|
-
connection.
|
184
|
+
expect(connection).to have_last_search_including(
|
185
185
|
:fq, "id:(Post\\ #{post1.id} OR Post\\ #{post2.id})"
|
186
186
|
)
|
187
187
|
end
|
@@ -191,7 +191,7 @@ shared_examples_for "scoped query" do
|
|
191
191
|
search do
|
192
192
|
with posts
|
193
193
|
end
|
194
|
-
connection.
|
194
|
+
expect(connection).to have_last_search_including(
|
195
195
|
:fq, "id:(Post\\ #{posts.first.id} OR Post\\ #{posts.last.id})"
|
196
196
|
)
|
197
197
|
end
|
@@ -201,7 +201,7 @@ shared_examples_for "scoped query" do
|
|
201
201
|
search do
|
202
202
|
without post
|
203
203
|
end
|
204
|
-
connection.
|
204
|
+
expect(connection).to have_last_search_including(:fq, "-id:(Post\\ #{post.id})")
|
205
205
|
end
|
206
206
|
|
207
207
|
it 'excludes multiple objects passed as varargs by object identity' do
|
@@ -209,7 +209,7 @@ shared_examples_for "scoped query" do
|
|
209
209
|
search do
|
210
210
|
without post1, post2
|
211
211
|
end
|
212
|
-
connection.
|
212
|
+
expect(connection).to have_last_search_including(
|
213
213
|
:fq,
|
214
214
|
"-id:(Post\\ #{post1.id} OR Post\\ #{post2.id})"
|
215
215
|
)
|
@@ -220,7 +220,7 @@ shared_examples_for "scoped query" do
|
|
220
220
|
search do
|
221
221
|
without posts
|
222
222
|
end
|
223
|
-
connection.
|
223
|
+
expect(connection).to have_last_search_including(
|
224
224
|
:fq,
|
225
225
|
"-id:(Post\\ #{posts.first.id} OR Post\\ #{posts.last.id})"
|
226
226
|
)
|
@@ -231,45 +231,45 @@ shared_examples_for "scoped query" do
|
|
231
231
|
search Post, Namespaced::Comment do
|
232
232
|
with :published_at, time
|
233
233
|
end
|
234
|
-
connection.
|
234
|
+
expect(connection).to have_last_search_including(:fq, 'published_at_dt:1983\-07\-08T09\:00\:00Z')
|
235
235
|
end
|
236
236
|
|
237
237
|
it 'allows scoping on field not common to all types' do
|
238
238
|
search Post, Namespaced::Comment do
|
239
239
|
with :blog_id, 1
|
240
240
|
end
|
241
|
-
connection.
|
241
|
+
expect(connection).to have_last_search_including(:fq, 'blog_id_i:1')
|
242
242
|
end
|
243
243
|
|
244
244
|
it 'raises Sunspot::UnrecognizedFieldError if search scoped to field configured differently between types' do
|
245
|
-
|
245
|
+
expect do
|
246
246
|
search Post, Namespaced::Comment do
|
247
247
|
with :average_rating, 2.2 # this is a float in Post but an integer in Comment
|
248
248
|
end
|
249
|
-
end.
|
249
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
250
250
|
end
|
251
251
|
|
252
252
|
it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in block scope' do
|
253
|
-
|
253
|
+
expect do
|
254
254
|
search do
|
255
255
|
with :bogus, 'Field'
|
256
256
|
end
|
257
|
-
end.
|
257
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
258
258
|
end
|
259
259
|
|
260
260
|
it 'raises NoMethodError if bogus operator referenced' do
|
261
|
-
|
261
|
+
expect do
|
262
262
|
search do
|
263
263
|
with(:category_ids).resembling :bogus_condition
|
264
264
|
end
|
265
|
-
end.
|
265
|
+
end.to raise_error(NoMethodError)
|
266
266
|
end
|
267
267
|
|
268
268
|
it 'should raise ArgumentError if more than two arguments passed to scope method' do
|
269
|
-
|
269
|
+
expect do
|
270
270
|
search do
|
271
271
|
with(:category_ids, 4, 5)
|
272
272
|
end
|
273
|
-
end.
|
273
|
+
end.to raise_error(ArgumentError)
|
274
274
|
end
|
275
275
|
end
|
@@ -6,7 +6,7 @@ shared_examples_for "spatial query" do
|
|
6
6
|
with(:coordinates_new).in_radius(23, -46, 100)
|
7
7
|
end
|
8
8
|
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_including(:fq, "{!geofilt sfield=coordinates_new_ll pt=23,-46 d=100}")
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'filters by radius via bbox (inexact)' do
|
@@ -14,7 +14,7 @@ shared_examples_for "spatial query" do
|
|
14
14
|
with(:coordinates_new).in_radius(23, -46, 100, :bbox => true)
|
15
15
|
end
|
16
16
|
|
17
|
-
connection.
|
17
|
+
expect(connection).to have_last_search_including(:fq, "{!bbox sfield=coordinates_new_ll pt=23,-46 d=100}")
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'filters by bounding box' do
|
@@ -22,6 +22,6 @@ shared_examples_for "spatial query" do
|
|
22
22
|
with(:coordinates_new).in_bounding_box([45, -94], [46, -93])
|
23
23
|
end
|
24
24
|
|
25
|
-
connection.
|
25
|
+
expect(connection).to have_last_search_including(:fq, "coordinates_new_ll:[45,-94 TO 46,-93]")
|
26
26
|
end
|
27
27
|
end
|
@@ -6,7 +6,7 @@ shared_examples_for 'spellcheck query' do
|
|
6
6
|
search do
|
7
7
|
spellcheck
|
8
8
|
end
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_including(:spellcheck, true)
|
10
10
|
end
|
11
11
|
|
12
12
|
|
@@ -14,7 +14,7 @@ shared_examples_for 'spellcheck query' do
|
|
14
14
|
search do
|
15
15
|
spellcheck :only_more_popular => true, :count => 5
|
16
16
|
end
|
17
|
-
connection.
|
18
|
-
connection.
|
17
|
+
expect(connection).to have_last_search_including('spellcheck.onlyMorePopular', true)
|
18
|
+
expect(connection).to have_last_search_including('spellcheck.count', 5)
|
19
19
|
end
|
20
20
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
shared_examples_for 'stats query' do
|
2
2
|
it 'does not use stats unless requested' do
|
3
3
|
search
|
4
|
-
connection.
|
4
|
+
expect(connection).not_to have_last_search_with(:stats)
|
5
5
|
end
|
6
6
|
|
7
7
|
it 'uses stats when requested' do
|
8
8
|
search do
|
9
9
|
stats :average_rating
|
10
10
|
end
|
11
|
-
connection.
|
11
|
+
expect(connection).to have_last_search_with(:stats => true)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'requests single field stats' do
|
15
15
|
search do
|
16
16
|
stats :average_rating
|
17
17
|
end
|
18
|
-
connection.
|
18
|
+
expect(connection).to have_last_search_with(:"stats.field" => %w{average_rating_ft})
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'requests multiple field stats' do
|
22
22
|
search do
|
23
23
|
stats :average_rating, :published_at
|
24
24
|
end
|
25
|
-
connection.
|
25
|
+
expect(connection).to have_last_search_with(:"stats.field" => %w{average_rating_ft published_at_dt})
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'facets on a stats field' do
|
@@ -31,14 +31,14 @@ shared_examples_for 'stats query' do
|
|
31
31
|
facet :featured
|
32
32
|
end
|
33
33
|
end
|
34
|
-
connection.
|
34
|
+
expect(connection).to have_last_search_with(:"f.average_rating_ft.stats.facet" => %w{featured_bs})
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'only facets on a stats field when requested' do
|
38
38
|
search do
|
39
39
|
stats :average_rating
|
40
40
|
end
|
41
|
-
connection.
|
41
|
+
expect(connection).not_to have_last_search_with(:"f.average_rating_ft.stats.facet")
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'facets on multiple stats fields' do
|
@@ -47,7 +47,7 @@ shared_examples_for 'stats query' do
|
|
47
47
|
facet :featured
|
48
48
|
end
|
49
49
|
end
|
50
|
-
connection.
|
50
|
+
expect(connection).to have_last_search_with(
|
51
51
|
:"f.average_rating_ft.stats.facet" => %w{featured_bs},
|
52
52
|
:"f.published_at_dt.stats.facet" => %w{featured_bs}
|
53
53
|
)
|
@@ -59,7 +59,7 @@ shared_examples_for 'stats query' do
|
|
59
59
|
facet :featured, :primary_category_id
|
60
60
|
end
|
61
61
|
end
|
62
|
-
connection.
|
62
|
+
expect(connection).to have_last_search_with(
|
63
63
|
:"f.average_rating_ft.stats.facet" => %w{featured_bs primary_category_id_i}
|
64
64
|
)
|
65
65
|
end
|
@@ -5,26 +5,26 @@ shared_examples_for 'query with text field scoping' do
|
|
5
5
|
with(:body, 'test')
|
6
6
|
end
|
7
7
|
end
|
8
|
-
connection.
|
8
|
+
expect(connection).to have_last_search_including(:fq, 'body_textsv:test')
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should raise an UnrecognizedFieldError if differently configured text field is used' do
|
12
|
-
|
12
|
+
expect do
|
13
13
|
search(Post, Namespaced::Comment) do
|
14
14
|
text_fields do
|
15
15
|
with(:body, 'test')
|
16
16
|
end
|
17
17
|
end
|
18
|
-
end.
|
18
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should raise an UnrecognizedFieldError if no field exists' do
|
22
|
-
|
22
|
+
expect do
|
23
23
|
search do
|
24
24
|
text_fields do
|
25
25
|
with(:bogus, 'test')
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end.
|
28
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
29
29
|
end
|
30
30
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
describe 'typed query' do
|
2
2
|
it 'properly escapes namespaced type names' do
|
3
3
|
session.search(Namespaced::Comment)
|
4
|
-
connection.
|
4
|
+
expect(connection).to have_last_search_with(:fq => ['type:Namespaced\:\:Comment'])
|
5
5
|
end
|
6
6
|
|
7
7
|
it 'builds search for multiple types' do
|
8
8
|
session.search(Post, Namespaced::Comment)
|
9
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_with(:fq => ['type:(Post OR Namespaced\:\:Comment)'])
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'searches type of subclass when superclass is configured' do
|
13
13
|
session.search PhotoPost
|
14
|
-
connection.
|
14
|
+
expect(connection).to have_last_search_with(:fq => ['type:PhotoPost'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'raises an ArgumentError if no types given to search' do
|
18
|
-
|
18
|
+
expect { session.search }.to raise_error(ArgumentError)
|
19
19
|
end
|
20
20
|
end
|
@@ -3,7 +3,7 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
3
3
|
describe "CursorPaginatedCollection" do
|
4
4
|
subject { Sunspot::Search::CursorPaginatedCollection.new [], 10, 20, '*', 'AoIIP4AAACxQcm9maWxlIDEwMTk=' }
|
5
5
|
|
6
|
-
it { subject.
|
6
|
+
it { expect(subject).to be_an(Array) }
|
7
7
|
|
8
8
|
describe "#send" do
|
9
9
|
it 'should allow send' do
|
@@ -13,23 +13,23 @@ describe "CursorPaginatedCollection" do
|
|
13
13
|
|
14
14
|
describe "#respond_to?" do
|
15
15
|
it 'should return true for current_cursor' do
|
16
|
-
subject.respond_to?(:current_cursor).
|
16
|
+
expect(subject.respond_to?(:current_cursor)).to be(true)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context "behaves like a WillPaginate::Collection" do
|
21
|
-
it { subject.total_entries.
|
22
|
-
it { subject.total_pages.
|
23
|
-
it { subject.current_cursor.
|
24
|
-
it { subject.per_page.
|
25
|
-
it { subject.next_page_cursor.
|
21
|
+
it { expect(subject.total_entries).to eql(20) }
|
22
|
+
it { expect(subject.total_pages).to eql(2) }
|
23
|
+
it { expect(subject.current_cursor).to eql('*') }
|
24
|
+
it { expect(subject.per_page).to eql(10) }
|
25
|
+
it { expect(subject.next_page_cursor).to eql('AoIIP4AAACxQcm9maWxlIDEwMTk=') }
|
26
26
|
end
|
27
27
|
|
28
28
|
context "behaves like Kaminari" do
|
29
|
-
it { subject.total_count.
|
30
|
-
it { subject.num_pages.
|
31
|
-
it { subject.limit_value.
|
32
|
-
it { subject.first_page
|
33
|
-
it { subject.last_page
|
29
|
+
it { expect(subject.total_count).to eql(20) }
|
30
|
+
it { expect(subject.num_pages).to eql(2) }
|
31
|
+
it { expect(subject.limit_value).to eql(10) }
|
32
|
+
it { expect(subject.first_page?).to be(true) }
|
33
|
+
it { expect(subject.last_page?).to be(true) }
|
34
34
|
end
|
35
35
|
end
|
@@ -4,13 +4,13 @@ describe 'search with dynamic fields' do
|
|
4
4
|
it 'returns dynamic string facet' do
|
5
5
|
stub_facet(:"custom_string:test_ss", 'two' => 2, 'one' => 1)
|
6
6
|
result = session.search(Post) { dynamic(:custom_string) { facet(:test) }}
|
7
|
-
result.facet(:custom_string, :test).rows.map { |row| row.value }.
|
7
|
+
expect(result.facet(:custom_string, :test).rows.map { |row| row.value }).to eq(['two', 'one'])
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'returns dynamic field facet with custom label' do
|
11
11
|
stub_facet(:"bogus", 'two' => 2, 'one' => 1)
|
12
12
|
result = session.search(Post) { dynamic(:custom_string) { facet(:test, :name => :bogus) }}
|
13
|
-
result.facet(:bogus).rows.map { |row| row.value }.
|
13
|
+
expect(result.facet(:bogus).rows.map { |row| row.value }).to eq(['two', 'one'])
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'returns query facet specified in dynamic call' do
|
@@ -27,7 +27,7 @@ describe 'search with dynamic fields' do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
facet = search.facet(:test)
|
30
|
-
facet.rows.first.value.
|
31
|
-
facet.rows.first.count.
|
30
|
+
expect(facet.rows.first.value).to eq(:foo_bar)
|
31
|
+
expect(facet.rows.first.count).to eq(3)
|
32
32
|
end
|
33
33
|
end
|