Commit 61cc090fdccee0370e7e3a8208f417be3e0175b0
1 parent
cf44c6d5
Exists in
relation
and in
1 other branch
Added smart_aggs [skip ci]
Showing
2 changed files
with
10 additions
and
0 deletions
Show diff stats
lib/searchkick/relation.rb
... | ... | @@ -354,6 +354,15 @@ module Searchkick |
354 | 354 | self |
355 | 355 | end |
356 | 356 | |
357 | + def smart_aggs(value) | |
358 | + spawn.smart_aggs!(value) | |
359 | + end | |
360 | + | |
361 | + def smart_aggs!(value) | |
362 | + options[:smart_aggs] = value | |
363 | + self | |
364 | + end | |
365 | + | |
357 | 366 | # same as Active Record |
358 | 367 | def inspect |
359 | 368 | entries = results.first(11).map!(&:inspect) | ... | ... |
test/aggs_test.rb
... | ... | @@ -110,6 +110,7 @@ class AggsTest < Minitest::Test |
110 | 110 | def test_smart_aggs_false |
111 | 111 | assert_equal ({2 => 2}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false) |
112 | 112 | assert_equal ({2 => 2}), store_agg(where: {color: "blue"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false) |
113 | + assert_equal ({2 => 2}), buckets_as_hash(Product.search("Product", relation: true).where(color: "red").aggs(store_id: {where: {in_stock: false}}).smart_aggs(false).aggs["store_id"]) | |
113 | 114 | end |
114 | 115 | |
115 | 116 | def test_aggs_group_by_date | ... | ... |