Commit e270c44bfcf1a6d7329a06d88b6ee6efad51f7b8
Exists in
master
and in
21 other branches
Merge pull request #454 from meetrajesh/master
[Facets] Support overriding field in facet search
Showing
2 changed files
with
9 additions
and
3 deletions
Show diff stats
lib/searchkick/query.rb
test/facets_test.rb
... | ... | @@ -21,6 +21,12 @@ class TestFacets < Minitest::Test |
21 | 21 | assert_equal ({1 => 1}), store_facet(facets: {store_id: {where: {in_stock: true}}}) |
22 | 22 | end |
23 | 23 | |
24 | + def test_field | |
25 | + assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {}}) | |
26 | + assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {field: "store_id"}}) | |
27 | + assert_equal ({1 => 1, 2 => 2}), store_facet({facets: {store_id_new: {field: "store_id"}}}, "store_id_new") | |
28 | + end | |
29 | + | |
24 | 30 | def test_limit |
25 | 31 | facet = Product.search("Product", facets: {store_id: {limit: 1}}).facets["store_id"] |
26 | 32 | assert_equal 1, facet["terms"].size |
... | ... | @@ -78,8 +84,8 @@ class TestFacets < Minitest::Test |
78 | 84 | |
79 | 85 | protected |
80 | 86 | |
81 | - def store_facet(options) | |
82 | - Hash[Product.search("Product", options).facets["store_id"]["terms"].map { |v| [v["term"], v["count"]] }] | |
87 | + def store_facet(options, facet_key="store_id") | |
88 | + Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }] | |
83 | 89 | end |
84 | 90 | |
85 | 91 | end | ... | ... |