Commit 454b59cc7c19406fae438dd7b57a2c5ef9ee81e6
Exists in
master
and in
21 other branches
Merge branch 'master' into agg_docs
Showing
28 changed files
with
47 additions
and
109 deletions
Show diff stats
lib/searchkick/index.rb
@@ -100,7 +100,7 @@ module Searchkick | @@ -100,7 +100,7 @@ module Searchkick | ||
100 | 100 | ||
101 | def similar_record(record, options = {}) | 101 | def similar_record(record, options = {}) |
102 | like_text = retrieve(record).to_hash | 102 | like_text = retrieve(record).to_hash |
103 | - .keep_if { |k, v| !options[:fields] || options[:fields].map(&:to_s).include?(k) } | 103 | + .keep_if { |k, _| !options[:fields] || options[:fields].map(&:to_s).include?(k) } |
104 | .values.compact.join(" ") | 104 | .values.compact.join(" ") |
105 | 105 | ||
106 | # TODO deep merge method | 106 | # TODO deep merge method |
@@ -118,9 +118,7 @@ module Searchkick | @@ -118,9 +118,7 @@ module Searchkick | ||
118 | 118 | ||
119 | def search_model(searchkick_klass, term = nil, options = {}, &block) | 119 | def search_model(searchkick_klass, term = nil, options = {}, &block) |
120 | query = Searchkick::Query.new(searchkick_klass, term, options) | 120 | query = Searchkick::Query.new(searchkick_klass, term, options) |
121 | - if block | ||
122 | - block.call(query.body) | ||
123 | - end | 121 | + block.call(query.body) if block |
124 | if options[:execute] == false | 122 | if options[:execute] == false |
125 | query | 123 | query |
126 | else | 124 | else |
@@ -350,9 +348,7 @@ module Searchkick | @@ -350,9 +348,7 @@ module Searchkick | ||
350 | # synonyms | 348 | # synonyms |
351 | synonyms = options[:synonyms] || [] | 349 | synonyms = options[:synonyms] || [] |
352 | 350 | ||
353 | - if synonyms.respond_to?(:call) | ||
354 | - synonyms = synonyms.call | ||
355 | - end | 351 | + synonyms = synonyms.call if synonyms.respond_to?(:call) |
356 | 352 | ||
357 | if synonyms.any? | 353 | if synonyms.any? |
358 | settings[:analysis][:filter][:searchkick_synonym] = { | 354 | settings[:analysis][:filter][:searchkick_synonym] = { |
@@ -384,7 +380,7 @@ module Searchkick | @@ -384,7 +380,7 @@ module Searchkick | ||
384 | end | 380 | end |
385 | 381 | ||
386 | if options[:special_characters] == false | 382 | if options[:special_characters] == false |
387 | - settings[:analysis][:analyzer].each do |analyzer, analyzer_settings| | 383 | + settings[:analysis][:analyzer].each do |_, analyzer_settings| |
388 | analyzer_settings[:filter].reject! { |f| f == "asciifolding" } | 384 | analyzer_settings[:filter].reject! { |f| f == "asciifolding" } |
389 | end | 385 | end |
390 | end | 386 | end |
@@ -566,6 +562,5 @@ module Searchkick | @@ -566,6 +562,5 @@ module Searchkick | ||
566 | obj | 562 | obj |
567 | end | 563 | end |
568 | end | 564 | end |
569 | - | ||
570 | end | 565 | end |
571 | end | 566 | end |
lib/searchkick/logging.rb
@@ -62,7 +62,8 @@ module Searchkick | @@ -62,7 +62,8 @@ module Searchkick | ||
62 | end | 62 | end |
63 | 63 | ||
64 | def self.reset_runtime | 64 | def self.reset_runtime |
65 | - rt, self.runtime = runtime, 0 | 65 | + rt = runtime |
66 | + self.runtime = 0 | ||
66 | rt | 67 | rt |
67 | end | 68 | end |
68 | 69 | ||
@@ -122,7 +123,8 @@ module Searchkick | @@ -122,7 +123,8 @@ module Searchkick | ||
122 | 123 | ||
123 | module ClassMethods | 124 | module ClassMethods |
124 | def log_process_action(payload) | 125 | def log_process_action(payload) |
125 | - messages, runtime = super, payload[:searchkick_runtime] | 126 | + messages = super |
127 | + runtime = payload[:searchkick_runtime] | ||
126 | messages << ("Searchkick: %.1fms" % runtime.to_f) if runtime.to_f > 0 | 128 | messages << ("Searchkick: %.1fms" % runtime.to_f) if runtime.to_f > 0 |
127 | messages | 129 | messages |
128 | end | 130 | end |
lib/searchkick/model.rb
@@ -2,7 +2,6 @@ module Searchkick | @@ -2,7 +2,6 @@ module Searchkick | ||
2 | module Reindex; end # legacy for Searchjoy | 2 | module Reindex; end # legacy for Searchjoy |
3 | 3 | ||
4 | module Model | 4 | module Model |
5 | - | ||
6 | def searchkick(options = {}) | 5 | def searchkick(options = {}) |
7 | raise "Only call searchkick once per model" if respond_to?(:searchkick_index) | 6 | raise "Only call searchkick once per model" if respond_to?(:searchkick_index) |
8 | 7 | ||
@@ -94,9 +93,7 @@ module Searchkick | @@ -94,9 +93,7 @@ module Searchkick | ||
94 | def should_index? | 93 | def should_index? |
95 | true | 94 | true |
96 | end unless method_defined?(:should_index?) | 95 | end unless method_defined?(:should_index?) |
97 | - | ||
98 | end | 96 | end |
99 | end | 97 | end |
100 | - | ||
101 | end | 98 | end |
102 | end | 99 | end |
lib/searchkick/query.rb
@@ -190,11 +190,9 @@ module Searchkick | @@ -190,11 +190,9 @@ module Searchkick | ||
190 | if boost_by.is_a?(Array) | 190 | if boost_by.is_a?(Array) |
191 | boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }] | 191 | boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }] |
192 | elsif boost_by.is_a?(Hash) | 192 | elsif boost_by.is_a?(Hash) |
193 | - multiply_by, boost_by = boost_by.partition { |k,v| v[:boost_mode] == "multiply" }.map{ |i| Hash[i] } | ||
194 | - end | ||
195 | - if options[:boost] | ||
196 | - boost_by[options[:boost]] = {factor: 1} | 193 | + multiply_by, boost_by = boost_by.partition { |_, v| v[:boost_mode] == "multiply" }.map { |i| Hash[i] } |
197 | end | 194 | end |
195 | + boost_by[options[:boost]] = {factor: 1} if options[:boost] | ||
198 | 196 | ||
199 | custom_filters.concat boost_filters(boost_by, log: true) | 197 | custom_filters.concat boost_filters(boost_by, log: true) |
200 | multiply_filters.concat boost_filters(multiply_by || {}) | 198 | multiply_filters.concat boost_filters(multiply_by || {}) |
@@ -209,12 +207,10 @@ module Searchkick | @@ -209,12 +207,10 @@ module Searchkick | ||
209 | boost_where.each do |field, value| | 207 | boost_where.each do |field, value| |
210 | if value.is_a?(Array) && value.first.is_a?(Hash) | 208 | if value.is_a?(Array) && value.first.is_a?(Hash) |
211 | value.each do |value_factor| | 209 | value.each do |value_factor| |
212 | - value, factor = value_factor[:value], value_factor[:factor] | ||
213 | - custom_filters << custom_filter(field, value, factor) | 210 | + custom_filters << custom_filter(field, value_factor[:value], value_factor[:factor]) |
214 | end | 211 | end |
215 | elsif value.is_a?(Hash) | 212 | elsif value.is_a?(Hash) |
216 | - value, factor = value[:value], value[:factor] | ||
217 | - custom_filters << custom_filter(field, value, factor) | 213 | + custom_filters << custom_filter(field, value[:value], value[:factor]) |
218 | else | 214 | else |
219 | factor = 1000 | 215 | factor = 1000 |
220 | custom_filters << custom_filter(field, value, factor) | 216 | custom_filters << custom_filter(field, value, factor) |
@@ -227,7 +223,7 @@ module Searchkick | @@ -227,7 +223,7 @@ module Searchkick | ||
227 | if !boost_by_distance[:field] || !boost_by_distance[:origin] | 223 | if !boost_by_distance[:field] || !boost_by_distance[:origin] |
228 | raise ArgumentError, "boost_by_distance requires :field and :origin" | 224 | raise ArgumentError, "boost_by_distance requires :field and :origin" |
229 | end | 225 | end |
230 | - function_params = boost_by_distance.select { |k, v| [:origin, :scale, :offset, :decay].include?(k) } | 226 | + function_params = boost_by_distance.select { |k, _| [:origin, :scale, :offset, :decay].include?(k) } |
231 | function_params[:origin] = function_params[:origin].reverse | 227 | function_params[:origin] = function_params[:origin].reverse |
232 | custom_filters << { | 228 | custom_filters << { |
233 | boost_by_distance[:function] => { | 229 | boost_by_distance[:function] => { |
@@ -293,9 +289,7 @@ module Searchkick | @@ -293,9 +289,7 @@ module Searchkick | ||
293 | # facets | 289 | # facets |
294 | if options[:facets] | 290 | if options[:facets] |
295 | facets = options[:facets] || {} | 291 | facets = options[:facets] || {} |
296 | - if facets.is_a?(Array) # convert to more advanced syntax | ||
297 | - facets = Hash[facets.map { |f| [f, {}] }] | ||
298 | - end | 292 | + facets = Hash[facets.map { |f| [f, {}] }] if facets.is_a?(Array) # convert to more advanced syntax |
299 | 293 | ||
300 | payload[:facets] = {} | 294 | payload[:facets] = {} |
301 | facets.each do |field, facet_options| | 295 | facets.each do |field, facet_options| |
@@ -331,7 +325,7 @@ module Searchkick | @@ -331,7 +325,7 @@ module Searchkick | ||
331 | # offset is not possible | 325 | # offset is not possible |
332 | # http://elasticsearch-users.115913.n3.nabble.com/Is-pagination-possible-in-termsStatsFacet-td3422943.html | 326 | # http://elasticsearch-users.115913.n3.nabble.com/Is-pagination-possible-in-termsStatsFacet-td3422943.html |
333 | 327 | ||
334 | - facet_options.deep_merge!(where: options.fetch(:where, {}).reject { |k| k == field } ) if options[:smart_facets] == true | 328 | + facet_options.deep_merge!(where: options.fetch(:where, {}).reject { |k| k == field }) if options[:smart_facets] == true |
335 | facet_filters = where_filters(facet_options[:where]) | 329 | facet_filters = where_filters(facet_options[:where]) |
336 | if facet_filters.any? | 330 | if facet_filters.any? |
337 | payload[:facets][field][:facet_filter] = { | 331 | payload[:facets][field][:facet_filter] = { |
@@ -348,9 +342,7 @@ module Searchkick | @@ -348,9 +342,7 @@ module Searchkick | ||
348 | aggs = options[:aggs] | 342 | aggs = options[:aggs] |
349 | payload[:aggs] = {} | 343 | payload[:aggs] = {} |
350 | 344 | ||
351 | - if aggs.is_a?(Array) # convert to more advanced syntax | ||
352 | - aggs = aggs.map { |f| [f, {}] }.to_h | ||
353 | - end | 345 | + aggs = aggs.map { |f| [f, {}] }.to_h if aggs.is_a?(Array) # convert to more advanced syntax |
354 | 346 | ||
355 | aggs.each do |field, agg_options| | 347 | aggs.each do |field, agg_options| |
356 | size = agg_options[:limit] ? agg_options[:limit] : 100_000 | 348 | size = agg_options[:limit] ? agg_options[:limit] : 100_000 |
@@ -441,9 +433,7 @@ module Searchkick | @@ -441,9 +433,7 @@ module Searchkick | ||
441 | end | 433 | end |
442 | 434 | ||
443 | # routing | 435 | # routing |
444 | - if options[:routing] | ||
445 | - @routing = options[:routing] | ||
446 | - end | 436 | + @routing = options[:routing] if options[:routing] |
447 | end | 437 | end |
448 | 438 | ||
449 | @body = payload | 439 | @body = payload |
@@ -539,9 +529,7 @@ module Searchkick | @@ -539,9 +529,7 @@ module Searchkick | ||
539 | value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last} | 529 | value = {gte: value.first, (value.exclude_end? ? :lt : :lte) => value.last} |
540 | end | 530 | end |
541 | 531 | ||
542 | - if value.is_a?(Array) | ||
543 | - value = {in: value} | ||
544 | - end | 532 | + value = {in: value} if value.is_a?(Array) |
545 | 533 | ||
546 | if value.is_a?(Hash) | 534 | if value.is_a?(Hash) |
547 | value.each do |op, op_value| | 535 | value.each do |op, op_value| |
@@ -623,7 +611,7 @@ module Searchkick | @@ -623,7 +611,7 @@ module Searchkick | ||
623 | def custom_filter(field, value, factor) | 611 | def custom_filter(field, value, factor) |
624 | { | 612 | { |
625 | filter: { | 613 | filter: { |
626 | - and: where_filters({field => value}) | 614 | + and: where_filters(field => value) |
627 | }, | 615 | }, |
628 | boost_factor: factor | 616 | boost_factor: factor |
629 | } | 617 | } |
lib/searchkick/reindex_job.rb
1 | module Searchkick | 1 | module Searchkick |
2 | class ReindexJob | 2 | class ReindexJob |
3 | - | ||
4 | def initialize(klass, id) | 3 | def initialize(klass, id) |
5 | @klass = klass | 4 | @klass = klass |
6 | @id = id | 5 | @id = id |
@@ -23,6 +22,5 @@ module Searchkick | @@ -23,6 +22,5 @@ module Searchkick | ||
23 | index.store record | 22 | index.store record |
24 | end | 23 | end |
25 | end | 24 | end |
26 | - | ||
27 | end | 25 | end |
28 | end | 26 | end |
lib/searchkick/reindex_v2_job.rb
lib/searchkick/results.rb
@@ -26,7 +26,7 @@ module Searchkick | @@ -26,7 +26,7 @@ module Searchkick | ||
26 | # results can have different types | 26 | # results can have different types |
27 | results = {} | 27 | results = {} |
28 | 28 | ||
29 | - hits.group_by { |hit, i| hit["_type"] }.each do |type, grouped_hits| | 29 | + hits.group_by { |hit, _| hit["_type"] }.each do |type, grouped_hits| |
30 | results[type] = results_query(type.camelize.constantize, grouped_hits).to_a.index_by { |r| r.id.to_s } | 30 | results[type] = results_query(type.camelize.constantize, grouped_hits).to_a.index_by { |r| r.id.to_s } |
31 | end | 31 | end |
32 | 32 |
lib/searchkick/tasks.rb
1 | require "rake" | 1 | require "rake" |
2 | 2 | ||
3 | namespace :searchkick do | 3 | namespace :searchkick do |
4 | - | ||
5 | desc "reindex model" | 4 | desc "reindex model" |
6 | task reindex: :environment do | 5 | task reindex: :environment do |
7 | if ENV["CLASS"] | 6 | if ENV["CLASS"] |
@@ -31,5 +30,4 @@ namespace :searchkick do | @@ -31,5 +30,4 @@ namespace :searchkick do | ||
31 | end | 30 | end |
32 | 31 | ||
33 | end | 32 | end |
34 | - | ||
35 | end | 33 | end |
test/aggs_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestAggs < Minitest::Test | ||
4 | - | 3 | +class AggsTest < Minitest::Test |
5 | def setup | 4 | def setup |
6 | super | 5 | super |
7 | store [ | 6 | store [ |
@@ -79,5 +78,4 @@ class TestAggs < Minitest::Test | @@ -79,5 +78,4 @@ class TestAggs < Minitest::Test | ||
79 | [field, buckets_as_hash(filtered_agg)] | 78 | [field, buckets_as_hash(filtered_agg)] |
80 | end.to_h | 79 | end.to_h |
81 | end | 80 | end |
82 | - | ||
83 | end | 81 | end |
test/autocomplete_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestAutocomplete < Minitest::Test | ||
4 | - | 3 | +class AutocompleteTest < Minitest::Test |
5 | def test_autocomplete | 4 | def test_autocomplete |
6 | store_names ["Hummus"] | 5 | store_names ["Hummus"] |
7 | assert_search "hum", ["Hummus"], autocomplete: true | 6 | assert_search "hum", ["Hummus"], autocomplete: true |
@@ -63,5 +62,4 @@ class TestAutocomplete < Minitest::Test | @@ -63,5 +62,4 @@ class TestAutocomplete < Minitest::Test | ||
63 | store_names ["hi@example.org"] | 62 | store_names ["hi@example.org"] |
64 | assert_search "hi@example.org", ["hi@example.org"], fields: [{name: :exact}] | 63 | assert_search "hi@example.org", ["hi@example.org"], fields: [{name: :exact}] |
65 | end | 64 | end |
66 | - | ||
67 | end | 65 | end |
test/boost_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestBoost < Minitest::Test | ||
4 | - | 3 | +class BoostTest < Minitest::Test |
5 | # conversions | 4 | # conversions |
6 | 5 | ||
7 | def test_conversions | 6 | def test_conversions |
@@ -133,5 +132,4 @@ class TestBoost < Minitest::Test | @@ -133,5 +132,4 @@ class TestBoost < Minitest::Test | ||
133 | ] | 132 | ] |
134 | assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: [37, -122], scale: "1000mi"} | 133 | assert_order "san", ["San Francisco", "San Antonio", "San Marino"], boost_by_distance: {field: :location, origin: [37, -122], scale: "1000mi"} |
135 | end | 134 | end |
136 | - | ||
137 | end | 135 | end |
test/facets_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestFacets < Minitest::Test | ||
4 | - | 3 | +class FacetsTest < Minitest::Test |
5 | def setup | 4 | def setup |
6 | skip if elasticsearch2? | 5 | skip if elasticsearch2? |
7 | super | 6 | super |
@@ -79,14 +78,13 @@ class TestFacets < Minitest::Test | @@ -79,14 +78,13 @@ class TestFacets < Minitest::Test | ||
79 | skip if Gem::Version.new(Searchkick.server_version) >= Gem::Version.new("1.4.0") | 78 | skip if Gem::Version.new(Searchkick.server_version) >= Gem::Version.new("1.4.0") |
80 | options = {where: {store_id: 2}, facets: {store_id: {stats: true}}} | 79 | options = {where: {store_id: 2}, facets: {store_id: {stats: true}}} |
81 | facets = Product.search("Product", options).facets["store_id"]["terms"] | 80 | facets = Product.search("Product", options).facets["store_id"]["terms"] |
82 | - expected_facets_keys = %w[term count total_count min max total mean] | 81 | + expected_facets_keys = %w(term count total_count min max total mean) |
83 | assert_equal expected_facets_keys, facets.first.keys | 82 | assert_equal expected_facets_keys, facets.first.keys |
84 | end | 83 | end |
85 | 84 | ||
86 | protected | 85 | protected |
87 | 86 | ||
88 | - def store_facet(options, facet_key="store_id") | 87 | + def store_facet(options, facet_key = "store_id") |
89 | Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }] | 88 | Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }] |
90 | end | 89 | end |
91 | - | ||
92 | end | 90 | end |
test/highlight_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestHighlight < Minitest::Test | ||
4 | - | 3 | +class HighlightTest < Minitest::Test |
5 | def test_basic | 4 | def test_basic |
6 | store_names ["Two Door Cinema Club"] | 5 | store_names ["Two Door Cinema Club"] |
7 | assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).with_details.first[1][:highlight][:name] | 6 | assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).with_details.first[1][:highlight][:name] |
@@ -54,5 +53,4 @@ class TestHighlight < Minitest::Test | @@ -54,5 +53,4 @@ class TestHighlight < Minitest::Test | ||
54 | } | 53 | } |
55 | assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(json: json).with_details.first[1][:highlight][:"name.analyzed"] | 54 | assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(json: json).with_details.first[1][:highlight][:"name.analyzed"] |
56 | end | 55 | end |
57 | - | ||
58 | end | 56 | end |
test/index_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestIndex < Minitest::Test | ||
4 | - | 3 | +class IndexTest < Minitest::Test |
5 | def test_clean_indices | 4 | def test_clean_indices |
6 | old_index = Searchkick::Index.new("products_test_20130801000000000") | 5 | old_index = Searchkick::Index.new("products_test_20130801000000000") |
7 | different_index = Searchkick::Index.new("items_test_20130801000000000") | 6 | different_index = Searchkick::Index.new("items_test_20130801000000000") |
@@ -93,7 +92,7 @@ class TestIndex < Minitest::Test | @@ -93,7 +92,7 @@ class TestIndex < Minitest::Test | ||
93 | end | 92 | end |
94 | 93 | ||
95 | def test_unsupported_version | 94 | def test_unsupported_version |
96 | - raises_exception = ->(s) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") } | 95 | + raises_exception = ->(_) { raise Elasticsearch::Transport::Transport::Error.new("[500] No query registered for [multi_match]") } |
97 | Searchkick.client.stub :search, raises_exception do | 96 | Searchkick.client.stub :search, raises_exception do |
98 | assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") } | 97 | assert_raises(Searchkick::UnsupportedVersionError) { Product.search("test") } |
99 | end | 98 | end |
@@ -115,5 +114,4 @@ class TestIndex < Minitest::Test | @@ -115,5 +114,4 @@ class TestIndex < Minitest::Test | ||
115 | end | 114 | end |
116 | 115 | ||
117 | end | 116 | end |
118 | - | ||
119 | end | 117 | end |
test/inheritance_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestInheritance < Minitest::Test | ||
4 | - | 3 | +class InheritanceTest < Minitest::Test |
5 | def test_child_reindex | 4 | def test_child_reindex |
6 | store_names ["Max"], Cat | 5 | store_names ["Max"], Cat |
7 | assert Dog.reindex | 6 | assert Dog.reindex |
@@ -76,5 +75,4 @@ class TestInheritance < Minitest::Test | @@ -76,5 +75,4 @@ class TestInheritance < Minitest::Test | ||
76 | store_names ["Product B"], Animal | 75 | store_names ["Product B"], Animal |
77 | assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false | 76 | assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false |
78 | end | 77 | end |
79 | - | ||
80 | end | 78 | end |
test/match_test.rb
@@ -2,8 +2,7 @@ | @@ -2,8 +2,7 @@ | ||
2 | 2 | ||
3 | require_relative "test_helper" | 3 | require_relative "test_helper" |
4 | 4 | ||
5 | -class TestMatch < Minitest::Test | ||
6 | - | 5 | +class MatchTest < Minitest::Test |
7 | # exact | 6 | # exact |
8 | 7 | ||
9 | def test_match | 8 | def test_match |
@@ -195,5 +194,4 @@ class TestMatch < Minitest::Test | @@ -195,5 +194,4 @@ class TestMatch < Minitest::Test | ||
195 | ] | 194 | ] |
196 | assert_search "almond", [] | 195 | assert_search "almond", [] |
197 | end | 196 | end |
198 | - | ||
199 | end | 197 | end |
test/model_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestModel < Minitest::Test | ||
4 | - | 3 | +class ModelTest < Minitest::Test |
5 | def test_disable_callbacks_model | 4 | def test_disable_callbacks_model |
6 | store_names ["product a"] | 5 | store_names ["product a"] |
7 | 6 | ||
@@ -20,7 +19,7 @@ class TestModel < Minitest::Test | @@ -20,7 +19,7 @@ class TestModel < Minitest::Test | ||
20 | def test_disable_callbacks_global | 19 | def test_disable_callbacks_global |
21 | # make sure callbacks default to on | 20 | # make sure callbacks default to on |
22 | assert Searchkick.callbacks? | 21 | assert Searchkick.callbacks? |
23 | - | 22 | + |
24 | store_names ["product a"] | 23 | store_names ["product a"] |
25 | 24 | ||
26 | Searchkick.disable_callbacks | 25 | Searchkick.disable_callbacks |
@@ -34,5 +33,4 @@ class TestModel < Minitest::Test | @@ -34,5 +33,4 @@ class TestModel < Minitest::Test | ||
34 | 33 | ||
35 | assert_search "product", ["product a", "product b"] | 34 | assert_search "product", ["product a", "product b"] |
36 | end | 35 | end |
37 | - | ||
38 | end | 36 | end |
test/query_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestQuery < Minitest::Test | ||
4 | - | 3 | +class QueryTest < Minitest::Test |
5 | def test_basic | 4 | def test_basic |
6 | store_names ["Milk", "Apple"] | 5 | store_names ["Milk", "Apple"] |
7 | query = Product.search("milk", execute: false) | 6 | query = Product.search("milk", execute: false) |
@@ -10,5 +9,4 @@ class TestQuery < Minitest::Test | @@ -10,5 +9,4 @@ class TestQuery < Minitest::Test | ||
10 | query.body[:query] = {match_all: {}} | 9 | query.body[:query] = {match_all: {}} |
11 | assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort | 10 | assert_equal ["Apple", "Milk"], query.execute.map(&:name).sort |
12 | end | 11 | end |
13 | - | ||
14 | end | 12 | end |
test/records_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | class RecordsTest < Minitest::Test | 3 | class RecordsTest < Minitest::Test |
4 | - | ||
5 | def test_records | 4 | def test_records |
6 | store_names ["Milk", "Apple"] | 5 | store_names ["Milk", "Apple"] |
7 | assert_equal Product.search("milk").records.where(name: "Milk").count, 1 | 6 | assert_equal Product.search("milk").records.where(name: "Milk").count, 1 |
8 | end | 7 | end |
9 | - | ||
10 | end | 8 | end |
test/reindex_job_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestReindexJob < Minitest::Test | ||
4 | - | 3 | +class ReindexJobTest < Minitest::Test |
5 | def setup | 4 | def setup |
6 | super | 5 | super |
7 | Searchkick.disable_callbacks | 6 | Searchkick.disable_callbacks |
@@ -29,5 +28,4 @@ class TestReindexJob < Minitest::Test | @@ -29,5 +28,4 @@ class TestReindexJob < Minitest::Test | ||
29 | Product.searchkick_index.refresh | 28 | Product.searchkick_index.refresh |
30 | assert_search "*", [] | 29 | assert_search "*", [] |
31 | end | 30 | end |
32 | - | ||
33 | end | 31 | end |
test/reindex_v2_job_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestReindexV2Job < Minitest::Test | ||
4 | - | 3 | +class ReindexV2JobTest < Minitest::Test |
5 | def setup | 4 | def setup |
6 | skip unless defined?(ActiveJob) | 5 | skip unless defined?(ActiveJob) |
7 | super | 6 | super |
@@ -30,5 +29,4 @@ class TestReindexV2Job < Minitest::Test | @@ -30,5 +29,4 @@ class TestReindexV2Job < Minitest::Test | ||
30 | Product.searchkick_index.refresh | 29 | Product.searchkick_index.refresh |
31 | assert_search "*", [] | 30 | assert_search "*", [] |
32 | end | 31 | end |
33 | - | ||
34 | end | 32 | end |
test/routing_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestRouting < Minitest::Test | ||
4 | - | 3 | +class RoutingTest < Minitest::Test |
5 | def test_routing_query | 4 | def test_routing_query |
6 | skip if elasticsearch2? | 5 | skip if elasticsearch2? |
7 | query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) | 6 | query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) |
@@ -11,6 +10,6 @@ class TestRouting < Minitest::Test | @@ -11,6 +10,6 @@ class TestRouting < Minitest::Test | ||
11 | def test_routing_mappings | 10 | def test_routing_mappings |
12 | skip if elasticsearch2? | 11 | skip if elasticsearch2? |
13 | index_options = Store.searchkick_index.index_options | 12 | index_options = Store.searchkick_index.index_options |
14 | - assert_equal index_options[:mappings][:_default_][:_routing], {required: true, path: "name"} | 13 | + assert_equal index_options[:mappings][:_default_][:_routing], required: true, path: "name" |
15 | end | 14 | end |
16 | end | 15 | end |
test/should_index_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestShouldIndex < Minitest::Test | ||
4 | - | 3 | +class ShouldIndexTest < Minitest::Test |
5 | def test_basic | 4 | def test_basic |
6 | store_names ["INDEX", "DO NOT INDEX"] | 5 | store_names ["INDEX", "DO NOT INDEX"] |
7 | assert_search "index", ["INDEX"] | 6 | assert_search "index", ["INDEX"] |
@@ -30,5 +29,4 @@ class TestShouldIndex < Minitest::Test | @@ -30,5 +29,4 @@ class TestShouldIndex < Minitest::Test | ||
30 | Product.searchkick_index.refresh | 29 | Product.searchkick_index.refresh |
31 | assert_search "index", [] | 30 | assert_search "index", [] |
32 | end | 31 | end |
33 | - | ||
34 | end | 32 | end |
test/similar_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestSimilar < Minitest::Test | ||
4 | - | 3 | +class SimilarTest < Minitest::Test |
5 | def test_similar | 4 | def test_similar |
6 | store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"] | 5 | store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"] |
7 | assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true | 6 | assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true |
@@ -16,5 +15,4 @@ class TestSimilar < Minitest::Test | @@ -16,5 +15,4 @@ class TestSimilar < Minitest::Test | ||
16 | store_names ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"] | 15 | store_names ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"] |
17 | assert_order "Lucerne Fat Free Chocolate Milk", ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"], similar: true | 16 | assert_order "Lucerne Fat Free Chocolate Milk", ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"], similar: true |
18 | end | 17 | end |
19 | - | ||
20 | end | 18 | end |
test/sql_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestSql < Minitest::Test | ||
4 | - | 3 | +class SqlTest < Minitest::Test |
5 | def test_limit | 4 | def test_limit |
6 | store_names ["Product A", "Product B", "Product C", "Product D"] | 5 | store_names ["Product A", "Product B", "Product C", "Product D"] |
7 | assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2 | 6 | assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2 |
@@ -333,7 +332,7 @@ class TestSql < Minitest::Test | @@ -333,7 +332,7 @@ class TestSql < Minitest::Test | ||
333 | def test_select | 332 | def test_select |
334 | store [{name: "Product A", store_id: 1}] | 333 | store [{name: "Product A", store_id: 1}] |
335 | result = Product.search("product", load: false, select: [:name, :store_id]).first | 334 | result = Product.search("product", load: false, select: [:name, :store_id]).first |
336 | - assert_equal %w[id name store_id], result.keys.reject { |k| k.start_with?("_") }.sort | 335 | + assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort |
337 | assert_equal ["Product A"], result.name # this is not great | 336 | assert_equal ["Product A"], result.name # this is not great |
338 | end | 337 | end |
339 | 338 | ||
@@ -363,5 +362,4 @@ class TestSql < Minitest::Test | @@ -363,5 +362,4 @@ class TestSql < Minitest::Test | ||
363 | assert Product.search("product", include: [:store]).first.association(:store).loaded? | 362 | assert Product.search("product", include: [:store]).first.association(:store).loaded? |
364 | end | 363 | end |
365 | end | 364 | end |
366 | - | ||
367 | end | 365 | end |
test/suggest_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestSuggest < Minitest::Test | ||
4 | - | 3 | +class SuggestTest < Minitest::Test |
5 | def test_basic | 4 | def test_basic |
6 | store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"] | 5 | store_names ["Great White Shark", "Hammerhead Shark", "Tiger Shark"] |
7 | assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [:name] | 6 | assert_suggest "How Big is a Tigre Shar", "how big is a tiger shark", fields: [:name] |
@@ -78,5 +77,4 @@ class TestSuggest < Minitest::Test | @@ -78,5 +77,4 @@ class TestSuggest < Minitest::Test | ||
78 | def assert_suggest_all(term, expected, options = {}) | 77 | def assert_suggest_all(term, expected, options = {}) |
79 | assert_equal expected.sort, Product.search(term, options.merge(suggest: true)).suggestions.sort | 78 | assert_equal expected.sort, Product.search(term, options.merge(suggest: true)).suggestions.sort |
80 | end | 79 | end |
81 | - | ||
82 | end | 80 | end |
test/synonyms_test.rb
1 | require_relative "test_helper" | 1 | require_relative "test_helper" |
2 | 2 | ||
3 | -class TestSynonyms < Minitest::Test | ||
4 | - | 3 | +class SynonymsTest < Minitest::Test |
5 | def test_bleach | 4 | def test_bleach |
6 | store_names ["Clorox Bleach", "Kroger Bleach"] | 5 | store_names ["Clorox Bleach", "Kroger Bleach"] |
7 | assert_search "clorox", ["Clorox Bleach", "Kroger Bleach"] | 6 | assert_search "clorox", ["Clorox Bleach", "Kroger Bleach"] |
@@ -46,5 +45,4 @@ class TestSynonyms < Minitest::Test | @@ -46,5 +45,4 @@ class TestSynonyms < Minitest::Test | ||
46 | # store_names ["Creature", "Beast", "Dragon"], Animal | 45 | # store_names ["Creature", "Beast", "Dragon"], Animal |
47 | # assert_search "animal", ["Creature", "Beast"], {}, Animal | 46 | # assert_search "animal", ["Creature", "Beast"], {}, Animal |
48 | # end | 47 | # end |
49 | - | ||
50 | end | 48 | end |
test/test_helper.rb
@@ -101,7 +101,7 @@ elsif defined?(NoBrainer) | @@ -101,7 +101,7 @@ elsif defined?(NoBrainer) | ||
101 | field :color, type: String | 101 | field :color, type: String |
102 | field :latitude | 102 | field :latitude |
103 | field :longitude | 103 | field :longitude |
104 | - field :description, type: String | 104 | + field :description, type: String |
105 | 105 | ||
106 | belongs_to :store, validates: false | 106 | belongs_to :store, validates: false |
107 | end | 107 | end |
@@ -230,10 +230,10 @@ class Store | @@ -230,10 +230,10 @@ class Store | ||
230 | mappings: { | 230 | mappings: { |
231 | store: { | 231 | store: { |
232 | properties: { | 232 | properties: { |
233 | - name: {type: "string", analyzer: "keyword"}, | 233 | + name: {type: "string", analyzer: "keyword"} |
234 | } | 234 | } |
235 | } | 235 | } |
236 | - } | 236 | + } |
237 | end | 237 | end |
238 | 238 | ||
239 | class Animal | 239 | class Animal |
@@ -252,7 +252,6 @@ Store.reindex | @@ -252,7 +252,6 @@ Store.reindex | ||
252 | Animal.reindex | 252 | Animal.reindex |
253 | 253 | ||
254 | class Minitest::Test | 254 | class Minitest::Test |
255 | - | ||
256 | def setup | 255 | def setup |
257 | Product.destroy_all | 256 | Product.destroy_all |
258 | Store.destroy_all | 257 | Store.destroy_all |
@@ -284,5 +283,4 @@ class Minitest::Test | @@ -284,5 +283,4 @@ class Minitest::Test | ||
284 | def assert_first(term, expected, options = {}, klass = Product) | 283 | def assert_first(term, expected, options = {}, klass = Product) |
285 | assert_equal expected, klass.search(term, options).map(&:name).first | 284 | assert_equal expected, klass.search(term, options).map(&:name).first |
286 | end | 285 | end |
287 | - | ||
288 | end | 286 | end |