@@ -279,6 +279,8 @@ class OpensearchTest < ActiveSupport::TestCase
279279 os . instance_variable_set ( :@params ,
280280 { geodistance : { latitude : '42.361145' , longitude : '-71.057083' , distance : '50mi' } } )
281281
282+ refute ( os . matches . to_json . include? ( '{"multi_match":{"query":' ) )
283+
282284 assert (
283285 os . query . to_json . include? ( '{"distance":"50mi","locations.geoshape":{"lat":"42.361145","lon":"-71.057083"}}' )
284286 )
@@ -296,4 +298,31 @@ class OpensearchTest < ActiveSupport::TestCase
296298 os . query . to_json . include? ( '{"distance":"50mi","locations.geoshape":{"lat":"42.361145","lon":"-71.057083"}}' )
297299 )
298300 end
301+
302+ test 'can search by bounding box' do
303+ os = Opensearch . new
304+ os . instance_variable_set ( :@params ,
305+ { geobox : { max_latitude : '42.886' , min_latitude : '41.239' ,
306+ max_longitude : '-73.928' , min_longitude : '-69.507' } } )
307+
308+ refute ( os . matches . to_json . include? ( '{"multi_match":{"query"' ) )
309+
310+ assert (
311+ os . query . to_json . include? ( '{"locations.geoshape":{"top":"42.886","bottom":"41.239","left":"-69.507","right":"-73.928"}}' )
312+ )
313+ end
314+
315+ test 'can search by bounding box and keyword' do
316+ os = Opensearch . new
317+ os . instance_variable_set ( :@params ,
318+ { geobox : { max_latitude : '42.886' , min_latitude : '41.239' ,
319+ max_longitude : '-73.928' , min_longitude : '-69.507' } ,
320+ q : 'rail stations' } )
321+
322+ assert ( os . matches . to_json . include? ( '{"multi_match":{"query":"rail stations","fields":' ) )
323+
324+ assert (
325+ os . query . to_json . include? ( '{"locations.geoshape":{"top":"42.886","bottom":"41.239","left":"-69.507","right":"-73.928"}}' )
326+ )
327+ end
299328end
0 commit comments