sunspot 2.0.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -2
- data/History.txt +10 -0
- data/lib/sunspot.rb +55 -17
- data/lib/sunspot/adapters.rb +68 -18
- data/lib/sunspot/batcher.rb +1 -1
- data/lib/sunspot/configuration.rb +4 -2
- data/lib/sunspot/data_extractor.rb +36 -6
- data/lib/sunspot/dsl.rb +4 -3
- data/lib/sunspot/dsl/adjustable.rb +2 -2
- data/lib/sunspot/dsl/field_query.rb +69 -16
- data/lib/sunspot/dsl/field_stats.rb +25 -0
- data/lib/sunspot/dsl/fields.rb +28 -8
- data/lib/sunspot/dsl/fulltext.rb +9 -1
- data/lib/sunspot/dsl/group.rb +118 -0
- data/lib/sunspot/dsl/paginatable.rb +4 -1
- data/lib/sunspot/dsl/scope.rb +19 -10
- data/lib/sunspot/dsl/search.rb +1 -1
- data/lib/sunspot/dsl/spellcheckable.rb +14 -0
- data/lib/sunspot/dsl/standard_query.rb +63 -35
- data/lib/sunspot/field.rb +76 -4
- data/lib/sunspot/field_factory.rb +60 -11
- data/lib/sunspot/indexer.rb +70 -18
- data/lib/sunspot/query.rb +5 -4
- data/lib/sunspot/query/abstract_field_facet.rb +0 -2
- data/lib/sunspot/query/abstract_fulltext.rb +76 -0
- data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
- data/lib/sunspot/query/bbox.rb +5 -1
- data/lib/sunspot/query/common_query.rb +31 -6
- data/lib/sunspot/query/composite_fulltext.rb +58 -8
- data/lib/sunspot/query/date_field_json_facet.rb +25 -0
- data/lib/sunspot/query/dismax.rb +25 -71
- data/lib/sunspot/query/field_json_facet.rb +19 -0
- data/lib/sunspot/query/field_list.rb +15 -0
- data/lib/sunspot/query/field_stats.rb +61 -0
- data/lib/sunspot/query/function_query.rb +1 -2
- data/lib/sunspot/query/geo.rb +1 -1
- data/lib/sunspot/query/geofilt.rb +8 -3
- data/lib/sunspot/query/group.rb +46 -0
- data/lib/sunspot/query/group_query.rb +17 -0
- data/lib/sunspot/query/join.rb +88 -0
- data/lib/sunspot/query/more_like_this.rb +1 -1
- data/lib/sunspot/query/pagination.rb +12 -4
- data/lib/sunspot/query/range_json_facet.rb +28 -0
- data/lib/sunspot/query/restriction.rb +99 -13
- data/lib/sunspot/query/sort.rb +41 -0
- data/lib/sunspot/query/sort_composite.rb +7 -0
- data/lib/sunspot/query/spellcheck.rb +19 -0
- data/lib/sunspot/query/standard_query.rb +24 -2
- data/lib/sunspot/query/text_field_boost.rb +1 -3
- data/lib/sunspot/schema.rb +12 -3
- data/lib/sunspot/search.rb +4 -2
- data/lib/sunspot/search/abstract_search.rb +93 -43
- data/lib/sunspot/search/cursor_paginated_collection.rb +32 -0
- data/lib/sunspot/search/field_facet.rb +4 -4
- data/lib/sunspot/search/field_json_facet.rb +33 -0
- data/lib/sunspot/search/field_stats.rb +21 -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/paginated_collection.rb +1 -0
- data/lib/sunspot/search/query_group.rb +74 -0
- data/lib/sunspot/search/standard_search.rb +70 -3
- data/lib/sunspot/search/stats_facet.rb +25 -0
- data/lib/sunspot/search/stats_json_row.rb +82 -0
- data/lib/sunspot/search/stats_row.rb +68 -0
- data/lib/sunspot/session.rb +62 -37
- data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +6 -4
- data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +16 -8
- data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +2 -2
- data/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/sharding_session_proxy.rb +4 -2
- data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +1 -1
- data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +6 -4
- data/lib/sunspot/setup.rb +42 -0
- data/lib/sunspot/type.rb +20 -0
- data/lib/sunspot/util.rb +78 -14
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/adapters_spec.rb +40 -15
- data/spec/api/batcher_spec.rb +15 -15
- data/spec/api/binding_spec.rb +3 -3
- data/spec/api/class_set_spec.rb +6 -6
- 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 +35 -30
- 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 +16 -11
- data/spec/api/indexer/fulltext_spec.rb +8 -8
- data/spec/api/indexer/removal_spec.rb +24 -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 +24 -6
- data/spec/api/query/dynamic_fields_examples.rb +18 -18
- data/spec/api/query/faceting_examples.rb +80 -61
- data/spec/api/query/fulltext_examples.rb +194 -40
- data/spec/api/query/function_spec.rb +116 -13
- data/spec/api/query/geo_examples.rb +8 -12
- data/spec/api/query/group_spec.rb +27 -5
- data/spec/api/query/highlighting_examples.rb +26 -26
- data/spec/api/query/join_spec.rb +19 -0
- data/spec/api/query/more_like_this_spec.rb +40 -27
- data/spec/api/query/ordering_pagination_examples.rb +37 -23
- 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 +20 -0
- data/spec/api/query/standard_spec.rb +3 -1
- data/spec/api/query/stats_examples.rb +66 -0
- 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 +35 -0
- 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 +19 -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 +94 -0
- data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +23 -16
- data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +16 -4
- data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
- data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +11 -11
- data/spec/api/session_proxy/sharding_session_proxy_spec.rb +15 -14
- data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +3 -3
- data/spec/api/session_proxy/spec_helper.rb +1 -1
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +40 -26
- data/spec/api/session_spec.rb +78 -38
- data/spec/api/sunspot_spec.rb +7 -4
- data/spec/helpers/integration_helper.rb +11 -1
- data/spec/helpers/query_helper.rb +1 -1
- data/spec/helpers/search_helper.rb +30 -0
- data/spec/integration/atomic_updates_spec.rb +58 -0
- data/spec/integration/dynamic_fields_spec.rb +31 -20
- data/spec/integration/faceting_spec.rb +252 -39
- data/spec/integration/field_grouping_spec.rb +47 -15
- data/spec/integration/field_lists_spec.rb +57 -0
- data/spec/integration/geospatial_spec.rb +34 -8
- data/spec/integration/highlighting_spec.rb +8 -8
- data/spec/integration/indexing_spec.rb +7 -6
- data/spec/integration/join_spec.rb +45 -0
- data/spec/integration/keyword_search_spec.rb +68 -38
- 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 +193 -74
- data/spec/integration/spellcheck_spec.rb +119 -0
- data/spec/integration/stats_spec.rb +88 -0
- 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 +36 -0
- data/spec/mocks/connection.rb +5 -3
- data/spec/mocks/photo.rb +32 -1
- data/spec/mocks/post.rb +18 -3
- data/spec/spec_helper.rb +13 -8
- data/sunspot.gemspec +6 -4
- data/tasks/rdoc.rake +22 -14
- metadata +101 -44
- data/lib/sunspot/dsl/field_group.rb +0 -57
- data/lib/sunspot/query/field_group.rb +0 -37
@@ -7,7 +7,7 @@ describe 'function query' do
|
|
7
7
|
boost(function { :average_rating })
|
8
8
|
end
|
9
9
|
end
|
10
|
-
connection.
|
10
|
+
expect(connection).to have_last_search_including(:bf, 'average_rating_ft')
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should send query to solr with boost function and boost amount" do
|
@@ -16,7 +16,7 @@ describe 'function query' do
|
|
16
16
|
boost(function { :average_rating }^5)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
connection.
|
19
|
+
expect(connection).to have_last_search_including(:bf, 'average_rating_ft^5')
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should handle boost function with constant float" do
|
@@ -25,7 +25,7 @@ describe 'function query' do
|
|
25
25
|
boost(function { 10.5 })
|
26
26
|
end
|
27
27
|
end
|
28
|
-
connection.
|
28
|
+
expect(connection).to have_last_search_including(:bf, '10.5')
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should handle boost function with constant float and boost amount" do
|
@@ -34,7 +34,7 @@ describe 'function query' do
|
|
34
34
|
boost(function { 10.5 }^5)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
connection.
|
37
|
+
expect(connection).to have_last_search_including(:bf, '10.5^5')
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should handle boost function with time literal" do
|
@@ -43,7 +43,7 @@ describe 'function query' do
|
|
43
43
|
boost(function { Time.parse('2010-03-25 14:13:00 EDT') })
|
44
44
|
end
|
45
45
|
end
|
46
|
-
connection.
|
46
|
+
expect(connection).to have_last_search_including(:bf, '2010-03-25T18:13:00Z')
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should handle arbitrary functions in a function query block" do
|
@@ -52,7 +52,7 @@ describe 'function query' do
|
|
52
52
|
boost(function { product(:average_rating, 10) })
|
53
53
|
end
|
54
54
|
end
|
55
|
-
connection.
|
55
|
+
expect(connection).to have_last_search_including(:bf, 'product(average_rating_ft,10)')
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should handle the sub function in a function query block" do
|
@@ -61,7 +61,7 @@ describe 'function query' do
|
|
61
61
|
boost(function { sub(:average_rating, 10) })
|
62
62
|
end
|
63
63
|
end
|
64
|
-
connection.
|
64
|
+
expect(connection).to have_last_search_including(:bf, 'sub(average_rating_ft,10)')
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should handle boost amounts on function query block" do
|
@@ -70,7 +70,7 @@ describe 'function query' do
|
|
70
70
|
boost(function { sub(:average_rating, 10)^5 })
|
71
71
|
end
|
72
72
|
end
|
73
|
-
connection.
|
73
|
+
expect(connection).to have_last_search_including(:bf, 'sub(average_rating_ft,10)^5')
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should handle nested functions in a function query block" do
|
@@ -79,28 +79,131 @@ describe 'function query' do
|
|
79
79
|
boost(function { product(:average_rating, sum(:average_rating, 20)) })
|
80
80
|
end
|
81
81
|
end
|
82
|
-
connection.
|
82
|
+
expect(connection).to have_last_search_including(:bf, 'product(average_rating_ft,sum(average_rating_ft,20))')
|
83
83
|
end
|
84
84
|
|
85
85
|
# TODO SOLR 1.5
|
86
86
|
it "should raise ArgumentError if string literal passed" do
|
87
|
-
|
87
|
+
expect do
|
88
88
|
session.search Post do
|
89
89
|
keywords('pizza') do
|
90
90
|
boost(function { "hello world" })
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end.
|
93
|
+
end.to raise_error(ArgumentError)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should raise UnrecognizedFieldError if bogus field name passed" do
|
97
|
-
|
97
|
+
expect do
|
98
98
|
session.search Post do
|
99
99
|
keywords('pizza') do
|
100
100
|
boost(function { :bogus })
|
101
101
|
end
|
102
102
|
end
|
103
|
-
end.
|
103
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
104
104
|
end
|
105
|
+
|
106
|
+
it "should send query to solr with multiplicative boost function" do
|
107
|
+
session.search Post do
|
108
|
+
keywords('pizza') do
|
109
|
+
multiplicative_boost(function { :average_rating })
|
110
|
+
end
|
111
|
+
end
|
112
|
+
expect(connection).to have_last_search_including(:boost, 'average_rating_ft')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should send query to solr with multiplicative boost function and boost amount" do
|
116
|
+
session.search Post do
|
117
|
+
keywords('pizza') do
|
118
|
+
multiplicative_boost(function { :average_rating }^5)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
expect(connection).to have_last_search_including(:boost, 'average_rating_ft^5')
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should handle multiplicative boost function with constant float" do
|
125
|
+
session.search Post do
|
126
|
+
keywords('pizza') do
|
127
|
+
multiplicative_boost(function { 10.5 })
|
128
|
+
end
|
129
|
+
end
|
130
|
+
expect(connection).to have_last_search_including(:boost, '10.5')
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should handle multiplicative boost function with constant float and boost amount" do
|
134
|
+
session.search Post do
|
135
|
+
keywords('pizza') do
|
136
|
+
multiplicative_boost(function { 10.5 }^5)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
expect(connection).to have_last_search_including(:boost, '10.5^5')
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should handle multiplicative boost function with time literal" do
|
143
|
+
session.search Post do
|
144
|
+
keywords('pizza') do
|
145
|
+
multiplicative_boost(function { Time.parse('2010-03-25 14:13:00 EDT') })
|
146
|
+
end
|
147
|
+
end
|
148
|
+
expect(connection).to have_last_search_including(:boost, '2010-03-25T18:13:00Z')
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should handle arbitrary functions in a function query block" do
|
152
|
+
session.search Post do
|
153
|
+
keywords('pizza') do
|
154
|
+
multiplicative_boost(function { product(:average_rating, 10) })
|
155
|
+
end
|
156
|
+
end
|
157
|
+
expect(connection).to have_last_search_including(:boost, 'product(average_rating_ft,10)')
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should handle the sub function in a multiplicative boost function query block" do
|
161
|
+
session.search Post do
|
162
|
+
keywords('pizza') do
|
163
|
+
multiplicative_boost(function { sub(:average_rating, 10) })
|
164
|
+
end
|
165
|
+
end
|
166
|
+
expect(connection).to have_last_search_including(:boost, 'sub(average_rating_ft,10)')
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should handle boost amounts on multiplicative boost function query block" do
|
170
|
+
session.search Post do
|
171
|
+
keywords('pizza') do
|
172
|
+
multiplicative_boost(function { sub(:average_rating, 10)^5 })
|
173
|
+
end
|
174
|
+
end
|
175
|
+
expect(connection).to have_last_search_including(:boost, 'sub(average_rating_ft,10)^5')
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should handle nested functions in a multiplicative boost function query block" do
|
179
|
+
session.search Post do
|
180
|
+
keywords('pizza') do
|
181
|
+
multiplicative_boost(function { product(:average_rating, sum(:average_rating, 20)) })
|
182
|
+
end
|
183
|
+
end
|
184
|
+
expect(connection).to have_last_search_including(:boost, 'product(average_rating_ft,sum(average_rating_ft,20))')
|
185
|
+
end
|
186
|
+
|
187
|
+
# TODO SOLR 1.5
|
188
|
+
it "should raise ArgumentError if string literal passed to multiplicative boost" do
|
189
|
+
expect do
|
190
|
+
session.search Post do
|
191
|
+
keywords('pizza') do
|
192
|
+
multiplicative_boost(function { "hello world" })
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end.to raise_error(ArgumentError)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should raise UnrecognizedFieldError if bogus field name passed to multiplicative boost" do
|
199
|
+
expect do
|
200
|
+
session.search Post do
|
201
|
+
keywords('pizza') do
|
202
|
+
multiplicative_boost(function { :bogus })
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end.to raise_error(Sunspot::UnrecognizedFieldError)
|
206
|
+
end
|
207
|
+
|
105
208
|
end
|
106
209
|
|
@@ -5,35 +5,35 @@ shared_examples_for 'geohash query' do
|
|
5
5
|
search do
|
6
6
|
with(:coordinates).near(40.7, -73.5)
|
7
7
|
end
|
8
|
-
connection.
|
8
|
+
expect(connection).to have_last_search_including(:q, build_geo_query)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'searches for nearby points with non-Float arguments' do
|
12
12
|
search do
|
13
13
|
with(:coordinates).near(BigDecimal.new('40.7'), BigDecimal.new('-73.5'))
|
14
14
|
end
|
15
|
-
connection.
|
15
|
+
expect(connection).to have_last_search_including(:q, build_geo_query)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'searches for nearby points with given precision' do
|
19
19
|
search do
|
20
20
|
with(:coordinates).near(40.7, -73.5, :precision => 10)
|
21
21
|
end
|
22
|
-
connection.
|
22
|
+
expect(connection).to have_last_search_including(:q, build_geo_query(:precision => 10))
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'searches for nearby points with given precision factor' do
|
26
26
|
search do
|
27
27
|
with(:coordinates).near(40.7, -73.5, :precision_factor => 1.5)
|
28
28
|
end
|
29
|
-
connection.
|
29
|
+
expect(connection).to have_last_search_including(:q, build_geo_query(:precision_factor => 1.5))
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'searches for nearby points with given boost' do
|
33
33
|
search do
|
34
34
|
with(:coordinates).near(40.7, -73.5, :boost => 2.0)
|
35
35
|
end
|
36
|
-
connection.
|
36
|
+
expect(connection).to have_last_search_including(:q, build_geo_query(:boost => 2.0))
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'performs both dismax search and location search' do
|
@@ -41,12 +41,8 @@ shared_examples_for 'geohash query' do
|
|
41
41
|
fulltext 'pizza', :fields => :title
|
42
42
|
with(:coordinates).near(40.7, -73.5)
|
43
43
|
end
|
44
|
-
expected =
|
45
|
-
|
46
|
-
connection.should have_last_search_including(
|
47
|
-
:q,
|
48
|
-
%Q(_query_:"{!dismax qf='title_text'}pizza" (#{build_geo_query}))
|
49
|
-
)
|
44
|
+
expected = %Q((_query_:"{!edismax qf='title_text'}pizza" AND (#{build_geo_query})))
|
45
|
+
expect(connection).to have_last_search_including(:q, expected)
|
50
46
|
end
|
51
47
|
|
52
48
|
private
|
@@ -57,7 +53,7 @@ shared_examples_for 'geohash query' do
|
|
57
53
|
boost = options[:boost] || 1.0
|
58
54
|
hash = 'dr5xx3nytvgs'
|
59
55
|
(precision..12).map do |i|
|
60
|
-
phrase =
|
56
|
+
phrase =
|
61
57
|
if i == 12 then hash
|
62
58
|
else "#{hash[0, i]}*"
|
63
59
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "grouping" do
|
4
4
|
it "sends grouping parameters to solr" do
|
5
5
|
session.search Post do
|
6
6
|
group :title
|
7
7
|
end
|
8
8
|
|
9
|
-
connection.
|
10
|
-
connection.
|
9
|
+
expect(connection).to have_last_search_including(:group, "true")
|
10
|
+
expect(connection).to have_last_search_including(:"group.field", "title_ss")
|
11
11
|
end
|
12
12
|
|
13
13
|
it "sends grouping limit parameters to solr" do
|
@@ -17,7 +17,7 @@ describe "field grouping" do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
connection.
|
20
|
+
expect(connection).to have_last_search_including(:"group.limit", 2)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "sends grouping sort parameters to solr" do
|
@@ -27,6 +27,28 @@ describe "field grouping" do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
connection.
|
30
|
+
expect(connection).to have_last_search_including(:"group.sort", "average_rating_ft asc")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sends grouping field parameters to solr" do
|
34
|
+
session.search Post do
|
35
|
+
group do
|
36
|
+
field :title
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
expect(connection).to have_last_search_including(:"group.field", "title_ss")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "sends grouping query parameters to solr" do
|
44
|
+
session.search Post do
|
45
|
+
group do
|
46
|
+
query 'category 1' do
|
47
|
+
with(:category_ids, 1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(connection).to have_last_search_including(:"group.query", "category_ids_im:1")
|
31
53
|
end
|
32
54
|
end
|
@@ -3,21 +3,21 @@ shared_examples_for "query with highlighting support" do
|
|
3
3
|
search do
|
4
4
|
keywords 'test'
|
5
5
|
end
|
6
|
-
connection.
|
6
|
+
expect(connection).not_to have_last_search_with(:hl)
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should enable highlighting when highlighting requested as keywords argument' do
|
10
10
|
search do
|
11
11
|
keywords 'test', :highlight => true
|
12
12
|
end
|
13
|
-
connection.
|
13
|
+
expect(connection).to have_last_search_with(:hl => 'on')
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should not set highlight fields parameter if highlight fields are not passed' do
|
17
17
|
search do
|
18
18
|
keywords 'test', :highlight => true, :fields => [:title]
|
19
19
|
end
|
20
|
-
connection.
|
20
|
+
expect(connection).not_to have_last_search_with(:'hl.fl')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should enable highlighting on multiple fields when highlighting requested as array of fields via keywords argument' do
|
@@ -25,15 +25,15 @@ shared_examples_for "query with highlighting support" do
|
|
25
25
|
keywords 'test', :highlight => [:title, :body]
|
26
26
|
end
|
27
27
|
|
28
|
-
connection.
|
28
|
+
expect(connection).to have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_textsv))
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should raise UnrecognizedFieldError if try to highlight unexisting field via keywords argument' do
|
32
|
-
|
32
|
+
expect {
|
33
33
|
search do
|
34
34
|
keywords 'test', :highlight => [:unknown_field]
|
35
35
|
end
|
36
|
-
}.
|
36
|
+
}.to raise_error(Sunspot::UnrecognizedFieldError)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should enable highlighting on multiple fields when highlighting requested as list of fields via block call' do
|
@@ -43,7 +43,7 @@ shared_examples_for "query with highlighting support" do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
connection.
|
46
|
+
expect(connection).to have_last_search_with(:hl => 'on', :'hl.fl' => %w(title_text body_textsv))
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should enable highlighting on multiple fields for multiple search types' do
|
@@ -52,24 +52,24 @@ shared_examples_for "query with highlighting support" do
|
|
52
52
|
highlight :body
|
53
53
|
end
|
54
54
|
end
|
55
|
-
connection.searches.last[:'hl.fl'].to_set.
|
55
|
+
expect(connection.searches.last[:'hl.fl'].to_set).to eq(Set['body_text', 'body_textsv'])
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should raise UnrecognizedFieldError if try to highlight unexisting field via block call' do
|
59
|
-
|
59
|
+
expect {
|
60
60
|
search do
|
61
61
|
keywords 'test' do
|
62
62
|
highlight :unknown_field
|
63
63
|
end
|
64
64
|
end
|
65
|
-
}.
|
65
|
+
}.to raise_error(Sunspot::UnrecognizedFieldError)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'should set internal formatting' do
|
69
69
|
search do
|
70
70
|
keywords 'test', :highlight => true
|
71
71
|
end
|
72
|
-
connection.
|
72
|
+
expect(connection).to have_last_search_with(
|
73
73
|
:"hl.simple.pre" => '@@@hl@@@',
|
74
74
|
:"hl.simple.post" => '@@@endhl@@@'
|
75
75
|
)
|
@@ -81,7 +81,7 @@ shared_examples_for "query with highlighting support" do
|
|
81
81
|
highlight :title
|
82
82
|
end
|
83
83
|
end
|
84
|
-
connection.
|
84
|
+
expect(connection).to have_last_search_with(
|
85
85
|
:"hl.fl" => %w(title_text)
|
86
86
|
)
|
87
87
|
end
|
@@ -90,7 +90,7 @@ shared_examples_for "query with highlighting support" do
|
|
90
90
|
search do
|
91
91
|
keywords 'test', :highlight => :body
|
92
92
|
end
|
93
|
-
connection.
|
93
|
+
expect(connection).to have_last_search_with(
|
94
94
|
:"hl.simple.pre" => '@@@hl@@@',
|
95
95
|
:"hl.simple.post" => '@@@endhl@@@'
|
96
96
|
)
|
@@ -102,7 +102,7 @@ shared_examples_for "query with highlighting support" do
|
|
102
102
|
highlight :max_snippets => 3
|
103
103
|
end
|
104
104
|
end
|
105
|
-
connection.
|
105
|
+
expect(connection).to have_last_search_with(
|
106
106
|
:"hl.snippets" => 3
|
107
107
|
)
|
108
108
|
end
|
@@ -113,7 +113,7 @@ shared_examples_for "query with highlighting support" do
|
|
113
113
|
highlight :title, :max_snippets => 3
|
114
114
|
end
|
115
115
|
end
|
116
|
-
connection.
|
116
|
+
expect(connection).to have_last_search_with(
|
117
117
|
:"hl.fl" => %w(title_text),
|
118
118
|
:"f.title_text.hl.snippets" => 3
|
119
119
|
)
|
@@ -125,7 +125,7 @@ shared_examples_for "query with highlighting support" do
|
|
125
125
|
highlight :fragment_size => 200
|
126
126
|
end
|
127
127
|
end
|
128
|
-
connection.
|
128
|
+
expect(connection).to have_last_search_with(
|
129
129
|
:"hl.fragsize" => 200
|
130
130
|
)
|
131
131
|
end
|
@@ -136,7 +136,7 @@ shared_examples_for "query with highlighting support" do
|
|
136
136
|
highlight :title, :fragment_size => 200
|
137
137
|
end
|
138
138
|
end
|
139
|
-
connection.
|
139
|
+
expect(connection).to have_last_search_with(
|
140
140
|
:"f.title_text.hl.fragsize" => 200
|
141
141
|
)
|
142
142
|
end
|
@@ -147,7 +147,7 @@ shared_examples_for "query with highlighting support" do
|
|
147
147
|
highlight :merge_contiguous_fragments => true
|
148
148
|
end
|
149
149
|
end
|
150
|
-
connection.
|
150
|
+
expect(connection).to have_last_search_with(
|
151
151
|
:"hl.mergeContiguous" => 'true'
|
152
152
|
)
|
153
153
|
end
|
@@ -158,7 +158,7 @@ shared_examples_for "query with highlighting support" do
|
|
158
158
|
highlight :title, :merge_contiguous_fragments => true
|
159
159
|
end
|
160
160
|
end
|
161
|
-
connection.
|
161
|
+
expect(connection).to have_last_search_with(
|
162
162
|
:"f.title_text.hl.mergeContiguous" => 'true'
|
163
163
|
)
|
164
164
|
end
|
@@ -169,7 +169,7 @@ shared_examples_for "query with highlighting support" do
|
|
169
169
|
highlight :phrase_highlighter => true
|
170
170
|
end
|
171
171
|
end
|
172
|
-
connection.
|
172
|
+
expect(connection).to have_last_search_with(
|
173
173
|
:"hl.usePhraseHighlighter" => 'true'
|
174
174
|
)
|
175
175
|
end
|
@@ -180,7 +180,7 @@ shared_examples_for "query with highlighting support" do
|
|
180
180
|
highlight :title, :phrase_highlighter => true
|
181
181
|
end
|
182
182
|
end
|
183
|
-
connection.
|
183
|
+
expect(connection).to have_last_search_with(
|
184
184
|
:"f.title_text.hl.usePhraseHighlighter" => 'true'
|
185
185
|
)
|
186
186
|
end
|
@@ -191,7 +191,7 @@ shared_examples_for "query with highlighting support" do
|
|
191
191
|
highlight :phrase_highlighter => true, :require_field_match => true
|
192
192
|
end
|
193
193
|
end
|
194
|
-
connection.
|
194
|
+
expect(connection).to have_last_search_with(
|
195
195
|
:"hl.requireFieldMatch" => 'true'
|
196
196
|
)
|
197
197
|
end
|
@@ -202,7 +202,7 @@ shared_examples_for "query with highlighting support" do
|
|
202
202
|
highlight :title, :phrase_highlighter => true, :require_field_match => true
|
203
203
|
end
|
204
204
|
end
|
205
|
-
connection.
|
205
|
+
expect(connection).to have_last_search_with(
|
206
206
|
:"f.title_text.hl.requireFieldMatch" => 'true'
|
207
207
|
)
|
208
208
|
end
|
@@ -214,7 +214,7 @@ shared_examples_for "query with highlighting support" do
|
|
214
214
|
highlight :body, :max_snippets => 1
|
215
215
|
end
|
216
216
|
end
|
217
|
-
connection.
|
217
|
+
expect(connection).to have_last_search_with(
|
218
218
|
:"hl.fl" => %w(title_text body_textsv),
|
219
219
|
:"f.title_text.hl.snippets" => 2,
|
220
220
|
:"f.body_textsv.hl.snippets" => 1
|
@@ -227,7 +227,7 @@ shared_examples_for "query with highlighting support" do
|
|
227
227
|
highlight :title, :formatter => 'formatter'
|
228
228
|
end
|
229
229
|
end
|
230
|
-
connection.
|
230
|
+
expect(connection).to have_last_search_with(
|
231
231
|
:"f.title_text.hl.formatter" => 'formatter'
|
232
232
|
)
|
233
233
|
end
|
@@ -238,7 +238,7 @@ shared_examples_for "query with highlighting support" do
|
|
238
238
|
highlight :title, :fragmenter => 'example_fragmenter'
|
239
239
|
end
|
240
240
|
end
|
241
|
-
connection.
|
241
|
+
expect(connection).to have_last_search_with(
|
242
242
|
:"f.title_text.hl.fragmenter" => 'example_fragmenter'
|
243
243
|
)
|
244
244
|
end
|