diff --git a/CHANGELOG.md b/CHANGELOG.md index 4559723..987dae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ - Added `below` option to misspellings to improve performance - Added `match` option -- Added `word: false` option +- Added `word` option - Added highlighted fields to `load: false` ## 1.0.3 diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index f0936fe..35e4c46 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -96,7 +96,8 @@ module Searchkick load: @load, includes: options[:include] || options[:includes], json: !options[:json].nil?, - match_suffix: @match_suffix + match_suffix: @match_suffix, + highlighted_fields: @highlighted_fields || [] } Searchkick::Results.new(searchkick_klass, response, opts) end @@ -544,6 +545,8 @@ module Searchkick end end end + + @highlighted_fields = payload[:highlight][:fields].keys.map { |k| k.sub(/\.(analyzed|word_start|word_middle|word_end|text_start|text_middle|text_end)\z/, "") } end # An empty array will cause only the _id and _type for each hit to be returned diff --git a/lib/searchkick/results.rb b/lib/searchkick/results.rb index 7d66f88..59f7f94 100644 --- a/lib/searchkick/results.rb +++ b/lib/searchkick/results.rb @@ -45,7 +45,7 @@ module Searchkick if hit["highlight"] 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] }] - result.keys.each do |k| + options[:highlighted_fields].each do |k| result["highlighted_#{k}"] ||= (highlight[k] || result[k]) end end -- libgit2 0.21.0