nxa-sunspot 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/History.txt +153 -0
  2. data/LICENSE +18 -0
  3. data/README.rdoc +191 -0
  4. data/Rakefile +9 -0
  5. data/TODO +14 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/sunspot-configure-solr +40 -0
  8. data/bin/sunspot-solr +95 -0
  9. data/lib/light_config.rb +40 -0
  10. data/lib/sunspot.rb +488 -0
  11. data/lib/sunspot/adapters.rb +265 -0
  12. data/lib/sunspot/composite_setup.rb +188 -0
  13. data/lib/sunspot/configuration.rb +56 -0
  14. data/lib/sunspot/data_extractor.rb +50 -0
  15. data/lib/sunspot/dsl.rb +4 -0
  16. data/lib/sunspot/dsl/field_query.rb +150 -0
  17. data/lib/sunspot/dsl/fields.rb +100 -0
  18. data/lib/sunspot/dsl/fulltext.rb +228 -0
  19. data/lib/sunspot/dsl/query.rb +162 -0
  20. data/lib/sunspot/dsl/query_facet.rb +36 -0
  21. data/lib/sunspot/dsl/restriction.rb +25 -0
  22. data/lib/sunspot/dsl/scope.rb +225 -0
  23. data/lib/sunspot/dsl/search.rb +30 -0
  24. data/lib/sunspot/field.rb +181 -0
  25. data/lib/sunspot/field_factory.rb +144 -0
  26. data/lib/sunspot/indexer.rb +133 -0
  27. data/lib/sunspot/query.rb +9 -0
  28. data/lib/sunspot/query/abstract_field_facet.rb +43 -0
  29. data/lib/sunspot/query/boost_query.rb +20 -0
  30. data/lib/sunspot/query/connective.rb +189 -0
  31. data/lib/sunspot/query/date_field_facet.rb +14 -0
  32. data/lib/sunspot/query/dismax.rb +88 -0
  33. data/lib/sunspot/query/field_facet.rb +9 -0
  34. data/lib/sunspot/query/highlighting.rb +55 -0
  35. data/lib/sunspot/query/local.rb +27 -0
  36. data/lib/sunspot/query/pagination.rb +38 -0
  37. data/lib/sunspot/query/query.rb +86 -0
  38. data/lib/sunspot/query/query_facet.rb +16 -0
  39. data/lib/sunspot/query/restriction.rb +254 -0
  40. data/lib/sunspot/query/scope.rb +9 -0
  41. data/lib/sunspot/query/sort.rb +105 -0
  42. data/lib/sunspot/query/sort_composite.rb +33 -0
  43. data/lib/sunspot/query/text_field_boost.rb +15 -0
  44. data/lib/sunspot/schema.rb +147 -0
  45. data/lib/sunspot/search.rb +216 -0
  46. data/lib/sunspot/search/date_facet.rb +35 -0
  47. data/lib/sunspot/search/facet_row.rb +27 -0
  48. data/lib/sunspot/search/field_facet.rb +44 -0
  49. data/lib/sunspot/search/highlight.rb +38 -0
  50. data/lib/sunspot/search/hit.rb +117 -0
  51. data/lib/sunspot/search/query_facet.rb +62 -0
  52. data/lib/sunspot/session.rb +236 -0
  53. data/lib/sunspot/setup.rb +323 -0
  54. data/lib/sunspot/text_field_setup.rb +29 -0
  55. data/lib/sunspot/type.rb +204 -0
  56. data/lib/sunspot/util.rb +210 -0
  57. data/solr/etc/jetty.xml +212 -0
  58. data/solr/etc/webdefault.xml +379 -0
  59. data/solr/lib/jetty-6.1.3.jar +0 -0
  60. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  61. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  62. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  63. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  64. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  65. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  66. data/solr/solr/conf/elevate.xml +36 -0
  67. data/solr/solr/conf/protwords.txt +21 -0
  68. data/solr/solr/conf/schema.xml +64 -0
  69. data/solr/solr/conf/solrconfig.xml +725 -0
  70. data/solr/solr/conf/stopwords.txt +57 -0
  71. data/solr/solr/conf/synonyms.txt +31 -0
  72. data/solr/solr/lib/geoapi-nogenerics-2.1-M2.jar +0 -0
  73. data/solr/solr/lib/gt2-referencing-2.3.1.jar +0 -0
  74. data/solr/solr/lib/jsr108-0.01.jar +0 -0
  75. data/solr/solr/lib/locallucene.jar +0 -0
  76. data/solr/solr/lib/localsolr.jar +0 -0
  77. data/solr/start.jar +0 -0
  78. data/solr/webapps/solr.war +0 -0
  79. data/spec/api/adapters_spec.rb +33 -0
  80. data/spec/api/indexer/attributes_spec.rb +110 -0
  81. data/spec/api/indexer/batch_spec.rb +46 -0
  82. data/spec/api/indexer/dynamic_fields_spec.rb +33 -0
  83. data/spec/api/indexer/fixed_fields_spec.rb +57 -0
  84. data/spec/api/indexer/fulltext_spec.rb +43 -0
  85. data/spec/api/indexer/removal_spec.rb +46 -0
  86. data/spec/api/indexer/spec_helper.rb +1 -0
  87. data/spec/api/indexer_spec.rb +4 -0
  88. data/spec/api/query/adjust_params_spec.rb +37 -0
  89. data/spec/api/query/connectives_spec.rb +176 -0
  90. data/spec/api/query/dsl_spec.rb +12 -0
  91. data/spec/api/query/dynamic_fields_spec.rb +149 -0
  92. data/spec/api/query/faceting_spec.rb +296 -0
  93. data/spec/api/query/fulltext_spec.rb +281 -0
  94. data/spec/api/query/highlighting_spec.rb +225 -0
  95. data/spec/api/query/local_spec.rb +62 -0
  96. data/spec/api/query/ordering_pagination_spec.rb +95 -0
  97. data/spec/api/query/scope_spec.rb +266 -0
  98. data/spec/api/query/spec_helper.rb +1 -0
  99. data/spec/api/query/text_field_scoping_spec.rb +30 -0
  100. data/spec/api/query/types_spec.rb +20 -0
  101. data/spec/api/search/dynamic_fields_spec.rb +27 -0
  102. data/spec/api/search/faceting_spec.rb +242 -0
  103. data/spec/api/search/highlighting_spec.rb +65 -0
  104. data/spec/api/search/hits_spec.rb +67 -0
  105. data/spec/api/search/results_spec.rb +52 -0
  106. data/spec/api/search/search_spec.rb +23 -0
  107. data/spec/api/search/spec_helper.rb +1 -0
  108. data/spec/api/session_spec.rb +198 -0
  109. data/spec/api/spec_helper.rb +1 -0
  110. data/spec/api/sunspot_spec.rb +18 -0
  111. data/spec/helpers/indexer_helper.rb +29 -0
  112. data/spec/helpers/query_helper.rb +13 -0
  113. data/spec/helpers/search_helper.rb +78 -0
  114. data/spec/integration/dynamic_fields_spec.rb +55 -0
  115. data/spec/integration/faceting_spec.rb +188 -0
  116. data/spec/integration/highlighting_spec.rb +22 -0
  117. data/spec/integration/indexing_spec.rb +7 -0
  118. data/spec/integration/keyword_search_spec.rb +245 -0
  119. data/spec/integration/local_search_spec.rb +56 -0
  120. data/spec/integration/scoped_search_spec.rb +303 -0
  121. data/spec/integration/spec_helper.rb +7 -0
  122. data/spec/integration/stored_fields_spec.rb +10 -0
  123. data/spec/integration/test_pagination.rb +32 -0
  124. data/spec/mocks/adapters.rb +32 -0
  125. data/spec/mocks/blog.rb +3 -0
  126. data/spec/mocks/comment.rb +19 -0
  127. data/spec/mocks/connection.rb +106 -0
  128. data/spec/mocks/mock_adapter.rb +30 -0
  129. data/spec/mocks/mock_record.rb +48 -0
  130. data/spec/mocks/photo.rb +11 -0
  131. data/spec/mocks/post.rb +75 -0
  132. data/spec/mocks/super_class.rb +2 -0
  133. data/spec/mocks/user.rb +8 -0
  134. data/spec/spec_helper.rb +68 -0
  135. data/tasks/gemspec.rake +42 -0
  136. data/tasks/rcov.rake +28 -0
  137. data/tasks/rdoc.rake +22 -0
  138. data/tasks/schema.rake +19 -0
  139. data/tasks/spec.rake +24 -0
  140. data/tasks/todo.rake +4 -0
  141. data/templates/schema.xml.erb +36 -0
  142. metadata +319 -0
@@ -0,0 +1,281 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'fulltext query', :type => :query do
4
+ it 'searches by keywords' do
5
+ session.search Post do
6
+ keywords 'keyword search'
7
+ end
8
+ connection.should have_last_search_with(:q => 'keyword search')
9
+ end
10
+
11
+ it 'ignores keywords if empty' do
12
+ session.search Post do
13
+ keywords ''
14
+ end
15
+ connection.should_not have_last_search_with(:defType => 'dismax')
16
+ end
17
+
18
+ it 'ignores keywords if nil' do
19
+ session.search Post do
20
+ keywords nil
21
+ end
22
+ connection.should_not have_last_search_with(:defType => 'dismax')
23
+ end
24
+
25
+ it 'ignores keywords with only whitespace' do
26
+ session.search Post do
27
+ keywords " \t"
28
+ end
29
+ connection.should_not have_last_search_with(:defType => 'dismax')
30
+ end
31
+
32
+ it 'gracefully ignores keywords block if keywords ignored' do
33
+ session.search Post do
34
+ keywords(nil) { fields(:title) }
35
+ end
36
+ end
37
+
38
+ it 'sets default query parser to dismax when keywords used' do
39
+ session.search Post do
40
+ keywords 'keyword search'
41
+ end
42
+ connection.should have_last_search_with(:defType => 'dismax')
43
+ end
44
+
45
+ it 'searches types in filter query if keywords used' do
46
+ session.search Post do
47
+ keywords 'keyword search'
48
+ end
49
+ connection.should have_last_search_with(:fq => ['type:Post'])
50
+ end
51
+
52
+ it 'searches all text fields for searched class' do
53
+ search = session.search Post do
54
+ keywords 'keyword search'
55
+ end
56
+ connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_texts title_text)
57
+ end
58
+
59
+ it 'searches both stored and unstored text fields' do
60
+ session.search Post, Namespaced::Comment do
61
+ keywords 'keyword search'
62
+ end
63
+ connection.searches.last[:qf].split(' ').sort.should == %w(author_name_text backwards_title_text body_text body_texts title_text)
64
+ end
65
+
66
+ it 'searches only specified text fields when specified' do
67
+ session.search Post do
68
+ keywords 'keyword search', :fields => [:title, :body]
69
+ end
70
+ connection.searches.last[:qf].split(' ').sort.should == %w(body_texts title_text)
71
+ end
72
+
73
+ it 'excludes text fields when instructed' do
74
+ session.search Post do
75
+ keywords 'keyword search' do
76
+ exclude_fields :backwards_title
77
+ end
78
+ end
79
+ connection.searches.last[:qf].split(' ').sort.should == %w(body_texts title_text)
80
+ end
81
+
82
+ it 'assigns boost to fields when specified' do
83
+ session.search Post do
84
+ keywords 'keyword search' do
85
+ fields :title => 2.0, :body => 0.75
86
+ end
87
+ end
88
+ connection.searches.last[:qf].split(' ').sort.should == %w(body_texts^0.75 title_text^2.0)
89
+ end
90
+
91
+ it 'allows assignment of boosted and unboosted fields' do
92
+ session.search Post do
93
+ keywords 'keyword search' do
94
+ fields :body, :title => 2.0
95
+ end
96
+ end
97
+ end
98
+
99
+ it 'searches both unstored and stored text field with same name when specified' do
100
+ session.search Post, Namespaced::Comment do
101
+ keywords 'keyword search', :fields => [:body]
102
+ end
103
+ connection.searches.last[:qf].split(' ').sort.should == %w(body_text body_texts)
104
+ end
105
+
106
+ it 'requests score when keywords used' do
107
+ session.search Post do
108
+ keywords 'keyword search'
109
+ end
110
+ connection.should have_last_search_with(:fl => '* score')
111
+ end
112
+
113
+ it 'does not request score when keywords not used' do
114
+ session.search Post
115
+ connection.should_not have_last_search_with(:fl)
116
+ end
117
+
118
+ it 'sets phrase fields' do
119
+ session.search Post do
120
+ keywords 'great pizza' do
121
+ phrase_fields :title => 2.0
122
+ end
123
+ end
124
+ connection.should have_last_search_with(:pf => 'title_text^2.0')
125
+ end
126
+
127
+ it 'sets phrase fields with boost' do
128
+ session.search Post do
129
+ keywords 'great pizza' do
130
+ phrase_fields :title => 1.5
131
+ end
132
+ end
133
+ connection.should have_last_search_with(:pf => 'title_text^1.5')
134
+ end
135
+
136
+ it 'sets phrase slop from DSL' do
137
+ session.search Post do
138
+ keywords 'great pizza' do
139
+ phrase_slop 2
140
+ end
141
+ end
142
+ connection.should have_last_search_with(:ps => 2)
143
+ end
144
+
145
+ it 'sets boost for certain fields without restricting fields' do
146
+ session.search Post do
147
+ keywords 'great pizza' do
148
+ boost_fields :title => 1.5
149
+ end
150
+ end
151
+ connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_texts title_text^1.5)
152
+ end
153
+
154
+ it 'ignores boost fields that do not apply' do
155
+ session.search Post do
156
+ keywords 'great pizza' do
157
+ boost_fields :bogus => 1.2, :title => 1.5
158
+ end
159
+ end
160
+ connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_texts title_text^1.5)
161
+ end
162
+
163
+ it 'sets default boost with default fields' do
164
+ session.search Photo do
165
+ keywords 'great pizza'
166
+ end
167
+ connection.should have_last_search_with(:qf => 'caption_text^1.5')
168
+ end
169
+
170
+ it 'sets default boost with fields specified in options' do
171
+ session.search Photo do
172
+ keywords 'great pizza', :fields => [:caption]
173
+ end
174
+ connection.should have_last_search_with(:qf => 'caption_text^1.5')
175
+ end
176
+
177
+ it 'sets default boost with fields specified in DSL' do
178
+ session.search Photo do
179
+ keywords 'great pizza' do
180
+ fields :caption
181
+ end
182
+ end
183
+ connection.should have_last_search_with(:qf => 'caption_text^1.5')
184
+ end
185
+
186
+ it 'overrides default boost when specified in DSL' do
187
+ session.search Photo do
188
+ keywords 'great pizza' do
189
+ fields :caption => 2.0
190
+ end
191
+ end
192
+ connection.should have_last_search_with(:qf => 'caption_text^2.0')
193
+ end
194
+
195
+ it 'creates boost query' do
196
+ session.search Post do
197
+ keywords 'great pizza' do
198
+ boost 2.0 do
199
+ with(:average_rating).greater_than(2.0)
200
+ end
201
+ end
202
+ end
203
+ connection.should have_last_search_with(:bq => ['average_rating_f:[2\.0 TO *]^2.0'])
204
+ end
205
+
206
+ it 'creates multiple boost queries' do
207
+ session.search Post do
208
+ keywords 'great pizza' do
209
+ boost(2.0) do
210
+ with(:average_rating).greater_than(2.0)
211
+ end
212
+ boost(1.5) do
213
+ with(:featured, true)
214
+ end
215
+ end
216
+ end
217
+ connection.should have_last_search_with(
218
+ :bq => [
219
+ 'average_rating_f:[2\.0 TO *]^2.0',
220
+ 'featured_b:true^1.5'
221
+ ]
222
+ )
223
+ end
224
+
225
+ it 'sends minimum match parameter from options' do
226
+ session.search Post do
227
+ keywords 'great pizza', :minimum_match => 2
228
+ end
229
+ connection.should have_last_search_with(:mm => 2)
230
+ end
231
+
232
+ it 'sends minimum match parameter from DSL' do
233
+ session.search Post do
234
+ keywords('great pizza') { minimum_match(2) }
235
+ end
236
+ connection.should have_last_search_with(:mm => 2)
237
+ end
238
+
239
+ it 'sends tiebreaker parameter from options' do
240
+ session.search Post do
241
+ keywords 'great pizza', :tie => 0.1
242
+ end
243
+ connection.should have_last_search_with(:tie => 0.1)
244
+ end
245
+
246
+ it 'sends tiebreaker parameter from DSL' do
247
+ session.search Post do
248
+ keywords('great pizza') { tie(0.1) }
249
+ end
250
+ connection.should have_last_search_with(:tie => 0.1)
251
+ end
252
+
253
+ it 'sends query phrase slop from options' do
254
+ session.search Post do
255
+ keywords 'great pizza', :query_phrase_slop => 2
256
+ end
257
+ connection.should have_last_search_with(:qs => 2)
258
+ end
259
+
260
+ it 'sends query phrase slop from DSL' do
261
+ session.search Post do
262
+ keywords('great pizza') { query_phrase_slop(2) }
263
+ end
264
+ connection.should have_last_search_with(:qs => 2)
265
+ end
266
+
267
+ it 'allows specification of a text field that only exists in one type' do
268
+ session.search Post, Namespaced::Comment do
269
+ keywords 'keywords', :fields => :author_name
270
+ end
271
+ connection.searches.last[:qf].should == 'author_name_text'
272
+ end
273
+
274
+ it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in keywords' do
275
+ lambda do
276
+ session.search Post do
277
+ keywords :text, :fields => :bogus
278
+ end
279
+ end.should raise_error(Sunspot::UnrecognizedFieldError)
280
+ end
281
+ end
@@ -0,0 +1,225 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'highlighted fulltext queries', :type => :query do
4
+ it 'should not send highlight parameter when highlight not requested' do
5
+ session.search(Post) do
6
+ keywords 'test'
7
+ end
8
+ connection.should_not have_last_search_with(:hl)
9
+ end
10
+
11
+ it 'should enable highlighting when highlighting requested as keywords argument' do
12
+ session.search(Post) do
13
+ keywords 'test', :highlight => true
14
+ end
15
+ connection.should have_last_search_with(:hl => 'on')
16
+ end
17
+
18
+ it 'should not set highlight fields parameter if highlight fields are not passed' do
19
+ session.search(Post) do
20
+ keywords 'test', :highlight => true, :fields => [:title]
21
+ end
22
+ connection.should_not have_last_search_with(:'hl.fl')
23
+ end
24
+
25
+ it 'should enable highlighting on multiple fields when highlighting requested as array of fields via keywords argument' do
26
+ session.search(Post) do
27
+ keywords 'test', :highlight => [:title, :body]
28
+ end
29
+
30
+ connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_texts))
31
+ end
32
+
33
+ it 'should raise UnrecognizedFieldError if try to highlight unexisting field via keywords argument' do
34
+ lambda {
35
+ session.search(Post) do
36
+ keywords 'test', :highlight => [:unknown_field]
37
+ end
38
+ }.should raise_error(Sunspot::UnrecognizedFieldError)
39
+ end
40
+
41
+ it 'should enable highlighting on multiple fields when highlighting requested as list of fields via block call' do
42
+ session.search(Post) do
43
+ keywords 'test' do
44
+ highlight :title, :body
45
+ end
46
+ end
47
+
48
+ connection.should have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_texts))
49
+ end
50
+
51
+ it 'should enable highlighting on multiple fields for multiple search types' do
52
+ session.search(Post, Namespaced::Comment) do
53
+ keywords 'test' do
54
+ highlight :body
55
+ end
56
+ end
57
+ connection.searches.last[:'hl.fl'].to_set.should == Set['body_text', 'body_texts']
58
+ end
59
+
60
+ it 'should raise UnrecognizedFieldError if try to highlight unexisting field via block call' do
61
+ lambda {
62
+ session.search(Post) do
63
+ keywords 'test' do
64
+ highlight :unknown_field
65
+ end
66
+ end
67
+ }.should raise_error(Sunspot::UnrecognizedFieldError)
68
+ end
69
+
70
+ it 'should set internal formatting' do
71
+ session.search(Post) do
72
+ keywords 'test', :highlight => true
73
+ end
74
+ connection.should have_last_search_with(
75
+ :"hl.simple.pre" => '@@@hl@@@',
76
+ :"hl.simple.post" => '@@@endhl@@@'
77
+ )
78
+ end
79
+
80
+ it 'should set highlight fields from DSL' do
81
+ session.search(Post) do
82
+ keywords 'test' do
83
+ highlight :title
84
+ end
85
+ end
86
+ connection.should have_last_search_with(
87
+ :"hl.fl" => %w(title_text)
88
+ )
89
+ end
90
+
91
+ it 'should not set formatting params specific to fields if fields specified' do
92
+ session.search(Post) do
93
+ keywords 'test', :highlight => :body
94
+ end
95
+ connection.should have_last_search_with(
96
+ :"hl.simple.pre" => '@@@hl@@@',
97
+ :"hl.simple.post" => '@@@endhl@@@'
98
+ )
99
+ end
100
+
101
+ it 'should set maximum highlights per field' do
102
+ session.search(Post) do
103
+ keywords 'test' do
104
+ highlight :max_snippets => 3
105
+ end
106
+ end
107
+ connection.should have_last_search_with(
108
+ :"hl.snippets" => 3
109
+ )
110
+ end
111
+
112
+ it 'should set max snippets specific to highlight fields' do
113
+ session.search(Post) do
114
+ keywords 'test' do
115
+ highlight :title, :max_snippets => 3
116
+ end
117
+ end
118
+ connection.should have_last_search_with(
119
+ :"hl.fl" => %w(title_text),
120
+ :"f.title_text.hl.snippets" => 3
121
+ )
122
+ end
123
+
124
+ it 'should set the maximum size' do
125
+ session.search(Post) do
126
+ keywords 'text' do
127
+ highlight :fragment_size => 200
128
+ end
129
+ end
130
+ connection.should have_last_search_with(
131
+ :"hl.fragsize" => 200
132
+ )
133
+ end
134
+
135
+ it 'should set the maximum size for specific fields' do
136
+ session.search(Post) do
137
+ keywords 'text' do
138
+ highlight :title, :fragment_size => 200
139
+ end
140
+ end
141
+ connection.should have_last_search_with(
142
+ :"f.title_text.hl.fragsize" => 200
143
+ )
144
+ end
145
+
146
+ it 'enables merging of contiguous fragments' do
147
+ session.search(Post) do
148
+ keywords 'test' do
149
+ highlight :merge_contiguous_fragments => true
150
+ end
151
+ end
152
+ connection.should have_last_search_with(
153
+ :"hl.mergeContiguous" => 'true'
154
+ )
155
+ end
156
+
157
+ it 'enables merging of contiguous fragments for specific fields' do
158
+ session.search(Post) do
159
+ keywords 'test' do
160
+ highlight :title, :merge_contiguous_fragments => true
161
+ end
162
+ end
163
+ connection.should have_last_search_with(
164
+ :"f.title_text.hl.mergeContiguous" => 'true'
165
+ )
166
+ end
167
+
168
+ it 'enables use of phrase highlighter' do
169
+ session.search(Post) do
170
+ keywords 'test' do
171
+ highlight :phrase_highlighter => true
172
+ end
173
+ end
174
+ connection.should have_last_search_with(
175
+ :"hl.usePhraseHighlighter" => 'true'
176
+ )
177
+ end
178
+
179
+ it 'enables use of phrase highlighter for specific fields' do
180
+ session.search(Post) do
181
+ keywords 'test' do
182
+ highlight :title, :phrase_highlighter => true
183
+ end
184
+ end
185
+ connection.should have_last_search_with(
186
+ :"f.title_text.hl.usePhraseHighlighter" => 'true'
187
+ )
188
+ end
189
+
190
+ it 'requires field match if requested' do
191
+ session.search(Post) do
192
+ keywords 'test' do
193
+ highlight :phrase_highlighter => true, :require_field_match => true
194
+ end
195
+ end
196
+ connection.should have_last_search_with(
197
+ :"hl.requireFieldMatch" => 'true'
198
+ )
199
+ end
200
+
201
+ it 'requires field match for specified field if requested' do
202
+ session.search(Post) do
203
+ keywords 'test' do
204
+ highlight :title, :phrase_highlighter => true, :require_field_match => true
205
+ end
206
+ end
207
+ connection.should have_last_search_with(
208
+ :"f.title_text.hl.requireFieldMatch" => 'true'
209
+ )
210
+ end
211
+
212
+ it 'sets field specific params for different fields if different params given' do
213
+ session.search(Post) do
214
+ keywords 'test' do
215
+ highlight :title, :max_snippets => 2
216
+ highlight :body, :max_snippets => 1
217
+ end
218
+ end
219
+ connection.should have_last_search_with(
220
+ :"hl.fl" => %w(title_text body_texts),
221
+ :"f.title_text.hl.snippets" => 2,
222
+ :"f.body_texts.hl.snippets" => 1
223
+ )
224
+ end
225
+ end