sunspot 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/TODO +6 -5
- data/bin/sunspot-solr +4 -0
- data/installer/config/schema.yml +24 -0
- data/lib/sunspot/composite_setup.rb +14 -0
- data/lib/sunspot/dsl/adjustable.rb +47 -0
- data/lib/sunspot/dsl/fulltext.rb +23 -8
- data/lib/sunspot/dsl/function.rb +14 -0
- data/lib/sunspot/dsl/functional.rb +41 -0
- data/lib/sunspot/dsl/more_like_this_query.rb +56 -0
- data/lib/sunspot/dsl/paginatable.rb +28 -0
- data/lib/sunspot/dsl/search.rb +1 -1
- data/lib/sunspot/dsl/{query.rb → standard_query.rb} +4 -49
- data/lib/sunspot/dsl.rb +3 -2
- data/lib/sunspot/field.rb +16 -2
- data/lib/sunspot/indexer.rb +1 -1
- data/lib/sunspot/installer/schema_builder.rb +1 -1
- data/lib/sunspot/installer/solrconfig_updater.rb +13 -0
- data/lib/sunspot/installer/task_helper.rb +1 -1
- data/lib/sunspot/query/abstract_field_facet.rb +5 -0
- data/lib/sunspot/query/boost_query.rb +5 -1
- data/lib/sunspot/query/{query.rb → common_query.rb} +26 -20
- data/lib/sunspot/query/composite_fulltext.rb +31 -0
- data/lib/sunspot/query/dismax.rb +45 -6
- data/lib/sunspot/query/function_query.rb +52 -0
- data/lib/sunspot/query/more_like_this.rb +60 -0
- data/lib/sunspot/query/more_like_this_query.rb +12 -0
- data/lib/sunspot/query/standard_query.rb +20 -0
- data/lib/sunspot/query/text_field_boost.rb +2 -0
- data/lib/sunspot/query.rb +3 -2
- data/lib/sunspot/search/abstract_search.rb +302 -0
- data/lib/sunspot/search/date_facet.rb +1 -1
- data/lib/sunspot/search/facet_row.rb +1 -1
- data/lib/sunspot/search/field_facet.rb +1 -1
- data/lib/sunspot/search/highlight.rb +1 -1
- data/lib/sunspot/search/hit.rb +1 -1
- data/lib/sunspot/search/more_like_this_search.rb +31 -0
- data/lib/sunspot/search/query_facet.rb +1 -1
- data/lib/sunspot/search/standard_search.rb +21 -0
- data/lib/sunspot/search.rb +3 -288
- data/lib/sunspot/server.rb +8 -4
- data/lib/sunspot/session.rb +30 -2
- data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/sharding_session_proxy.rb +9 -0
- data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +9 -2
- data/lib/sunspot/setup.rb +32 -3
- data/lib/sunspot/type.rb +74 -0
- data/lib/sunspot/util.rb +3 -2
- data/lib/sunspot/version.rb +1 -1
- data/lib/sunspot.rb +9 -1
- data/solr/solr/conf/schema.xml +12 -0
- data/solr/solr/conf/solrconfig.xml +6 -0
- data/spec/api/indexer/attributes_spec.rb +9 -3
- data/spec/api/indexer/fulltext_spec.rb +2 -2
- data/spec/api/indexer/removal_spec.rb +1 -1
- data/spec/api/query/advanced_manipulation_examples.rb +35 -0
- data/spec/api/query/{connectives_spec.rb → connectives_examples.rb} +19 -19
- data/spec/api/query/{dynamic_fields_spec.rb → dynamic_fields_examples.rb} +33 -17
- data/spec/api/query/{faceting_spec.rb → faceting_examples.rb} +146 -43
- data/spec/api/query/{fulltext_spec.rb → fulltext_examples.rb} +81 -47
- data/spec/api/query/function_spec.rb +70 -0
- data/spec/api/query/{highlighting_spec.rb → highlighting_examples.rb} +27 -27
- data/spec/api/query/{local_spec.rb → local_examples.rb} +5 -5
- data/spec/api/query/more_like_this_spec.rb +140 -0
- data/spec/api/query/{ordering_pagination_spec.rb → ordering_pagination_examples.rb} +16 -16
- data/spec/api/query/{scope_spec.rb → scope_examples.rb} +44 -61
- data/spec/api/query/standard_spec.rb +28 -0
- data/spec/api/query/{text_field_scoping_spec.rb → text_field_scoping_examples.rb} +5 -5
- data/spec/api/search/dynamic_fields_spec.rb +6 -0
- data/spec/api/search/faceting_spec.rb +10 -10
- data/spec/api/search/hits_spec.rb +1 -1
- data/spec/api/search/results_spec.rb +10 -0
- data/spec/api/server_spec.rb +6 -0
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +2 -2
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +17 -0
- data/spec/api/spec_helper.rb +2 -0
- data/spec/helpers/query_helper.rb +25 -0
- data/spec/helpers/search_helper.rb +4 -0
- data/spec/integration/faceting_spec.rb +8 -0
- data/spec/integration/keyword_search_spec.rb +75 -3
- data/spec/integration/local_search_spec.rb +1 -1
- data/spec/integration/more_like_this_spec.rb +43 -0
- data/spec/mocks/comment.rb +1 -1
- data/spec/mocks/connection.rb +27 -12
- data/spec/mocks/post.rb +5 -4
- data/spec/spec_helper.rb +4 -21
- data/tasks/gemspec.rake +1 -1
- metadata +39 -27
- data/spec/api/query/adjust_params_spec.rb +0 -37
- data/spec/api/query/facet_local_params_spec.rb +0 -103
@@ -1,95 +1,121 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
|
3
|
+
shared_examples_for 'fulltext query' do
|
4
4
|
it 'searches by keywords' do
|
5
|
-
|
5
|
+
search do
|
6
6
|
keywords 'keyword search'
|
7
7
|
end
|
8
8
|
connection.should have_last_search_with(:q => 'keyword search')
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'ignores keywords if empty' do
|
12
|
-
|
12
|
+
search do
|
13
13
|
keywords ''
|
14
14
|
end
|
15
15
|
connection.should_not have_last_search_with(:defType => 'dismax')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'ignores keywords if nil' do
|
19
|
-
|
19
|
+
search do
|
20
20
|
keywords nil
|
21
21
|
end
|
22
22
|
connection.should_not have_last_search_with(:defType => 'dismax')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'ignores keywords with only whitespace' do
|
26
|
-
|
26
|
+
search do
|
27
27
|
keywords " \t"
|
28
28
|
end
|
29
29
|
connection.should_not have_last_search_with(:defType => 'dismax')
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'gracefully ignores keywords block if keywords ignored' do
|
33
|
-
|
33
|
+
search do
|
34
34
|
keywords(nil) { fields(:title) }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'sets default query parser to dismax when keywords used' do
|
39
|
-
|
39
|
+
search do
|
40
40
|
keywords 'keyword search'
|
41
41
|
end
|
42
42
|
connection.should have_last_search_with(:defType => 'dismax')
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'searches types in filter query if keywords used' do
|
46
|
-
|
46
|
+
search do
|
47
47
|
keywords 'keyword search'
|
48
48
|
end
|
49
49
|
connection.should have_last_search_with(:fq => ['type:Post'])
|
50
50
|
end
|
51
51
|
|
52
|
+
describe 'with multiple keyword components' do
|
53
|
+
before :each do
|
54
|
+
session.search Post do
|
55
|
+
keywords 'first search', :fields => :title
|
56
|
+
keywords 'second search'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'puts specified keywords in subquery' do
|
61
|
+
subqueries(:q).map { |subquery| subquery[:v] }.should ==
|
62
|
+
['first search', 'second search']
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'puts specified dismax parameters in subquery' do
|
66
|
+
subqueries(:q).first[:qf].should == 'title_text'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'puts default dismax parameters in subquery' do
|
70
|
+
subqueries(:q).last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'puts automatic dismax parameters in subquery' do
|
74
|
+
subqueries(:q).each { |subquery| subquery[:fl].should == '* score' }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
52
78
|
it 'searches all text fields for searched class' do
|
53
|
-
search =
|
79
|
+
search = search do
|
54
80
|
keywords 'keyword search'
|
55
81
|
end
|
56
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text
|
82
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text)
|
57
83
|
end
|
58
84
|
|
59
85
|
it 'searches both stored and unstored text fields' do
|
60
|
-
|
86
|
+
search Post, Namespaced::Comment do
|
61
87
|
keywords 'keyword search'
|
62
88
|
end
|
63
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(author_name_text backwards_title_text body_text
|
89
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(author_name_text backwards_title_text body_text body_textsv tags_textv title_text)
|
64
90
|
end
|
65
91
|
|
66
92
|
it 'searches only specified text fields when specified' do
|
67
|
-
|
93
|
+
search do
|
68
94
|
keywords 'keyword search', :fields => [:title, :body]
|
69
95
|
end
|
70
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(
|
96
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_textsv title_text)
|
71
97
|
end
|
72
98
|
|
73
99
|
it 'excludes text fields when instructed' do
|
74
|
-
|
100
|
+
search do
|
75
101
|
keywords 'keyword search' do
|
76
|
-
exclude_fields :backwards_title
|
102
|
+
exclude_fields :backwards_title, :body_mlt
|
77
103
|
end
|
78
104
|
end
|
79
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(
|
105
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_textsv tags_textv title_text)
|
80
106
|
end
|
81
107
|
|
82
108
|
it 'assigns boost to fields when specified' do
|
83
|
-
|
109
|
+
search do
|
84
110
|
keywords 'keyword search' do
|
85
111
|
fields :title => 2.0, :body => 0.75
|
86
112
|
end
|
87
113
|
end
|
88
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(
|
114
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_textsv^0.75 title_text^2.0)
|
89
115
|
end
|
90
116
|
|
91
117
|
it 'allows assignment of boosted and unboosted fields' do
|
92
|
-
|
118
|
+
search do
|
93
119
|
keywords 'keyword search' do
|
94
120
|
fields :body, :title => 2.0
|
95
121
|
end
|
@@ -97,26 +123,26 @@ describe 'fulltext query', :type => :query do
|
|
97
123
|
end
|
98
124
|
|
99
125
|
it 'searches both unstored and stored text field with same name when specified' do
|
100
|
-
|
126
|
+
search Post, Namespaced::Comment do
|
101
127
|
keywords 'keyword search', :fields => [:body]
|
102
128
|
end
|
103
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(body_text
|
129
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(body_text body_textsv)
|
104
130
|
end
|
105
131
|
|
106
132
|
it 'requests score when keywords used' do
|
107
|
-
|
133
|
+
search do
|
108
134
|
keywords 'keyword search'
|
109
135
|
end
|
110
136
|
connection.should have_last_search_with(:fl => '* score')
|
111
137
|
end
|
112
138
|
|
113
139
|
it 'does not request score when keywords not used' do
|
114
|
-
|
140
|
+
search Post
|
115
141
|
connection.should_not have_last_search_with(:fl)
|
116
142
|
end
|
117
143
|
|
118
144
|
it 'sets phrase fields' do
|
119
|
-
|
145
|
+
search do
|
120
146
|
keywords 'great pizza' do
|
121
147
|
phrase_fields :title => 2.0
|
122
148
|
end
|
@@ -125,7 +151,7 @@ describe 'fulltext query', :type => :query do
|
|
125
151
|
end
|
126
152
|
|
127
153
|
it 'sets phrase fields with boost' do
|
128
|
-
|
154
|
+
search do
|
129
155
|
keywords 'great pizza' do
|
130
156
|
phrase_fields :title => 1.5
|
131
157
|
end
|
@@ -134,7 +160,7 @@ describe 'fulltext query', :type => :query do
|
|
134
160
|
end
|
135
161
|
|
136
162
|
it 'sets phrase slop from DSL' do
|
137
|
-
|
163
|
+
search do
|
138
164
|
keywords 'great pizza' do
|
139
165
|
phrase_slop 2
|
140
166
|
end
|
@@ -143,39 +169,39 @@ describe 'fulltext query', :type => :query do
|
|
143
169
|
end
|
144
170
|
|
145
171
|
it 'sets boost for certain fields without restricting fields' do
|
146
|
-
|
172
|
+
search do
|
147
173
|
keywords 'great pizza' do
|
148
174
|
boost_fields :title => 1.5
|
149
175
|
end
|
150
176
|
end
|
151
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text
|
177
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text^1.5)
|
152
178
|
end
|
153
179
|
|
154
180
|
it 'ignores boost fields that do not apply' do
|
155
|
-
|
181
|
+
search do
|
156
182
|
keywords 'great pizza' do
|
157
183
|
boost_fields :bogus => 1.2, :title => 1.5
|
158
184
|
end
|
159
185
|
end
|
160
|
-
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text
|
186
|
+
connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text^1.5)
|
161
187
|
end
|
162
188
|
|
163
189
|
it 'sets default boost with default fields' do
|
164
|
-
|
190
|
+
search Photo do
|
165
191
|
keywords 'great pizza'
|
166
192
|
end
|
167
193
|
connection.should have_last_search_with(:qf => 'caption_text^1.5')
|
168
194
|
end
|
169
195
|
|
170
196
|
it 'sets default boost with fields specified in options' do
|
171
|
-
|
197
|
+
search Photo do
|
172
198
|
keywords 'great pizza', :fields => [:caption]
|
173
199
|
end
|
174
200
|
connection.should have_last_search_with(:qf => 'caption_text^1.5')
|
175
201
|
end
|
176
202
|
|
177
203
|
it 'sets default boost with fields specified in DSL' do
|
178
|
-
|
204
|
+
search Photo do
|
179
205
|
keywords 'great pizza' do
|
180
206
|
fields :caption
|
181
207
|
end
|
@@ -184,7 +210,7 @@ describe 'fulltext query', :type => :query do
|
|
184
210
|
end
|
185
211
|
|
186
212
|
it 'overrides default boost when specified in DSL' do
|
187
|
-
|
213
|
+
search Photo do
|
188
214
|
keywords 'great pizza' do
|
189
215
|
fields :caption => 2.0
|
190
216
|
end
|
@@ -193,18 +219,18 @@ describe 'fulltext query', :type => :query do
|
|
193
219
|
end
|
194
220
|
|
195
221
|
it 'creates boost query' do
|
196
|
-
|
222
|
+
search do
|
197
223
|
keywords 'great pizza' do
|
198
224
|
boost 2.0 do
|
199
225
|
with(:average_rating).greater_than(2.0)
|
200
226
|
end
|
201
227
|
end
|
202
228
|
end
|
203
|
-
connection.should have_last_search_with(:bq => ['
|
229
|
+
connection.should have_last_search_with(:bq => ['average_rating_ft:[2\.0 TO *]^2.0'])
|
204
230
|
end
|
205
231
|
|
206
232
|
it 'creates multiple boost queries' do
|
207
|
-
|
233
|
+
search do
|
208
234
|
keywords 'great pizza' do
|
209
235
|
boost(2.0) do
|
210
236
|
with(:average_rating).greater_than(2.0)
|
@@ -216,56 +242,56 @@ describe 'fulltext query', :type => :query do
|
|
216
242
|
end
|
217
243
|
connection.should have_last_search_with(
|
218
244
|
:bq => [
|
219
|
-
'
|
245
|
+
'average_rating_ft:[2\.0 TO *]^2.0',
|
220
246
|
'featured_b:true^1.5'
|
221
247
|
]
|
222
248
|
)
|
223
249
|
end
|
224
250
|
|
225
251
|
it 'sends minimum match parameter from options' do
|
226
|
-
|
252
|
+
search do
|
227
253
|
keywords 'great pizza', :minimum_match => 2
|
228
254
|
end
|
229
255
|
connection.should have_last_search_with(:mm => 2)
|
230
256
|
end
|
231
257
|
|
232
258
|
it 'sends minimum match parameter from DSL' do
|
233
|
-
|
259
|
+
search do
|
234
260
|
keywords('great pizza') { minimum_match(2) }
|
235
261
|
end
|
236
262
|
connection.should have_last_search_with(:mm => 2)
|
237
263
|
end
|
238
264
|
|
239
265
|
it 'sends tiebreaker parameter from options' do
|
240
|
-
|
266
|
+
search do
|
241
267
|
keywords 'great pizza', :tie => 0.1
|
242
268
|
end
|
243
269
|
connection.should have_last_search_with(:tie => 0.1)
|
244
270
|
end
|
245
271
|
|
246
272
|
it 'sends tiebreaker parameter from DSL' do
|
247
|
-
|
273
|
+
search do
|
248
274
|
keywords('great pizza') { tie(0.1) }
|
249
275
|
end
|
250
276
|
connection.should have_last_search_with(:tie => 0.1)
|
251
277
|
end
|
252
278
|
|
253
279
|
it 'sends query phrase slop from options' do
|
254
|
-
|
280
|
+
search do
|
255
281
|
keywords 'great pizza', :query_phrase_slop => 2
|
256
282
|
end
|
257
283
|
connection.should have_last_search_with(:qs => 2)
|
258
284
|
end
|
259
285
|
|
260
286
|
it 'sends query phrase slop from DSL' do
|
261
|
-
|
287
|
+
search do
|
262
288
|
keywords('great pizza') { query_phrase_slop(2) }
|
263
289
|
end
|
264
290
|
connection.should have_last_search_with(:qs => 2)
|
265
291
|
end
|
266
292
|
|
267
293
|
it 'allows specification of a text field that only exists in one type' do
|
268
|
-
|
294
|
+
search Post, Namespaced::Comment do
|
269
295
|
keywords 'keywords', :fields => :author_name
|
270
296
|
end
|
271
297
|
connection.searches.last[:qf].should == 'author_name_text'
|
@@ -273,9 +299,17 @@ describe 'fulltext query', :type => :query do
|
|
273
299
|
|
274
300
|
it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in keywords' do
|
275
301
|
lambda do
|
276
|
-
|
302
|
+
search do
|
277
303
|
keywords :text, :fields => :bogus
|
278
304
|
end
|
279
305
|
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
280
306
|
end
|
307
|
+
|
308
|
+
it 'raises Sunspot::UnrecognizedFieldError if a text field that does not exist for any type is specified' do
|
309
|
+
lambda do
|
310
|
+
search Post, Namespaced::Comment do
|
311
|
+
keywords 'fulltext', :fields => :bogus
|
312
|
+
end
|
313
|
+
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
314
|
+
end
|
281
315
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe 'function query' do
|
4
|
+
it "should send query to solr with boost function" do
|
5
|
+
session.search Post do
|
6
|
+
keywords('pizza') do
|
7
|
+
boost(function { :average_rating })
|
8
|
+
end
|
9
|
+
end
|
10
|
+
connection.should have_last_search_including(:bf, 'average_rating_ft')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle boost function with constant float" do
|
14
|
+
session.search Post do
|
15
|
+
keywords('pizza') do
|
16
|
+
boost(function { 10.5 })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
connection.should have_last_search_including(:bf, '10.5')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should handle boost function with time literal" do
|
23
|
+
session.search Post do
|
24
|
+
keywords('pizza') do
|
25
|
+
boost(function { Time.parse('2010-03-25 14:13:00 EDT') })
|
26
|
+
end
|
27
|
+
end
|
28
|
+
connection.should have_last_search_including(:bf, '2010-03-25T18:13:00Z')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should handle arbitrary functions in a function query block" do
|
32
|
+
session.search Post do
|
33
|
+
keywords('pizza') do
|
34
|
+
boost(function { product(:average_rating, 10) })
|
35
|
+
end
|
36
|
+
end
|
37
|
+
connection.should have_last_search_including(:bf, 'product(average_rating_ft,10)')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should handle nested functions in a function query block" do
|
41
|
+
session.search Post do
|
42
|
+
keywords('pizza') do
|
43
|
+
boost(function { product(:average_rating, sum(:average_rating, 20)) })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
connection.should have_last_search_including(:bf, 'product(average_rating_ft,sum(average_rating_ft,20))')
|
47
|
+
end
|
48
|
+
|
49
|
+
# TODO SOLR 1.5
|
50
|
+
it "should raise ArgumentError if string literal passed" do
|
51
|
+
lambda do
|
52
|
+
session.search Post do
|
53
|
+
keywords('pizza') do
|
54
|
+
boost(function { "hello world" })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end.should raise_error(ArgumentError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise UnrecognizedFieldError if bogus field name passed" do
|
61
|
+
lambda do
|
62
|
+
session.search Post do
|
63
|
+
keywords('pizza') do
|
64
|
+
boost(function { :bogus })
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end.should raise_error(Sunspot::UnrecognizedFieldError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -1,51 +1,51 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
|
3
|
+
shared_examples_for "query with highlighting support" do
|
4
4
|
it 'should not send highlight parameter when highlight not requested' do
|
5
|
-
|
5
|
+
search do
|
6
6
|
keywords 'test'
|
7
7
|
end
|
8
8
|
connection.should_not have_last_search_with(:hl)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should enable highlighting when highlighting requested as keywords argument' do
|
12
|
-
|
12
|
+
search do
|
13
13
|
keywords 'test', :highlight => true
|
14
14
|
end
|
15
15
|
connection.should have_last_search_with(:hl => 'on')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should not set highlight fields parameter if highlight fields are not passed' do
|
19
|
-
|
19
|
+
search do
|
20
20
|
keywords 'test', :highlight => true, :fields => [:title]
|
21
21
|
end
|
22
22
|
connection.should_not have_last_search_with(:'hl.fl')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should enable highlighting on multiple fields when highlighting requested as array of fields via keywords argument' do
|
26
|
-
|
26
|
+
search do
|
27
27
|
keywords 'test', :highlight => [:title, :body]
|
28
28
|
end
|
29
29
|
|
30
|
-
connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text
|
30
|
+
connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_textsv))
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should raise UnrecognizedFieldError if try to highlight unexisting field via keywords argument' do
|
34
34
|
lambda {
|
35
|
-
|
35
|
+
search do
|
36
36
|
keywords 'test', :highlight => [:unknown_field]
|
37
37
|
end
|
38
38
|
}.should raise_error(Sunspot::UnrecognizedFieldError)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should enable highlighting on multiple fields when highlighting requested as list of fields via block call' do
|
42
|
-
|
42
|
+
search do
|
43
43
|
keywords 'test' do
|
44
44
|
highlight :title, :body
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text
|
48
|
+
connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_textsv))
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should enable highlighting on multiple fields for multiple search types' do
|
@@ -54,12 +54,12 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
54
54
|
highlight :body
|
55
55
|
end
|
56
56
|
end
|
57
|
-
connection.searches.last[:'hl.fl'].to_set.should == Set['body_text', '
|
57
|
+
connection.searches.last[:'hl.fl'].to_set.should == Set['body_text', 'body_textsv']
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'should raise UnrecognizedFieldError if try to highlight unexisting field via block call' do
|
61
61
|
lambda {
|
62
|
-
|
62
|
+
search do
|
63
63
|
keywords 'test' do
|
64
64
|
highlight :unknown_field
|
65
65
|
end
|
@@ -68,7 +68,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should set internal formatting' do
|
71
|
-
|
71
|
+
search do
|
72
72
|
keywords 'test', :highlight => true
|
73
73
|
end
|
74
74
|
connection.should have_last_search_with(
|
@@ -78,7 +78,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'should set highlight fields from DSL' do
|
81
|
-
|
81
|
+
search do
|
82
82
|
keywords 'test' do
|
83
83
|
highlight :title
|
84
84
|
end
|
@@ -89,7 +89,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should not set formatting params specific to fields if fields specified' do
|
92
|
-
|
92
|
+
search do
|
93
93
|
keywords 'test', :highlight => :body
|
94
94
|
end
|
95
95
|
connection.should have_last_search_with(
|
@@ -99,7 +99,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should set maximum highlights per field' do
|
102
|
-
|
102
|
+
search do
|
103
103
|
keywords 'test' do
|
104
104
|
highlight :max_snippets => 3
|
105
105
|
end
|
@@ -110,7 +110,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'should set max snippets specific to highlight fields' do
|
113
|
-
|
113
|
+
search do
|
114
114
|
keywords 'test' do
|
115
115
|
highlight :title, :max_snippets => 3
|
116
116
|
end
|
@@ -122,7 +122,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should set the maximum size' do
|
125
|
-
|
125
|
+
search do
|
126
126
|
keywords 'text' do
|
127
127
|
highlight :fragment_size => 200
|
128
128
|
end
|
@@ -133,7 +133,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'should set the maximum size for specific fields' do
|
136
|
-
|
136
|
+
search do
|
137
137
|
keywords 'text' do
|
138
138
|
highlight :title, :fragment_size => 200
|
139
139
|
end
|
@@ -144,7 +144,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'enables merging of contiguous fragments' do
|
147
|
-
|
147
|
+
search do
|
148
148
|
keywords 'test' do
|
149
149
|
highlight :merge_contiguous_fragments => true
|
150
150
|
end
|
@@ -155,7 +155,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'enables merging of contiguous fragments for specific fields' do
|
158
|
-
|
158
|
+
search do
|
159
159
|
keywords 'test' do
|
160
160
|
highlight :title, :merge_contiguous_fragments => true
|
161
161
|
end
|
@@ -166,7 +166,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'enables use of phrase highlighter' do
|
169
|
-
|
169
|
+
search do
|
170
170
|
keywords 'test' do
|
171
171
|
highlight :phrase_highlighter => true
|
172
172
|
end
|
@@ -177,7 +177,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
177
177
|
end
|
178
178
|
|
179
179
|
it 'enables use of phrase highlighter for specific fields' do
|
180
|
-
|
180
|
+
search do
|
181
181
|
keywords 'test' do
|
182
182
|
highlight :title, :phrase_highlighter => true
|
183
183
|
end
|
@@ -188,7 +188,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'requires field match if requested' do
|
191
|
-
|
191
|
+
search do
|
192
192
|
keywords 'test' do
|
193
193
|
highlight :phrase_highlighter => true, :require_field_match => true
|
194
194
|
end
|
@@ -199,7 +199,7 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
199
199
|
end
|
200
200
|
|
201
201
|
it 'requires field match for specified field if requested' do
|
202
|
-
|
202
|
+
search do
|
203
203
|
keywords 'test' do
|
204
204
|
highlight :title, :phrase_highlighter => true, :require_field_match => true
|
205
205
|
end
|
@@ -210,16 +210,16 @@ describe 'highlighted fulltext queries', :type => :query do
|
|
210
210
|
end
|
211
211
|
|
212
212
|
it 'sets field specific params for different fields if different params given' do
|
213
|
-
|
213
|
+
search do
|
214
214
|
keywords 'test' do
|
215
215
|
highlight :title, :max_snippets => 2
|
216
216
|
highlight :body, :max_snippets => 1
|
217
217
|
end
|
218
218
|
end
|
219
219
|
connection.should have_last_search_with(
|
220
|
-
:"hl.fl" => %w(title_text
|
220
|
+
:"hl.fl" => %w(title_text body_textsv),
|
221
221
|
:"f.title_text.hl.snippets" => 2,
|
222
|
-
:"f.
|
222
|
+
:"f.body_textsv.hl.snippets" => 1
|
223
223
|
)
|
224
224
|
end
|
225
225
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
|
3
|
+
shared_examples_for "spatial query" do
|
4
4
|
it 'sends lat and lng, and distance when geo search is performed' do
|
5
|
-
|
5
|
+
search do
|
6
6
|
near [40.7, -73.5], :distance => 5
|
7
7
|
end
|
8
8
|
connection.should have_last_search_with(:spatial => "{!radius=5}40.7,-73.5")
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'sets lat, lng, and sort flag when sorted geo search is performed' do
|
12
|
-
|
12
|
+
search do
|
13
13
|
near [40.7, -73.5], :sort => true
|
14
14
|
end
|
15
15
|
connection.should have_last_search_with(:spatial => "{!sort=true}40.7,-73.5")
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'sets radius and sort when both are specified' do
|
19
|
-
|
19
|
+
search do
|
20
20
|
near [40.7, -73.5], :distance => 5, :sort => true
|
21
21
|
end
|
22
22
|
connection.should have_last_search_with(:spatial => "{!radius=5 sort=true}40.7,-73.5")
|
@@ -29,7 +29,7 @@ describe 'local query' do
|
|
29
29
|
[:latitude, :longitude]
|
30
30
|
].each do |lat_attr, lng_attr|
|
31
31
|
it "sets coordinates using #{lat_attr.inspect}, #{lng_attr.inspect}" do
|
32
|
-
|
32
|
+
search do
|
33
33
|
near OpenStruct.new(lat_attr => 40.7, lng_attr => -73.5), :distance => 5
|
34
34
|
end
|
35
35
|
connection.should have_last_search_with(:spatial => "{!radius=5}40.7,-73.5")
|