Commit f5c2552ca9a1b08bd2ae7094c0802803d94c327e

Authored by Andrew Kane
1 parent 32a8a2aa

DRY

lib/searchkick/query.rb
... ... @@ -546,7 +546,7 @@ module Searchkick
546 546 end
547 547 end
548 548  
549   - @highlighted_fields = payload[:highlight][:fields].keys.map { |k| k.sub(/\.(analyzed|word_start|word_middle|word_end|text_start|text_middle|text_end)\z/, "") }
  549 + @highlighted_fields = payload[:highlight][:fields].keys
550 550 end
551 551  
552 552 # An empty array will cause only the _id and _type for each hit to be returned
... ...
lib/searchkick/results.rb
... ... @@ -44,8 +44,8 @@ module Searchkick
44 44 end
45 45  
46 46 if hit["highlight"]
47   - highlight = Hash[hit["highlight"].map { |k, v| [k.sub(/\.(analyzed|word_start|word_middle|word_end|text_start|text_middle|text_end)\z/, ""), v.first] }]
48   - options[:highlighted_fields].each do |k|
  47 + highlight = Hash[hit["highlight"].map { |k, v| [base_field(k), v.first] }]
  48 + options[:highlighted_fields].map(&:base_field).each do |k|
49 49 result["highlighted_#{k}"] ||= (highlight[k] || result[k])
50 50 end
51 51 end
... ... @@ -197,5 +197,9 @@ module Searchkick
197 197 raise "Not sure how to load records"
198 198 end
199 199 end
  200 +
  201 + def base_field(k)
  202 + k.sub(/\.(analyzed|word_start|word_middle|word_end|text_start|text_middle|text_end)\z/, "")
  203 + end
200 204 end
201 205 end
... ...