Commit 6916ac83037f3743132c583619c03b681ef3cbab

Authored by Eric Harrison
Committed by Andrew Kane
1 parent 8fc9d462

Added in top_right and bottom_left for posterity (#1064)

@@ -900,6 +900,10 @@ Bounded by a box @@ -900,6 +900,10 @@ Bounded by a box
900 ```ruby 900 ```ruby
901 Restaurant.search "sushi", where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}} 901 Restaurant.search "sushi", where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}}
902 ``` 902 ```
  903 +OR
  904 +```ruby
  905 +Restaurant.search "sushi", where: {location: {top_right: {lat: 38, lon: -122}, bottom_left: {lat: 37, lon: -123}}}
  906 +```
903 907
904 Bounded by a polygon 908 Bounded by a polygon
905 909
lib/searchkick/query.rb
@@ -770,7 +770,7 @@ module Searchkick @@ -770,7 +770,7 @@ module Searchkick
770 if value.is_a?(Hash) 770 if value.is_a?(Hash)
771 value.each do |op, op_value| 771 value.each do |op, op_value|
772 case op 772 case op
773 - when :within, :bottom_right 773 + when :within, :bottom_right, :bottom_left
774 # do nothing 774 # do nothing
775 when :near 775 when :near
776 filters << { 776 filters << {
@@ -805,6 +805,15 @@ module Searchkick @@ -805,6 +805,15 @@ module Searchkick
805 } 805 }
806 } 806 }
807 } 807 }
  808 + when :top_right
  809 + filters << {
  810 + geo_bounding_box: {
  811 + field => {
  812 + top_right: location_value(op_value),
  813 + bottom_left: location_value(value[:bottom_left])
  814 + }
  815 + }
  816 + }
808 when :regexp # support for regexp queries without using a regexp ruby object 817 when :regexp # support for regexp queries without using a regexp ruby object
809 filters << {regexp: {field => {value: op_value}}} 818 filters << {regexp: {field => {value: op_value}}}
810 when :not # not equal 819 when :not # not equal
test/where_test.rb
@@ -189,6 +189,22 @@ class WhereTest &lt; Minitest::Test @@ -189,6 +189,22 @@ class WhereTest &lt; Minitest::Test
189 assert_search "san", ["San Francisco"], where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}} 189 assert_search "san", ["San Francisco"], where: {location: {top_left: {lat: 38, lon: -123}, bottom_right: {lat: 37, lon: -122}}}
190 end 190 end
191 191
  192 + def test_top_right_bottom_left
  193 + store [
  194 + {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
  195 + {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
  196 + ]
  197 + assert_search "san", ["San Francisco"], where: {location: {top_right: [38, -122], bottom_left: [37, -123]}}
  198 + end
  199 +
  200 + def test_top_right_bottom_left_hash
  201 + store [
  202 + {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
  203 + {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
  204 + ]
  205 + assert_search "san", ["San Francisco"], where: {location: {top_right: {lat: 38, lon: -122}, bottom_left: {lat: 37, lon: -123}}}
  206 + end
  207 +
192 def test_multiple_locations 208 def test_multiple_locations
193 store [ 209 store [
194 {name: "San Francisco", latitude: 37.7833, longitude: -122.4167}, 210 {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},