sunspot 2.0.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -2
  6. data/History.txt +10 -0
  7. data/lib/sunspot.rb +55 -17
  8. data/lib/sunspot/adapters.rb +68 -18
  9. data/lib/sunspot/batcher.rb +1 -1
  10. data/lib/sunspot/configuration.rb +4 -2
  11. data/lib/sunspot/data_extractor.rb +36 -6
  12. data/lib/sunspot/dsl.rb +4 -3
  13. data/lib/sunspot/dsl/adjustable.rb +2 -2
  14. data/lib/sunspot/dsl/field_query.rb +69 -16
  15. data/lib/sunspot/dsl/field_stats.rb +25 -0
  16. data/lib/sunspot/dsl/fields.rb +28 -8
  17. data/lib/sunspot/dsl/fulltext.rb +9 -1
  18. data/lib/sunspot/dsl/group.rb +118 -0
  19. data/lib/sunspot/dsl/paginatable.rb +4 -1
  20. data/lib/sunspot/dsl/scope.rb +19 -10
  21. data/lib/sunspot/dsl/search.rb +1 -1
  22. data/lib/sunspot/dsl/spellcheckable.rb +14 -0
  23. data/lib/sunspot/dsl/standard_query.rb +63 -35
  24. data/lib/sunspot/field.rb +76 -4
  25. data/lib/sunspot/field_factory.rb +60 -11
  26. data/lib/sunspot/indexer.rb +70 -18
  27. data/lib/sunspot/query.rb +5 -4
  28. data/lib/sunspot/query/abstract_field_facet.rb +0 -2
  29. data/lib/sunspot/query/abstract_fulltext.rb +76 -0
  30. data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
  31. data/lib/sunspot/query/bbox.rb +5 -1
  32. data/lib/sunspot/query/common_query.rb +31 -6
  33. data/lib/sunspot/query/composite_fulltext.rb +58 -8
  34. data/lib/sunspot/query/date_field_json_facet.rb +25 -0
  35. data/lib/sunspot/query/dismax.rb +25 -71
  36. data/lib/sunspot/query/field_json_facet.rb +19 -0
  37. data/lib/sunspot/query/field_list.rb +15 -0
  38. data/lib/sunspot/query/field_stats.rb +61 -0
  39. data/lib/sunspot/query/function_query.rb +1 -2
  40. data/lib/sunspot/query/geo.rb +1 -1
  41. data/lib/sunspot/query/geofilt.rb +8 -3
  42. data/lib/sunspot/query/group.rb +46 -0
  43. data/lib/sunspot/query/group_query.rb +17 -0
  44. data/lib/sunspot/query/join.rb +88 -0
  45. data/lib/sunspot/query/more_like_this.rb +1 -1
  46. data/lib/sunspot/query/pagination.rb +12 -4
  47. data/lib/sunspot/query/range_json_facet.rb +28 -0
  48. data/lib/sunspot/query/restriction.rb +99 -13
  49. data/lib/sunspot/query/sort.rb +41 -0
  50. data/lib/sunspot/query/sort_composite.rb +7 -0
  51. data/lib/sunspot/query/spellcheck.rb +19 -0
  52. data/lib/sunspot/query/standard_query.rb +24 -2
  53. data/lib/sunspot/query/text_field_boost.rb +1 -3
  54. data/lib/sunspot/schema.rb +12 -3
  55. data/lib/sunspot/search.rb +4 -2
  56. data/lib/sunspot/search/abstract_search.rb +93 -43
  57. data/lib/sunspot/search/cursor_paginated_collection.rb +32 -0
  58. data/lib/sunspot/search/field_facet.rb +4 -4
  59. data/lib/sunspot/search/field_json_facet.rb +33 -0
  60. data/lib/sunspot/search/field_stats.rb +21 -0
  61. data/lib/sunspot/search/hit.rb +6 -1
  62. data/lib/sunspot/search/hit_enumerable.rb +4 -1
  63. data/lib/sunspot/search/json_facet_row.rb +40 -0
  64. data/lib/sunspot/search/json_facet_stats.rb +23 -0
  65. data/lib/sunspot/search/paginated_collection.rb +1 -0
  66. data/lib/sunspot/search/query_group.rb +74 -0
  67. data/lib/sunspot/search/standard_search.rb +70 -3
  68. data/lib/sunspot/search/stats_facet.rb +25 -0
  69. data/lib/sunspot/search/stats_json_row.rb +82 -0
  70. data/lib/sunspot/search/stats_row.rb +68 -0
  71. data/lib/sunspot/session.rb +62 -37
  72. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +6 -4
  73. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +16 -8
  74. data/lib/sunspot/session_proxy/master_slave_session_proxy.rb +2 -2
  75. data/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +1 -1
  76. data/lib/sunspot/session_proxy/sharding_session_proxy.rb +4 -2
  77. data/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +1 -1
  78. data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +6 -4
  79. data/lib/sunspot/setup.rb +42 -0
  80. data/lib/sunspot/type.rb +20 -0
  81. data/lib/sunspot/util.rb +78 -14
  82. data/lib/sunspot/version.rb +1 -1
  83. data/spec/api/adapters_spec.rb +40 -15
  84. data/spec/api/batcher_spec.rb +15 -15
  85. data/spec/api/binding_spec.rb +3 -3
  86. data/spec/api/class_set_spec.rb +6 -6
  87. data/spec/api/data_extractor_spec.rb +39 -0
  88. data/spec/api/hit_enumerable_spec.rb +32 -9
  89. data/spec/api/indexer/attributes_spec.rb +35 -30
  90. data/spec/api/indexer/batch_spec.rb +8 -7
  91. data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
  92. data/spec/api/indexer/fixed_fields_spec.rb +16 -11
  93. data/spec/api/indexer/fulltext_spec.rb +8 -8
  94. data/spec/api/indexer/removal_spec.rb +24 -14
  95. data/spec/api/indexer_spec.rb +2 -2
  96. data/spec/api/query/advanced_manipulation_examples.rb +3 -3
  97. data/spec/api/query/connectives_examples.rb +26 -14
  98. data/spec/api/query/dsl_spec.rb +24 -6
  99. data/spec/api/query/dynamic_fields_examples.rb +18 -18
  100. data/spec/api/query/faceting_examples.rb +80 -61
  101. data/spec/api/query/fulltext_examples.rb +194 -40
  102. data/spec/api/query/function_spec.rb +116 -13
  103. data/spec/api/query/geo_examples.rb +8 -12
  104. data/spec/api/query/group_spec.rb +27 -5
  105. data/spec/api/query/highlighting_examples.rb +26 -26
  106. data/spec/api/query/join_spec.rb +19 -0
  107. data/spec/api/query/more_like_this_spec.rb +40 -27
  108. data/spec/api/query/ordering_pagination_examples.rb +37 -23
  109. data/spec/api/query/scope_examples.rb +39 -39
  110. data/spec/api/query/spatial_examples.rb +3 -3
  111. data/spec/api/query/spellcheck_examples.rb +20 -0
  112. data/spec/api/query/standard_spec.rb +3 -1
  113. data/spec/api/query/stats_examples.rb +66 -0
  114. data/spec/api/query/text_field_scoping_examples.rb +5 -5
  115. data/spec/api/query/types_spec.rb +4 -4
  116. data/spec/api/search/cursor_paginated_collection_spec.rb +35 -0
  117. data/spec/api/search/dynamic_fields_spec.rb +4 -4
  118. data/spec/api/search/faceting_spec.rb +55 -52
  119. data/spec/api/search/highlighting_spec.rb +7 -7
  120. data/spec/api/search/hits_spec.rb +43 -29
  121. data/spec/api/search/paginated_collection_spec.rb +19 -18
  122. data/spec/api/search/results_spec.rb +13 -13
  123. data/spec/api/search/search_spec.rb +3 -3
  124. data/spec/api/search/stats_spec.rb +94 -0
  125. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +23 -16
  126. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +16 -4
  127. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
  128. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +11 -11
  129. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +15 -14
  130. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +3 -3
  131. data/spec/api/session_proxy/spec_helper.rb +1 -1
  132. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +40 -26
  133. data/spec/api/session_spec.rb +78 -38
  134. data/spec/api/sunspot_spec.rb +7 -4
  135. data/spec/helpers/integration_helper.rb +11 -1
  136. data/spec/helpers/query_helper.rb +1 -1
  137. data/spec/helpers/search_helper.rb +30 -0
  138. data/spec/integration/atomic_updates_spec.rb +58 -0
  139. data/spec/integration/dynamic_fields_spec.rb +31 -20
  140. data/spec/integration/faceting_spec.rb +252 -39
  141. data/spec/integration/field_grouping_spec.rb +47 -15
  142. data/spec/integration/field_lists_spec.rb +57 -0
  143. data/spec/integration/geospatial_spec.rb +34 -8
  144. data/spec/integration/highlighting_spec.rb +8 -8
  145. data/spec/integration/indexing_spec.rb +7 -6
  146. data/spec/integration/join_spec.rb +45 -0
  147. data/spec/integration/keyword_search_spec.rb +68 -38
  148. data/spec/integration/local_search_spec.rb +4 -4
  149. data/spec/integration/more_like_this_spec.rb +7 -7
  150. data/spec/integration/scoped_search_spec.rb +193 -74
  151. data/spec/integration/spellcheck_spec.rb +119 -0
  152. data/spec/integration/stats_spec.rb +88 -0
  153. data/spec/integration/stored_fields_spec.rb +1 -1
  154. data/spec/integration/test_pagination.rb +4 -4
  155. data/spec/integration/unicode_spec.rb +1 -1
  156. data/spec/mocks/adapters.rb +36 -0
  157. data/spec/mocks/connection.rb +5 -3
  158. data/spec/mocks/photo.rb +32 -1
  159. data/spec/mocks/post.rb +18 -3
  160. data/spec/spec_helper.rb +13 -8
  161. data/sunspot.gemspec +6 -4
  162. data/tasks/rdoc.rake +22 -14
  163. metadata +101 -44
  164. data/lib/sunspot/dsl/field_group.rb +0 -57
  165. data/lib/sunspot/query/field_group.rb +0 -37
@@ -3,41 +3,41 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
3
  describe 'indexing fulltext fields' do
4
4
  it 'indexes text field' do
5
5
  session.index(post(:title => 'A Title'))
6
- connection.should have_add_with(:title_text => 'A Title')
6
+ expect(connection).to have_add_with(:title_text => 'A Title')
7
7
  end
8
8
 
9
9
  it 'indexes stored text field' do
10
10
  session.index(post(:body => 'Test body'))
11
- connection.should have_add_with(:body_textsv => 'Test body')
11
+ expect(connection).to have_add_with(:body_textsv => 'Test body')
12
12
  end
13
13
 
14
14
  it 'indexes text field with boost' do
15
15
  session.index(post(:title => 'A Title'))
16
- connection.adds.last.first.field_by_name(:title_text).attrs[:boost].should == 2
16
+ expect(connection.adds.last.first.field_by_name(:title_text).attrs[:boost]).to eq(2)
17
17
  end
18
18
 
19
19
  it 'indexes multiple values for a text field' do
20
20
  session.index(post(:body => %w(some title)))
21
- connection.should have_add_with(:body_textsv => %w(some title))
21
+ expect(connection).to have_add_with(:body_textsv => %w(some title))
22
22
  end
23
23
 
24
24
  it 'indexes text via a block accessor' do
25
25
  session.index(post(:title => 'backwards'))
26
- connection.should have_add_with(:backwards_title_text => 'sdrawkcab')
26
+ expect(connection).to have_add_with(:backwards_title_text => 'sdrawkcab')
27
27
  end
28
28
 
29
29
  it 'indexes document level boost using block' do
30
30
  session.index(post(:ratings_average => 4.0))
31
- connection.adds.last.first.attrs[:boost].should == 1.25
31
+ expect(connection.adds.last.first.attrs[:boost]).to eq(1.25)
32
32
  end
33
33
 
34
34
  it 'indexes document level boost using attribute' do
35
35
  session.index(Namespaced::Comment.new(:boost => 1.5))
36
- connection.adds.last.first.attrs[:boost].should == 1.5
36
+ expect(connection.adds.last.first.attrs[:boost]).to eq(1.5)
37
37
  end
38
38
 
39
39
  it 'indexes document level boost defined statically' do
40
40
  session.index(Photo.new)
41
- connection.adds.last.first.attrs[:boost].should == 0.75
41
+ expect(connection.adds.last.first.attrs[:boost]).to eq(0.75)
42
42
  end
43
43
  end
@@ -3,44 +3,54 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
3
  describe 'document removal', :type => :indexer do
4
4
  it 'removes an object from the index' do
5
5
  session.remove(post)
6
- connection.should have_delete("Post #{post.id}")
6
+ expect(connection).to have_delete("Post #{post.id}")
7
7
  end
8
8
 
9
9
  it 'removes an object by type and id' do
10
10
  session.remove_by_id(Post, 1)
11
- connection.should have_delete('Post 1')
11
+ expect(connection).to have_delete('Post 1')
12
12
  end
13
13
 
14
- it 'removes an object by type and id and immediately commits' do
15
- connection.should_receive(:delete_by_id).with(['Post 1']).ordered
16
- connection.should_receive(:commit).ordered
17
- session.remove_by_id!(Post, 1)
14
+ it 'removes an object by type and ids' do
15
+ session.remove_by_id(Post, 1, 2)
16
+ expect(connection).to have_delete('Post 1', 'Post 2')
17
+ end
18
+
19
+ it 'removes an object by type and ids array' do
20
+ session.remove_by_id(Post, [1, 2])
21
+ expect(connection).to have_delete('Post 1', 'Post 2')
22
+ end
23
+
24
+ it 'removes an object by type and ids and immediately commits' do
25
+ expect(connection).to receive(:delete_by_id).with(['Post 1', 'Post 2', 'Post 3']).ordered
26
+ expect(connection).to receive(:commit).ordered
27
+ session.remove_by_id!(Post, 1, 2, 3)
18
28
  end
19
29
 
20
30
  it 'removes an object from the index and immediately commits' do
21
- connection.should_receive(:delete_by_id).ordered
22
- connection.should_receive(:commit).ordered
31
+ expect(connection).to receive(:delete_by_id).ordered
32
+ expect(connection).to receive(:commit).ordered
23
33
  session.remove!(post)
24
34
  end
25
35
 
26
36
  it 'removes everything from the index' do
27
37
  session.remove_all
28
- connection.should have_delete_by_query("*:*")
38
+ expect(connection).to have_delete_by_query("*:*")
29
39
  end
30
40
 
31
41
  it 'removes everything from the index and immediately commits' do
32
- connection.should_receive(:delete_by_query).ordered
33
- connection.should_receive(:commit).ordered
42
+ expect(connection).to receive(:delete_by_query).ordered
43
+ expect(connection).to receive(:commit).ordered
34
44
  session.remove_all!
35
45
  end
36
46
 
37
47
  it 'removes everything of a given class from the index' do
38
48
  session.remove_all(Post)
39
- connection.should have_delete_by_query("type:Post")
49
+ expect(connection).to have_delete_by_query("type:Post")
40
50
  end
41
51
 
42
52
  it 'correctly escapes namespaced classes when removing everything from the index' do
43
- connection.should_receive(:delete_by_query).with('type:Namespaced\:\:Comment')
53
+ expect(connection).to receive(:delete_by_query).with('type:Namespaced\:\:Comment')
44
54
  session.remove_all(Namespaced::Comment)
45
55
  end
46
56
 
@@ -48,6 +58,6 @@ describe 'document removal', :type => :indexer do
48
58
  session.remove(Post) do
49
59
  with(:title, 'monkeys')
50
60
  end
51
- connection.should have_delete_by_query("(type:Post AND title_ss:monkeys)")
61
+ expect(connection).to have_delete_by_query("(type:Post AND title_ss:monkeys)")
52
62
  end
53
63
  end
@@ -7,8 +7,8 @@ describe 'indexer', :type => :indexer do
7
7
  Object.class_eval { remove_const(:ReloadableClass) }
8
8
  Object::ReloadableClass = Class.new(MockRecord)
9
9
  Sunspot.setup(ReloadableClass) {}
10
- lambda do
10
+ expect do
11
11
  Sunspot.search(ReloadableClass) { with(:title, 'title') }
12
- end.should raise_error(Sunspot::UnrecognizedFieldError)
12
+ end.to raise_error(Sunspot::UnrecognizedFieldError)
13
13
  end
14
14
  end
@@ -12,11 +12,11 @@ shared_examples_for "query with advanced manipulation" do
12
12
  end
13
13
 
14
14
  it "modifies existing param" do
15
- connection.should have_last_search_with(:rows => 40)
15
+ expect(connection).to have_last_search_with(:rows => 40)
16
16
  end
17
17
 
18
18
  it "adds new param" do
19
- connection.should have_last_search_with(:qt => 'complicated')
19
+ expect(connection).to have_last_search_with(:qt => 'complicated')
20
20
  end
21
21
  end
22
22
 
@@ -29,7 +29,7 @@ shared_examples_for "query with advanced manipulation" do
29
29
  end
30
30
 
31
31
  it 'should use specified request handler' do
32
- connection.should have_last_search_with({})
32
+ expect(connection).to have_last_search_with({})
33
33
  end
34
34
  end
35
35
  end
@@ -6,7 +6,7 @@ shared_examples_for "query with connective scope" do
6
6
  with :blog_id, 2
7
7
  end
8
8
  end
9
- connection.should have_last_search_including(
9
+ expect(connection).to have_last_search_including(
10
10
  :fq, '(category_ids_im:1 OR blog_id_i:2)'
11
11
  )
12
12
  end
@@ -21,7 +21,7 @@ shared_examples_for "query with connective scope" do
21
21
  end
22
22
  end
23
23
  end
24
- connection.should have_last_search_including(
24
+ expect(connection).to have_last_search_including(
25
25
  :fq,
26
26
  '(blog_id_i:2 OR (category_ids_im:1 AND average_rating_ft:{3\.0 TO *}))'
27
27
  )
@@ -37,7 +37,7 @@ shared_examples_for "query with connective scope" do
37
37
  end
38
38
  end
39
39
  end
40
- connection.should have_last_search_including(
40
+ expect(connection).to have_last_search_including(
41
41
  :fq, '(category_ids_im:1 OR (-average_rating_ft:{3\.0 TO *} AND blog_id_i:1))'
42
42
  )
43
43
  end
@@ -49,7 +49,7 @@ shared_examples_for "query with connective scope" do
49
49
  with :category_ids, 1
50
50
  end
51
51
  end
52
- connection.should have_last_search_including(
52
+ expect(connection).to have_last_search_including(
53
53
  :fq, 'blog_id_i:2', 'category_ids_im:1'
54
54
  )
55
55
  end
@@ -61,7 +61,7 @@ shared_examples_for "query with connective scope" do
61
61
  without(:average_rating).greater_than(3.0)
62
62
  end
63
63
  end
64
- connection.should have_last_search_including(
64
+ expect(connection).to have_last_search_including(
65
65
  :fq, '-(-category_ids_im:1 AND average_rating_ft:{3\.0 TO *})'
66
66
  )
67
67
  end
@@ -79,7 +79,7 @@ shared_examples_for "query with connective scope" do
79
79
  end
80
80
  end
81
81
  end
82
- connection.should have_last_search_including(
82
+ expect(connection).to have_last_search_including(
83
83
  :fq, '-(title_ss:Yes AND -(blog_id_i:1 AND -(-category_ids_im:4 AND average_rating_ft:2\.0)))'
84
84
  )
85
85
  end
@@ -96,7 +96,7 @@ shared_examples_for "query with connective scope" do
96
96
  end
97
97
  end
98
98
  end
99
- connection.should have_last_search_including(
99
+ expect(connection).to have_last_search_including(
100
100
  :fq, '(title_ss:Yes OR (blog_id_i:1 AND -(-category_ids_im:4 AND average_rating_ft:2\.0)))'
101
101
  )
102
102
  end
@@ -123,7 +123,7 @@ shared_examples_for "query with connective scope" do
123
123
  end
124
124
  end
125
125
  end
126
- connection.should have_last_search_including(
126
+ expect(connection).to have_last_search_including(
127
127
  :fq, '(title_ss:Yes OR blog_id_i:1 OR category_ids_im:4)'
128
128
  )
129
129
  end
@@ -136,7 +136,7 @@ shared_examples_for "query with connective scope" do
136
136
  with(:category_ids, 1)
137
137
  end
138
138
  end
139
- connection.should have_last_search_including(
139
+ expect(connection).to have_last_search_including(
140
140
  :fq, "-(id:(Post\\ #{post.id}) AND -category_ids_im:1)"
141
141
  )
142
142
  end
@@ -148,7 +148,7 @@ shared_examples_for "query with connective scope" do
148
148
  with(:average_rating).greater_than(3.0)
149
149
  end
150
150
  end
151
- connection.should have_last_search_including(
151
+ expect(connection).to have_last_search_including(
152
152
  :fq, '-(average_rating_ft:[* TO *] AND -average_rating_ft:{3\.0 TO *})'
153
153
  )
154
154
  end
@@ -161,7 +161,7 @@ shared_examples_for "query with connective scope" do
161
161
  with(:average_rating).greater_than(3.0)
162
162
  end
163
163
  end
164
- connection.should have_last_search_including(
164
+ expect(connection).to have_last_search_including(
165
165
  :fq, "(id:(Post\\ #{post.id}) OR average_rating_ft:{3\\.0 TO *})"
166
166
  )
167
167
  end
@@ -175,7 +175,7 @@ shared_examples_for "query with connective scope" do
175
175
  with(:blog_id, 1)
176
176
  end
177
177
  end
178
- connection.should have_last_search_including(
178
+ expect(connection).to have_last_search_including(
179
179
  :fq, '(title_text:test* OR blog_id_i:1)'
180
180
  )
181
181
  end
@@ -184,7 +184,7 @@ shared_examples_for "query with connective scope" do
184
184
  search do
185
185
  any_of {}
186
186
  end
187
- connection.should_not have_last_search_including(:fq, '')
187
+ expect(connection).not_to have_last_search_including(:fq, '')
188
188
  end
189
189
 
190
190
  it 'creates a conjunction of in_radius queries' do
@@ -194,8 +194,20 @@ shared_examples_for "query with connective scope" do
194
194
  with(:coordinates_new).in_radius(42, 56, 50)
195
195
  end
196
196
  end
197
- connection.should have_last_search_including(
197
+ expect(connection).to have_last_search_including(
198
198
  :fq, '(_query_:"{!geofilt sfield=coordinates_new_ll pt=23,-46 d=100}" OR _query_:"{!geofilt sfield=coordinates_new_ll pt=42,56 d=50}")'
199
199
  )
200
200
  end
201
+
202
+ it 'creates a conjunction of in_bounding_box queries' do
203
+ search do
204
+ any_of do
205
+ with(:coordinates_new).in_bounding_box([23, -46], [25, -44])
206
+ with(:coordinates_new).in_bounding_box([42, 56], [43, 58])
207
+ end
208
+ end
209
+ expect(connection).to have_last_search_including(
210
+ :fq, '(coordinates_new_ll:[23,-46 TO 25,-44] OR coordinates_new_ll:[42,56 TO 43,58])'
211
+ )
212
+ end
201
213
  end
@@ -1,18 +1,36 @@
1
1
  require File.expand_path('spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe 'query DSL', :type => :query do
4
+ let(:blog_id) { 1 }
5
+
4
6
  it 'should allow building search using block argument rather than instance_eval' do
5
- @blog_id = 1
6
7
  session.search Post do |query|
7
- query.with(:blog_id, @blog_id)
8
+ query.field_list [:blog_id, :title]
9
+ query.with(:blog_id, blog_id)
10
+ end
11
+ expect(connection).to have_last_search_including(:fq, 'blog_id_i:1')
12
+ expect(connection).to have_last_search_with(fl: [:id, :blog_id_i, :title_ss])
13
+ end
14
+
15
+ it 'should allow field_list specified as arguments' do
16
+ session.search Post do |query|
17
+ query.field_list :blog_id, :title
18
+ query.with(:blog_id, blog_id)
8
19
  end
9
- connection.should have_last_search_including(:fq, 'blog_id_i:1')
20
+ expect(connection).to have_last_search_with(fl: [:id, :blog_id_i, :title_ss])
21
+ end
22
+
23
+ it 'should allow to skip stored fields retrieval' do
24
+ session.search Post do |query|
25
+ query.with(:blog_id, blog_id)
26
+ query.without_stored_fields
27
+ end
28
+ expect(connection).to have_last_search_with(fl: [:id])
10
29
  end
11
30
 
12
31
  it 'should accept a block in the #new_search method' do
13
- search = session.new_search(Post) { with(:blog_id, 1) }
32
+ search = session.new_search(Post) { with(:blog_id, blog_id) }
14
33
  search.execute
15
- connection.should have_last_search_including(:fq, 'blog_id_i:1')
34
+ expect(connection).to have_last_search_including(:fq, 'blog_id_i:1')
16
35
  end
17
36
  end
18
-
@@ -5,7 +5,7 @@ shared_examples_for "query with dynamic field support" do
5
5
  with :test, 'string'
6
6
  end
7
7
  end
8
- connection.should have_last_search_including(:fq, 'custom_string\:test_ss:string')
8
+ expect(connection).to have_last_search_including(:fq, 'custom_string\:test_ss:string')
9
9
  end
10
10
 
11
11
  it 'restricts by dynamic integer field with less than restriction' do
@@ -14,7 +14,7 @@ shared_examples_for "query with dynamic field support" do
14
14
  with(:test).less_than(1)
15
15
  end
16
16
  end
17
- connection.should have_last_search_including(:fq, 'custom_integer\:test_i:{* TO 1}')
17
+ expect(connection).to have_last_search_including(:fq, 'custom_integer\:test_i:{* TO 1}')
18
18
  end
19
19
 
20
20
  it 'restricts by dynamic float field with between restriction' do
@@ -23,7 +23,7 @@ shared_examples_for "query with dynamic field support" do
23
23
  with(:test).between(2.2..3.3)
24
24
  end
25
25
  end
26
- connection.should have_last_search_including(:fq, 'custom_float\:test_fm:[2\.2 TO 3\.3]')
26
+ expect(connection).to have_last_search_including(:fq, 'custom_float\:test_fm:[2\.2 TO 3\.3]')
27
27
  end
28
28
 
29
29
  it 'restricts by dynamic time field with any of restriction' do
@@ -33,7 +33,7 @@ shared_examples_for "query with dynamic field support" do
33
33
  Time.parse('2009-02-13 18:00:00 UTC')])
34
34
  end
35
35
  end
36
- connection.should have_last_search_including(:fq, 'custom_time\:test_d:(2009\-02\-10T14\:00\:00Z OR 2009\-02\-13T18\:00\:00Z)')
36
+ expect(connection).to have_last_search_including(:fq, 'custom_time\:test_d:(2009\-02\-10T14\:00\:00Z OR 2009\-02\-13T18\:00\:00Z)')
37
37
  end
38
38
 
39
39
  it 'restricts by dynamic boolean field with equality restriction' do
@@ -42,7 +42,7 @@ shared_examples_for "query with dynamic field support" do
42
42
  with :test, false
43
43
  end
44
44
  end
45
- connection.should have_last_search_including(:fq, 'custom_boolean\:test_b:false')
45
+ expect(connection).to have_last_search_including(:fq, 'custom_boolean\:test_b:false')
46
46
  end
47
47
 
48
48
  it 'negates a dynamic field restriction' do
@@ -51,7 +51,7 @@ shared_examples_for "query with dynamic field support" do
51
51
  without :test, 'foo'
52
52
  end
53
53
  end
54
- connection.should have_last_search_including(:fq, '-custom_string\:test_ss:foo')
54
+ expect(connection).to have_last_search_including(:fq, '-custom_string\:test_ss:foo')
55
55
  end
56
56
 
57
57
  it 'scopes by a dynamic field inside a disjunction' do
@@ -63,7 +63,7 @@ shared_examples_for "query with dynamic field support" do
63
63
  with :title, 'bar'
64
64
  end
65
65
  end
66
- connection.should have_last_search_including(
66
+ expect(connection).to have_last_search_including(
67
67
  :fq, '(custom_string\:test_ss:foo OR title_ss:bar)'
68
68
  )
69
69
  end
@@ -74,7 +74,7 @@ shared_examples_for "query with dynamic field support" do
74
74
  order_by :test, :desc
75
75
  end
76
76
  end
77
- connection.should have_last_search_with(:sort => 'custom_integer:test_i desc')
77
+ expect(connection).to have_last_search_with(:sort => 'custom_integer:test_i desc')
78
78
  end
79
79
 
80
80
  it 'orders by a dynamic field and static field, with given precedence' do
@@ -84,25 +84,25 @@ shared_examples_for "query with dynamic field support" do
84
84
  end
85
85
  order_by :sort_title, :asc
86
86
  end
87
- connection.should have_last_search_with(:sort => 'custom_integer:test_i desc, sort_title_s asc')
87
+ expect(connection).to have_last_search_with(:sort => 'custom_integer:test_i desc, sort_title_s asc')
88
88
  end
89
89
 
90
90
  it 'raises an UnrecognizedFieldError if an unknown dynamic field is searched by' do
91
- lambda do
91
+ expect do
92
92
  search do
93
93
  dynamic(:bogus) { with :some, 'value' }
94
94
  end
95
- end.should raise_error(Sunspot::UnrecognizedFieldError)
95
+ end.to raise_error(Sunspot::UnrecognizedFieldError)
96
96
  end
97
97
 
98
98
  it 'raises a NoMethodError if pagination is attempted in a dynamic query' do
99
- lambda do
99
+ expect do
100
100
  search do
101
101
  dynamic :custom_string do
102
102
  paginate :page => 3, :per_page => 10
103
103
  end
104
104
  end
105
- end.should raise_error(NoMethodError)
105
+ end.to raise_error(NoMethodError)
106
106
  end
107
107
 
108
108
  it 'requests field facet on dynamic field' do
@@ -111,7 +111,7 @@ shared_examples_for "query with dynamic field support" do
111
111
  facet(:test)
112
112
  end
113
113
  end
114
- connection.should have_last_search_including(:"facet.field", 'custom_string:test_ss')
114
+ expect(connection).to have_last_search_including(:"facet.field", 'custom_string:test_ss')
115
115
  end
116
116
 
117
117
  it 'requests named field facet on dynamic field' do
@@ -120,7 +120,7 @@ shared_examples_for "query with dynamic field support" do
120
120
  facet(:test, :name => :bogus)
121
121
  end
122
122
  end
123
- connection.should have_last_search_including(:"facet.field", '{!key=bogus}custom_string:test_ss')
123
+ expect(connection).to have_last_search_including(:"facet.field", '{!key=bogus}custom_string:test_ss')
124
124
  end
125
125
 
126
126
  it 'requests query facet with internal dynamic field' do
@@ -133,7 +133,7 @@ shared_examples_for "query with dynamic field support" do
133
133
  end
134
134
  end
135
135
  end
136
- connection.should have_last_search_with(
136
+ expect(connection).to have_last_search_with(
137
137
  :"facet.query" => 'custom_string\:test_ss:foo'
138
138
  )
139
139
  end
@@ -148,7 +148,7 @@ shared_examples_for "query with dynamic field support" do
148
148
  end
149
149
  end
150
150
  end
151
- connection.should have_last_search_including(
151
+ expect(connection).to have_last_search_including(
152
152
  :"facet.query",
153
153
  'custom_string\:test_ss:foo'
154
154
  )
@@ -160,6 +160,6 @@ shared_examples_for "query with dynamic field support" do
160
160
  with(:test, 1.23)
161
161
  end
162
162
  end
163
- connection.should have_last_search_including(:fq, 'custom_float\\:test_fm:1\\.23')
163
+ expect(connection).to have_last_search_including(:fq, 'custom_float\\:test_fm:1\\.23')
164
164
  end
165
165
  end