Commit 579b09088fe89c92901d6144f801f2c8edbf0564
1 parent
709641ef
Exists in
master
and in
21 other branches
Fixed with_details for json option
Showing
3 changed files
with
4 additions
and
3 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -396,7 +396,8 @@ module Searchkick |
396 | 396 | per_page: @per_page, |
397 | 397 | padding: @padding, |
398 | 398 | load: @load, |
399 | - includes: options[:include] || options[:includes] | |
399 | + includes: options[:include] || options[:includes], | |
400 | + json: !options[:json].nil? | |
400 | 401 | } |
401 | 402 | Searchkick::Results.new(searchkick_klass, response, opts) |
402 | 403 | end | ... | ... |
lib/searchkick/results.rb
... | ... | @@ -67,7 +67,7 @@ module Searchkick |
67 | 67 | each_with_hit.map do |model, hit| |
68 | 68 | details = {} |
69 | 69 | if hit["highlight"] |
70 | - details[:highlight] = Hash[ hit["highlight"].map{|k, v| [k.sub(/\.analyzed\z/, "").to_sym, v.first] } ] | |
70 | + details[:highlight] = Hash[ hit["highlight"].map{|k, v| [options[:json] ? k : k.sub(/\.analyzed\z/, "").to_sym, v.first] } ] | |
71 | 71 | end |
72 | 72 | [model, details] |
73 | 73 | end | ... | ... |
test/highlight_test.rb
... | ... | @@ -35,7 +35,7 @@ class TestHighlight < Minitest::Unit::TestCase |
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
38 | - assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(json: json).response["hits"]["hits"].first["highlight"]["name.analyzed"].first | |
38 | + assert_equal "Two Door <strong>Cinema</strong> Club", Product.search(json: json).with_details.first[1][:highlight]["name.analyzed"] | |
39 | 39 | end |
40 | 40 | |
41 | 41 | end | ... | ... |