Commit 61cc090fdccee0370e7e3a8208f417be3e0175b0

Authored by Andrew Kane
1 parent cf44c6d5

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,6 +354,15 @@ module Searchkick
354 self 354 self
355 end 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 # same as Active Record 366 # same as Active Record
358 def inspect 367 def inspect
359 entries = results.first(11).map!(&:inspect) 368 entries = results.first(11).map!(&:inspect)
test/aggs_test.rb
@@ -110,6 +110,7 @@ class AggsTest < Minitest::Test @@ -110,6 +110,7 @@ class AggsTest < Minitest::Test
110 def test_smart_aggs_false 110 def test_smart_aggs_false
111 assert_equal ({2 => 2}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false) 111 assert_equal ({2 => 2}), store_agg(where: {color: "red"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false)
112 assert_equal ({2 => 2}), store_agg(where: {color: "blue"}, aggs: {store_id: {where: {in_stock: false}}}, smart_aggs: false) 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 end 114 end
114 115
115 def test_aggs_group_by_date 116 def test_aggs_group_by_date