diff --git a/lib/searchkick/relation.rb b/lib/searchkick/relation.rb index af54b41..d5a8b33 100644 --- a/lib/searchkick/relation.rb +++ b/lib/searchkick/relation.rb @@ -354,6 +354,15 @@ module Searchkick self end + def smart_aggs(value) + spawn.smart_aggs!(value) + end + + def smart_aggs!(value) + options[:smart_aggs] = value + self + end + # same as Active Record def inspect entries = results.first(11).map!(&:inspect) diff --git a/test/aggs_test.rb b/test/aggs_test.rb index 6782138..87f1f2c 100644 --- a/test/aggs_test.rb +++ b/test/aggs_test.rb @@ -110,6 +110,7 @@ class AggsTest < Minitest::Test def test_smart_aggs_false assert_equal ({2 => 2}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false) assert_equal ({2 => 2}), store_agg(where: {color: "blue"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false) + 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"]) end def test_aggs_group_by_date -- libgit2 0.21.0