searchkick 1.3.4 → 1.3.5

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.
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "1.3.4"
2
+ VERSION = "1.3.5"
3
3
  end
data/test/aggs_test.rb CHANGED
@@ -100,16 +100,14 @@ class AggsTest < Minitest::Test
100
100
  store [{name: "Old Product", created_at: 3.years.ago}]
101
101
  aggs = Product.search(
102
102
  "Product",
103
- {
104
- aggs: {
105
- products_per_year: {
106
- date_histogram: {
107
- field: :created_at,
108
- interval: :year
109
- }
110
- }
111
- }
112
- }
103
+ aggs: {
104
+ products_per_year: {
105
+ date_histogram: {
106
+ field: :created_at,
107
+ interval: :year
108
+ }
109
+ }
110
+ }
113
111
  ).aggs
114
112
 
115
113
  if elasticsearch_below20?
data/test/boost_test.rb CHANGED
@@ -10,7 +10,7 @@ class BoostTest < Minitest::Test
10
10
  {name: "Tomato C", conversions: {"tomato" => 3}}
11
11
  ]
12
12
  assert_order "tomato", ["Tomato C", "Tomato B", "Tomato A"]
13
- assert_equal_scores "tomato", {conversions: false}
13
+ assert_equal_scores "tomato", conversions: false
14
14
  end
15
15
 
16
16
  def test_multiple_conversions
@@ -19,7 +19,7 @@ class BoostTest < Minitest::Test
19
19
  store [
20
20
  {name: "Speaker A", conversions_a: {"speaker" => 1}, conversions_b: {"speaker" => 6}},
21
21
  {name: "Speaker B", conversions_a: {"speaker" => 2}, conversions_b: {"speaker" => 5}},
22
- {name: "Speaker C", conversions_a: {"speaker" => 3}, conversions_b: {"speaker" => 4}},
22
+ {name: "Speaker C", conversions_a: {"speaker" => 3}, conversions_b: {"speaker" => 4}}
23
23
  ], Speaker
24
24
 
25
25
  assert_equal_scores "speaker", {conversions: false}, Speaker
data/test/errors_test.rb CHANGED
@@ -12,7 +12,7 @@ class ErrorsTest < Minitest::Test
12
12
  }
13
13
  }
14
14
  index.store valid_dog
15
- error = assert_raises(Searchkick::ImportError) do
15
+ assert_raises(Searchkick::ImportError) do
16
16
  index.bulk_index [valid_dog, invalid_dog]
17
17
  end
18
18
  end
data/test/index_test.rb CHANGED
@@ -92,7 +92,7 @@ class IndexTest < Minitest::Test
92
92
  end
93
93
 
94
94
  def test_unsupported_version
95
- raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") }
95
+ raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error, "[500] No query registered for [multi_match]" }
96
96
  Searchkick.client.stub :search, raises_exception do
97
97
  assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") }
98
98
  end
@@ -112,6 +112,14 @@ class IndexTest < Minitest::Test
112
112
  end
113
113
 
114
114
  def test_analyzed_only
115
+ # skip for 5.0 since it throws
116
+ # Cannot search on field [alt_description] since it is not indexed.
117
+ skip unless elasticsearch_below50?
118
+ store [{name: "Product A", alt_description: "Hello"}]
119
+ assert_search "*", [], where: {alt_description: "Hello"}
120
+ end
121
+
122
+ def test_analyzed_only_large_value
115
123
  skip if nobrainer?
116
124
  large_value = 10000.times.map { "hello" }.join(" ")
117
125
  store [{name: "Product A", alt_description: large_value}]
data/test/query_test.rb CHANGED
@@ -12,8 +12,9 @@ class QueryTest < Minitest::Test
12
12
  end
13
13
 
14
14
  def test_with_effective_min_score
15
+ min_score = elasticsearch_below50? ? 0.1 : 1
15
16
  store_names ["Milk", "Milk2"]
16
- assert_search "milk", ["Milk"], body_options: {min_score: 0.1}
17
+ assert_search "milk", ["Milk"], body_options: {min_score: min_score}
17
18
  end
18
19
 
19
20
  def test_with_uneffective_min_score
@@ -28,4 +29,8 @@ class QueryTest < Minitest::Test
28
29
  def test_timeout_override
29
30
  assert_equal "1s", Product.search("*", body_options: {timeout: "1s"}, execute: false).body[:timeout]
30
31
  end
32
+
33
+ def test_request_params
34
+ assert_equal "dfs_query_then_fetch", Product.search("*", request_params: {search_type: "dfs_query_then_fetch"}, execute: false).params[:search_type]
35
+ end
31
36
  end
data/test/sql_test.rb CHANGED
@@ -55,7 +55,7 @@ class SqlTest < Minitest::Test
55
55
  # body_options
56
56
 
57
57
  def test_body_options_should_merge_into_body
58
- query = Product.search({ query: { name: "milk"}, body_options: { min_score: 1.0 }}, execute: false)
58
+ query = Product.search({query: {name: "milk"}, body_options: {min_score: 1.0}}, execute: false)
59
59
  assert_equal 1.0, query.body[:min_score]
60
60
  end
61
61
 
@@ -163,6 +163,7 @@ class SqlTest < Minitest::Test
163
163
  end
164
164
 
165
165
  def test_select_v2_include
166
+ skip unless elasticsearch_below50?
166
167
  store [{name: "Product A", user_ids: [1, 2]}]
167
168
  result = Product.search("product", load: false, select_v2: {include: [:name]}).first
168
169
  assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
@@ -171,6 +172,7 @@ class SqlTest < Minitest::Test
171
172
  end
172
173
 
173
174
  def test_select_v2_exclude
175
+ skip unless elasticsearch_below50?
174
176
  store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
175
177
  result = Product.search("product", load: false, select_v2: {exclude: [:name]}).first
176
178
  assert_nil result.name
@@ -179,6 +181,7 @@ class SqlTest < Minitest::Test
179
181
  end
180
182
 
181
183
  def test_select_v2_include_and_exclude
184
+ skip unless elasticsearch_below50?
182
185
  # let's take this to the next level
183
186
  store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
184
187
  result = Product.search("product", load: false, select_v2: {include: [:store_id], exclude: [:name]}).first
@@ -187,6 +190,34 @@ class SqlTest < Minitest::Test
187
190
  assert_nil result.user_ids
188
191
  end
189
192
 
193
+ def test_select_v2_includes
194
+ skip if elasticsearch_below50?
195
+ store [{name: "Product A", user_ids: [1, 2]}]
196
+ result = Product.search("product", load: false, select_v2: {includes: [:name]}).first
197
+ assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
198
+ assert_equal "Product A", result.name
199
+ assert_nil result.store_id
200
+ end
201
+
202
+ def test_select_v2_excludes
203
+ skip if elasticsearch_below50?
204
+ store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
205
+ result = Product.search("product", load: false, select_v2: {excludes: [:name]}).first
206
+ assert_nil result.name
207
+ assert_equal [1, 2], result.user_ids
208
+ assert_equal 1, result.store_id
209
+ end
210
+
211
+ def test_select_v2_include_and_excludes
212
+ skip if elasticsearch_below50?
213
+ # let's take this to the next level
214
+ store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
215
+ result = Product.search("product", load: false, select_v2: {includes: [:store_id], excludes: [:name]}).first
216
+ assert_equal 1, result.store_id
217
+ assert_nil result.name
218
+ assert_nil result.user_ids
219
+ end
220
+
190
221
  # other tests
191
222
 
192
223
  def test_nested_object
data/test/test_helper.rb CHANGED
@@ -277,9 +277,9 @@ class Product
277
277
  ],
278
278
  autocomplete: [:name],
279
279
  suggest: [:name, :color],
280
- conversions: "conversions",
281
- personalize: "user_ids",
282
- locations: ["location", "multiple_locations"],
280
+ conversions: [:conversions],
281
+ personalize: :user_ids,
282
+ locations: [:location, :multiple_locations],
283
283
  text_start: [:name],
284
284
  text_middle: [:name],
285
285
  text_end: [:name],
@@ -287,12 +287,13 @@ class Product
287
287
  word_middle: [:name],
288
288
  word_end: [:name],
289
289
  highlight: [:name],
290
- # unsearchable: [:description],
291
290
  searchable: [:name, :color],
292
- only_analyzed: [:alt_description],
291
+ filterable: [:name, :color, :description],
292
+ # unsearchable: [:description],
293
+ # only_analyzed: [:alt_description],
293
294
  match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil
294
295
 
295
- attr_accessor :conversions, :user_ids, :aisle
296
+ attr_accessor :conversions, :user_ids, :aisle, :details
296
297
 
297
298
  def search_data
298
299
  serializable_hash.except("id").merge(
@@ -300,7 +301,8 @@ class Product
300
301
  user_ids: user_ids,
301
302
  location: {lat: latitude, lon: longitude},
302
303
  multiple_locations: [{lat: latitude, lon: longitude}, {lat: 0, lon: 0}],
303
- aisle: aisle
304
+ aisle: aisle,
305
+ details: details
304
306
  )
305
307
  end
306
308
 
@@ -339,7 +341,7 @@ class Speaker
339
341
  def search_data
340
342
  serializable_hash.except("id").merge(
341
343
  conversions_a: conversions_a,
342
- conversions_b: conversions_b,
344
+ conversions_b: conversions_b
343
345
  )
344
346
  end
345
347
  end
@@ -392,7 +394,7 @@ class Minitest::Test
392
394
  end
393
395
 
394
396
  def assert_equal_scores(term, options = {}, klass = Product)
395
- assert_equal 1, klass.search(term, options).hits.map { |a| a['_score'] }.uniq.size
397
+ assert_equal 1, klass.search(term, options).hits.map { |a| a["_score"] }.uniq.size
396
398
  end
397
399
 
398
400
  def assert_first(term, expected, options = {}, klass = Product)
data/test/where_test.rb CHANGED
@@ -168,4 +168,11 @@ class WhereTest < Minitest::Test
168
168
  ]
169
169
  assert_search "san", ["San Francisco"], where: {multiple_locations: {near: {lat: 37.5, lon: -122.5}}}
170
170
  end
171
+
172
+ def test_nested
173
+ store [
174
+ {name: "Product A", details: {year: 2016}}
175
+ ]
176
+ assert_search "product", ["Product A"], where: {"details.year" => 2016}
177
+ end
171
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -110,6 +110,7 @@ files:
110
110
  - Rakefile
111
111
  - lib/searchkick.rb
112
112
  - lib/searchkick/index.rb
113
+ - lib/searchkick/index_options.rb
113
114
  - lib/searchkick/logging.rb
114
115
  - lib/searchkick/middleware.rb
115
116
  - lib/searchkick/model.rb
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  requirements: []
183
184
  rubyforge_project:
184
- rubygems_version: 2.6.1
185
+ rubygems_version: 2.5.1
185
186
  signing_key:
186
187
  specification_version: 4
187
188
  summary: Searchkick learns what your users are looking for. As more people search,
@@ -229,4 +230,3 @@ test_files:
229
230
  - test/synonyms_test.rb
230
231
  - test/test_helper.rb
231
232
  - test/where_test.rb
232
- has_rdoc: