Skip to content

Commit cf938ae

Browse files
committed
Fixed smart aggs not applying to _or
1 parent 919599c commit cf938ae

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- Added `per` method
44
- Fixed error with `aggs` method and non-hash arguments
5-
- Fixed smart aggs not applying to `_and` and `_not`
5+
- Fixed smart aggs not applying to `_and`, `_or`, and `_not`
66
- Fixed smart aggs not applying when multiple `where` calls
77

88
## 6.0.3 (2026-01-06)

lib/searchkick/query.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,9 @@ def smart_agg_filters(where, field, agg_where)
908908
agg_where_keys = agg_where.except(:_and, :_or, :_not, :_script).to_h { |k, v| [k.to_s, true] }
909909
where.each do |f, v|
910910
case f
911-
when :_and
911+
when :_and, :_or
912912
smart_where[f] = v.map { |v2| smart_agg_filters(v2, field, agg_where) }
913-
when :_or, :_script
914-
# TODO figure out how to handle
913+
when :_script
915914
smart_where[f] = v
916915
when :_not
917916
# TODO figure out agg_where overrides

test/aggs_test.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,15 @@ def test_smart_aggs
171171
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_and: [{store_id: 2}]}, aggs: [:store_id]
172172
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_and: [{store_id: 2}]}, aggs: [:store_id], smart_aggs: false
173173

174-
# TODO fix
175-
assert_aggs ({"store_id" => {2 => 2}}), where: {_or: [{store_id: 2}]}, aggs: [:store_id]
174+
assert_aggs ({"store_id" => {1 => 1}}), where: {_and: [{store_id: 2}, {in_stock: true}]}, aggs: [:store_id]
175+
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_and: [{store_id: 2}, {in_stock: true}]}, aggs: [:store_id], smart_aggs: false
176+
177+
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_or: [{store_id: 2}]}, aggs: [:store_id]
176178
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_or: [{store_id: 2}]}, aggs: [:store_id], smart_aggs: false
177179

180+
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_or: [{store_id: 2}, {in_stock: true}]}, aggs: [:store_id]
181+
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {_or: [{store_id: 2}, {in_stock: true}]}, aggs: [:store_id], smart_aggs: false
182+
178183
assert_aggs ({"store_id" => {1 => 1, 2 => 1}}), where: {store_id: 2, price: {gt: 5}}, aggs: [:store_id]
179184
assert_aggs ({"store_id" => {1 => 1, 2 => 2}}), where: {store_id: 2, price: {gt: 5}}, aggs: [:store_id], smart_aggs: false
180185

0 commit comments

Comments
 (0)