Commit b2472aeaaae804d11037a5378150f1e283329b1e
1 parent
5d89f271
Exists in
master
and in
21 other branches
Easier conversions
Showing
3 changed files
with
7 additions
and
3 deletions
Show diff stats
README.md
... | ... | @@ -168,7 +168,7 @@ class Product < ActiveRecord::Base |
168 | 168 | def _source |
169 | 169 | { |
170 | 170 | name: name, |
171 | - conversions: searches.group("query").count.map{|query, count| {query: query, count: count} } | |
171 | + conversions: searches.group("query").count | |
172 | 172 | } |
173 | 173 | end |
174 | 174 | end | ... | ... |
lib/searchkick/model.rb
... | ... | @@ -19,7 +19,11 @@ module Searchkick |
19 | 19 | end |
20 | 20 | |
21 | 21 | def to_indexed_json |
22 | - _source.to_json | |
22 | + source = _source | |
23 | + if self.class.instance_variable_get("@searchkick_options")[:conversions] and source[:conversions] | |
24 | + source[:conversions] = source[:conversions].map{|k, v| {query: k, count: v} } | |
25 | + end | |
26 | + source.to_json | |
23 | 27 | end |
24 | 28 | end |
25 | 29 | end | ... | ... |
test/searchkick_test.rb
... | ... | @@ -18,7 +18,7 @@ class Product < ActiveRecord::Base |
18 | 18 | conversions: true |
19 | 19 | |
20 | 20 | def _source |
21 | - as_json.merge(conversions: searches.group("query").count.map{|query, count| {query: query, count: count} }) | |
21 | + as_json.merge(conversions: searches.group("query").count) | |
22 | 22 | end |
23 | 23 | end |
24 | 24 | ... | ... |