diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index e400e8c..9329eac 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -100,7 +100,7 @@ module Searchkick record_data = RecordData.new(self, record).record_data # remove underscore - get_options = Hash[record_data.map { |k, v| [k.to_s.sub(/\A_/, "").to_sym, v] }] + get_options = record_data.to_h { |k, v| [k.to_s.sub(/\A_/, "").to_sym, v] } client.get(get_options)["_source"] end diff --git a/lib/searchkick/index_options.rb b/lib/searchkick/index_options.rb index 2153c2a..d81ae87 100644 --- a/lib/searchkick/index_options.rb +++ b/lib/searchkick/index_options.rb @@ -357,10 +357,9 @@ module Searchkick } end - mapping_options = Hash[ + mapping_options = [:suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight, :searchable, :filterable] - .map { |type| [type, (options[type] || []).map(&:to_s)] } - ] + .to_h { |type| [type, (options[type] || []).map(&:to_s)] } word = options[:word] != false && (!options[:match] || options[:match] == :word) diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 6945b1e..d993078 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -692,9 +692,9 @@ module Searchkick def set_boost_by(multiply_filters, custom_filters) boost_by = options[:boost_by] || {} if boost_by.is_a?(Array) - boost_by = Hash[boost_by.map { |f| [f, {factor: 1}] }] + boost_by = boost_by.to_h { |f| [f, {factor: 1}] } elsif boost_by.is_a?(Hash) - multiply_by, boost_by = boost_by.partition { |_, v| v.delete(:boost_mode) == "multiply" }.map { |i| Hash[i] } + multiply_by, boost_by = boost_by.partition { |_, v| v.delete(:boost_mode) == "multiply" }.map(&:to_h) end boost_by[options[:boost]] = {factor: 1} if options[:boost] @@ -759,7 +759,7 @@ module Searchkick def set_highlights(payload, fields) payload[:highlight] = { - fields: Hash[fields.map { |f| [f, {}] }], + fields: fields.to_h { |f| [f, {}] }, fragment_size: 0 } @@ -793,7 +793,7 @@ module Searchkick aggs = options[:aggs] payload[:aggs] = {} - aggs = Hash[aggs.map { |f| [f, {}] }] if aggs.is_a?(Array) # convert to more advanced syntax + aggs = aggs.to_h { |f| [f, {}] } if aggs.is_a?(Array) # convert to more advanced syntax aggs.each do |field, agg_options| size = agg_options[:limit] ? agg_options[:limit] : 1_000 shared_agg_options = agg_options.except(:limit, :field, :ranges, :date_ranges, :where) diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 7b76225..443b581 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -284,7 +284,7 @@ module Searchkick end if hit["highlight"] || options[:highlight] - highlight = Hash[hit["highlight"].to_a.map { |k, v| [base_field(k), v.first] }] + highlight = hit["highlight"].to_a.to_h { |k, v| [base_field(k), v.first] } options[:highlighted_fields].map { |k| base_field(k) }.each do |k| result["highlighted_#{k}"] ||= (highlight[k] || result[k]) end @@ -341,7 +341,7 @@ module Searchkick def hit_highlights(hit, multiple: false) if hit["highlight"] - Hash[hit["highlight"].map { |k, v| [(options[:json] ? k : k.sub(/\.#{@options[:match_suffix]}\z/, "")).to_sym, multiple ? v : v.first] }] + hit["highlight"].to_h { |k, v| [(options[:json] ? k : k.sub(/\.#{@options[:match_suffix]}\z/, "")).to_sym, multiple ? v : v.first] } else {} end diff --git a/test/aggs_test.rb b/test/aggs_test.rb index fb0ef3f..ebdbf14 100644 --- a/test/aggs_test.rb +++ b/test/aggs_test.rb @@ -250,7 +250,7 @@ class AggsTest < Minitest::Test end def buckets_as_hash(agg) - Hash[agg["buckets"].map { |v| [v["key"], v["doc_count"]] }] + agg["buckets"].to_h { |v| [v["key"], v["doc_count"]] } end def store_agg(options, agg_key = "store_id") @@ -259,9 +259,9 @@ class AggsTest < Minitest::Test end def store_multiple_aggs(options) - Hash[Product.search("Product", **options).aggs.map do |field, filtered_agg| + Product.search("Product", **options).aggs.to_h do |field, filtered_agg| [field, buckets_as_hash(filtered_agg)] - end] + end end def interval_key -- libgit2 0.21.0