Commit 15cf7e15a9c5342881f44f1fe4cd479b7f7d7e12

Authored by Adam Engesath
1 parent 39209254

add support for min_doc_count in aggregations

@@ -18,3 +18,4 @@ tmp @@ -18,3 +18,4 @@ tmp
18 *.log 18 *.log
19 .DS_Store 19 .DS_Store
20 .ruby-* 20 .ruby-*
  21 +.idea/
@@ -624,6 +624,13 @@ Limit @@ -624,6 +624,13 @@ Limit
624 Product.search "apples", aggs: {store_id: {limit: 10}} 624 Product.search "apples", aggs: {store_id: {limit: 10}}
625 ``` 625 ```
626 626
  627 +Minimum Document Count
  628 +
  629 +```ruby
  630 +Product.search "apples", aggs: {store_id: {min_doc_count: 2}}
  631 +# Only return stores that have 2 or more hits
  632 +```
  633 +
627 Order 634 Order
628 635
629 ```ruby 636 ```ruby
lib/searchkick/query.rb
@@ -527,7 +527,7 @@ module Searchkick @@ -527,7 +527,7 @@ module Searchkick
527 527
528 aggs.each do |field, agg_options| 528 aggs.each do |field, agg_options|
529 size = agg_options[:limit] ? agg_options[:limit] : 1_000 529 size = agg_options[:limit] ? agg_options[:limit] : 1_000
530 - shared_agg_options = agg_options.slice(:order) 530 + shared_agg_options = agg_options.slice(:order, :min_doc_count)
531 531
532 if agg_options[:ranges] 532 if agg_options[:ranges]
533 payload[:aggs][field] = { 533 payload[:aggs][field] = {
test/aggs_test.rb
@@ -30,6 +30,10 @@ class AggsTest < Minitest::Test @@ -30,6 +30,10 @@ class AggsTest < Minitest::Test
30 assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new") 30 assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new")
31 end 31 end
32 32
  33 + def test_min_doc_count
  34 + assert_equal ({2 => 2}), store_agg(aggs: {store_id: { min_doc_count: 2 }})
  35 + end
  36 +
33 def test_no_aggs 37 def test_no_aggs
34 assert_nil Product.search("*").aggs 38 assert_nil Product.search("*").aggs
35 end 39 end