Commit d7fb6d75207257167d575c7329d0fd82d1119b0e
1 parent
21b5a4e6
Exists in
master
and in
2 other branches
Switched to to_h where possible [skip ci]
Showing
5 changed files
with
12 additions
and
13 deletions
Show diff stats
lib/searchkick/index.rb
... | ... | @@ -100,7 +100,7 @@ module Searchkick |
100 | 100 | record_data = RecordData.new(self, record).record_data |
101 | 101 | |
102 | 102 | # remove underscore |
103 | - get_options = Hash[record_data.map { |k, v| [k.to_s.sub(/\A_/, "").to_sym, v] }] | |
103 | + get_options = record_data.to_h { |k, v| [k.to_s.sub(/\A_/, "").to_sym, v] } | |
104 | 104 | |
105 | 105 | client.get(get_options)["_source"] |
106 | 106 | end | ... | ... |
lib/searchkick/index_options.rb
... | ... | @@ -357,10 +357,9 @@ module Searchkick |
357 | 357 | } |
358 | 358 | end |
359 | 359 | |
360 | - mapping_options = Hash[ | |
360 | + mapping_options = | |
361 | 361 | [:suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight, :searchable, :filterable] |
362 | - .map { |type| [type, (options[type] || []).map(&:to_s)] } | |
363 | - ] | |
362 | + .to_h { |type| [type, (options[type] || []).map(&:to_s)] } | |
364 | 363 | |
365 | 364 | word = options[:word] != false && (!options[:match] || options[:match] == :word) |
366 | 365 | ... | ... |
lib/searchkick/query.rb
... | ... | @@ -692,9 +692,9 @@ module Searchkick |
692 | 692 | def set_boost_by(multiply_filters, custom_filters) |
693 | 693 | boost_by = options[:boost_by] || {} |
694 | 694 | if boost_by.is_a?(Array) |
695 | - boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }] | |
695 | + boost_by = boost_by.to_h { |f| [f, {factor: 1}] } | |
696 | 696 | elsif boost_by.is_a?(Hash) |
697 | - multiply_by, boost_by = boost_by.partition { |_, v| v.delete(:boost_mode) == "multiply" }.map { |i| Hash[i] } | |
697 | + multiply_by, boost_by = boost_by.partition { |_, v| v.delete(:boost_mode) == "multiply" }.map(&:to_h) | |
698 | 698 | end |
699 | 699 | boost_by[options[:boost]] = {factor: 1} if options[:boost] |
700 | 700 | |
... | ... | @@ -759,7 +759,7 @@ module Searchkick |
759 | 759 | |
760 | 760 | def set_highlights(payload, fields) |
761 | 761 | payload[:highlight] = { |
762 | - fields: Hash[fields.map { |f| [f, {}] }], | |
762 | + fields: fields.to_h { |f| [f, {}] }, | |
763 | 763 | fragment_size: 0 |
764 | 764 | } |
765 | 765 | |
... | ... | @@ -793,7 +793,7 @@ module Searchkick |
793 | 793 | aggs = options[:aggs] |
794 | 794 | payload[:aggs] = {} |
795 | 795 | |
796 | - aggs = Hash[aggs.map { |f| [f, {}] }] if aggs.is_a?(Array) # convert to more advanced syntax | |
796 | + aggs = aggs.to_h { |f| [f, {}] } if aggs.is_a?(Array) # convert to more advanced syntax | |
797 | 797 | aggs.each do |field, agg_options| |
798 | 798 | size = agg_options[:limit] ? agg_options[:limit] : 1_000 |
799 | 799 | shared_agg_options = agg_options.except(:limit, :field, :ranges, :date_ranges, :where) | ... | ... |
lib/searchkick/results.rb
... | ... | @@ -284,7 +284,7 @@ module Searchkick |
284 | 284 | end |
285 | 285 | |
286 | 286 | if hit["highlight"] || options[:highlight] |
287 | - highlight = Hash[hit["highlight"].to_a.map { |k, v| [base_field(k), v.first] }] | |
287 | + highlight = hit["highlight"].to_a.to_h { |k, v| [base_field(k), v.first] } | |
288 | 288 | options[:highlighted_fields].map { |k| base_field(k) }.each do |k| |
289 | 289 | result["highlighted_#{k}"] ||= (highlight[k] || result[k]) |
290 | 290 | end |
... | ... | @@ -341,7 +341,7 @@ module Searchkick |
341 | 341 | |
342 | 342 | def hit_highlights(hit, multiple: false) |
343 | 343 | if hit["highlight"] |
344 | - Hash[hit["highlight"].map { |k, v| [(options[:json] ? k : k.sub(/\.#{@options[:match_suffix]}\z/, "")).to_sym, multiple ? v : v.first] }] | |
344 | + hit["highlight"].to_h { |k, v| [(options[:json] ? k : k.sub(/\.#{@options[:match_suffix]}\z/, "")).to_sym, multiple ? v : v.first] } | |
345 | 345 | else |
346 | 346 | {} |
347 | 347 | end | ... | ... |
test/aggs_test.rb
... | ... | @@ -250,7 +250,7 @@ class AggsTest < Minitest::Test |
250 | 250 | end |
251 | 251 | |
252 | 252 | def buckets_as_hash(agg) |
253 | - Hash[agg["buckets"].map { |v| [v["key"], v["doc_count"]] }] | |
253 | + agg["buckets"].to_h { |v| [v["key"], v["doc_count"]] } | |
254 | 254 | end |
255 | 255 | |
256 | 256 | def store_agg(options, agg_key = "store_id") |
... | ... | @@ -259,9 +259,9 @@ class AggsTest < Minitest::Test |
259 | 259 | end |
260 | 260 | |
261 | 261 | def store_multiple_aggs(options) |
262 | - Hash[Product.search("Product", **options).aggs.map do |field, filtered_agg| | |
262 | + Product.search("Product", **options).aggs.to_h do |field, filtered_agg| | |
263 | 263 | [field, buckets_as_hash(filtered_agg)] |
264 | - end] | |
264 | + end | |
265 | 265 | end |
266 | 266 | |
267 | 267 | def interval_key | ... | ... |