sunspot 2.2.7 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -8
  6. data/lib/sunspot/adapters.rb +4 -1
  7. data/lib/sunspot/configuration.rb +1 -0
  8. data/lib/sunspot/data_extractor.rb +36 -6
  9. data/lib/sunspot/dsl/field_query.rb +11 -0
  10. data/lib/sunspot/dsl/field_stats.rb +7 -0
  11. data/lib/sunspot/dsl/fields.rb +16 -0
  12. data/lib/sunspot/dsl/group.rb +10 -0
  13. data/lib/sunspot/dsl/scope.rb +23 -18
  14. data/lib/sunspot/field.rb +11 -0
  15. data/lib/sunspot/field_factory.rb +6 -2
  16. data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
  17. data/lib/sunspot/query/bbox.rb +5 -1
  18. data/lib/sunspot/query/date_field_json_facet.rb +25 -0
  19. data/lib/sunspot/query/field_json_facet.rb +19 -0
  20. data/lib/sunspot/query/field_stats.rb +35 -2
  21. data/lib/sunspot/query/group.rb +4 -5
  22. data/lib/sunspot/query/join.rb +2 -4
  23. data/lib/sunspot/query/range_json_facet.rb +28 -0
  24. data/lib/sunspot/query/restriction.rb +19 -4
  25. data/lib/sunspot/query.rb +3 -3
  26. data/lib/sunspot/schema.rb +10 -2
  27. data/lib/sunspot/search/abstract_search.rb +14 -1
  28. data/lib/sunspot/search/field_json_facet.rb +33 -0
  29. data/lib/sunspot/search/hit.rb +6 -1
  30. data/lib/sunspot/search/hit_enumerable.rb +4 -1
  31. data/lib/sunspot/search/json_facet_row.rb +40 -0
  32. data/lib/sunspot/search/json_facet_stats.rb +23 -0
  33. data/lib/sunspot/search/standard_search.rb +2 -3
  34. data/lib/sunspot/search/stats_json_row.rb +82 -0
  35. data/lib/sunspot/search/stats_row.rb +3 -1
  36. data/lib/sunspot/search.rb +4 -3
  37. data/lib/sunspot/session.rb +13 -5
  38. data/lib/sunspot/setup.rb +31 -0
  39. data/lib/sunspot/util.rb +23 -0
  40. data/lib/sunspot/version.rb +1 -1
  41. data/spec/api/adapters_spec.rb +32 -19
  42. data/spec/api/batcher_spec.rb +15 -15
  43. data/spec/api/binding_spec.rb +3 -3
  44. data/spec/api/class_set_spec.rb +3 -3
  45. data/spec/api/data_extractor_spec.rb +39 -0
  46. data/spec/api/hit_enumerable_spec.rb +32 -9
  47. data/spec/api/indexer/attributes_spec.rb +31 -31
  48. data/spec/api/indexer/batch_spec.rb +8 -7
  49. data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
  50. data/spec/api/indexer/fixed_fields_spec.rb +12 -12
  51. data/spec/api/indexer/fulltext_spec.rb +8 -8
  52. data/spec/api/indexer/removal_spec.rb +14 -14
  53. data/spec/api/indexer_spec.rb +2 -2
  54. data/spec/api/query/advanced_manipulation_examples.rb +3 -3
  55. data/spec/api/query/connectives_examples.rb +26 -14
  56. data/spec/api/query/dsl_spec.rb +17 -9
  57. data/spec/api/query/dynamic_fields_examples.rb +18 -18
  58. data/spec/api/query/faceting_examples.rb +62 -62
  59. data/spec/api/query/fulltext_examples.rb +63 -58
  60. data/spec/api/query/function_spec.rb +26 -26
  61. data/spec/api/query/geo_examples.rb +6 -6
  62. data/spec/api/query/group_spec.rb +6 -6
  63. data/spec/api/query/highlighting_examples.rb +26 -26
  64. data/spec/api/query/join_spec.rb +2 -2
  65. data/spec/api/query/more_like_this_spec.rb +29 -29
  66. data/spec/api/query/ordering_pagination_examples.rb +25 -25
  67. data/spec/api/query/scope_examples.rb +39 -39
  68. data/spec/api/query/spatial_examples.rb +3 -3
  69. data/spec/api/query/spellcheck_examples.rb +3 -3
  70. data/spec/api/query/standard_spec.rb +1 -1
  71. data/spec/api/query/stats_examples.rb +8 -8
  72. data/spec/api/query/text_field_scoping_examples.rb +5 -5
  73. data/spec/api/query/types_spec.rb +4 -4
  74. data/spec/api/search/cursor_paginated_collection_spec.rb +12 -12
  75. data/spec/api/search/dynamic_fields_spec.rb +4 -4
  76. data/spec/api/search/faceting_spec.rb +55 -52
  77. data/spec/api/search/highlighting_spec.rb +7 -7
  78. data/spec/api/search/hits_spec.rb +43 -29
  79. data/spec/api/search/paginated_collection_spec.rb +18 -18
  80. data/spec/api/search/results_spec.rb +13 -13
  81. data/spec/api/search/search_spec.rb +3 -3
  82. data/spec/api/search/stats_spec.rb +10 -10
  83. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +19 -18
  84. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +9 -9
  85. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
  86. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +10 -10
  87. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +14 -13
  88. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +2 -2
  89. data/spec/api/session_proxy/spec_helper.rb +1 -1
  90. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +9 -5
  91. data/spec/api/session_spec.rb +42 -42
  92. data/spec/api/sunspot_spec.rb +7 -4
  93. data/spec/helpers/integration_helper.rb +1 -0
  94. data/spec/integration/atomic_updates_spec.rb +25 -11
  95. data/spec/integration/dynamic_fields_spec.rb +10 -10
  96. data/spec/integration/faceting_spec.rb +252 -39
  97. data/spec/integration/field_grouping_spec.rb +35 -16
  98. data/spec/integration/field_lists_spec.rb +57 -0
  99. data/spec/integration/geospatial_spec.rb +34 -8
  100. data/spec/integration/highlighting_spec.rb +5 -5
  101. data/spec/integration/indexing_spec.rb +5 -5
  102. data/spec/integration/join_spec.rb +45 -0
  103. data/spec/integration/keyword_search_spec.rb +47 -45
  104. data/spec/integration/local_search_spec.rb +4 -4
  105. data/spec/integration/more_like_this_spec.rb +7 -7
  106. data/spec/integration/scoped_search_spec.rb +108 -108
  107. data/spec/integration/spellcheck_spec.rb +52 -7
  108. data/spec/integration/stats_spec.rb +54 -13
  109. data/spec/integration/stored_fields_spec.rb +1 -1
  110. data/spec/integration/test_pagination.rb +4 -4
  111. data/spec/integration/unicode_spec.rb +1 -1
  112. data/spec/mocks/adapters.rb +33 -0
  113. data/spec/mocks/photo.rb +14 -4
  114. data/spec/mocks/post.rb +9 -1
  115. data/spec/spec_helper.rb +11 -10
  116. data/sunspot.gemspec +3 -1
  117. metadata +49 -6
@@ -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,28 +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
8
  query.field_list [:blog_id, :title]
8
- query.with(:blog_id, @blog_id)
9
+ query.with(:blog_id, blog_id)
9
10
  end
10
- connection.should have_last_search_including(:fq, 'blog_id_i:1')
11
- connection.should have_last_search_with(fl: [:blog_id, :title])
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])
12
13
  end
13
14
 
14
15
  it 'should allow field_list specified as arguments' do
15
- @blog_id = 1
16
16
  session.search Post do |query|
17
17
  query.field_list :blog_id, :title
18
- query.with(:blog_id, @blog_id)
18
+ query.with(:blog_id, blog_id)
19
+ end
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
19
27
  end
20
- connection.should have_last_search_with(fl: [:blog_id, :title])
28
+ expect(connection).to have_last_search_with(fl: [:id])
21
29
  end
22
30
 
23
31
  it 'should accept a block in the #new_search method' do
24
- search = session.new_search(Post) { with(:blog_id, 1) }
32
+ search = session.new_search(Post) { with(:blog_id, blog_id) }
25
33
  search.execute
26
- connection.should have_last_search_including(:fq, 'blog_id_i:1')
34
+ expect(connection).to have_last_search_including(:fq, 'blog_id_i:1')
27
35
  end
28
36
  end
@@ -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