diff --git a/app/models/opensearch.rb b/app/models/opensearch.rb index cf334ed..e533f79 100644 --- a/app/models/opensearch.rb +++ b/app/models/opensearch.rb @@ -110,11 +110,11 @@ def matches match_single_field_nested(:locations, m) match_single_field_nested(:subjects, m) - match_geopoint(m) if @params[:geopoint].present? + match_geodistance(m) if @params[:geodistance].present? m end - def match_geopoint(match_array) + def match_geodistance(match_array) match_array << { bool: { must: { @@ -122,10 +122,10 @@ def match_geopoint(match_array) }, filter: { geo_distance: { - distance: @params[:geopoint][:distance], + distance: @params[:geodistance][:distance], 'locations.geoshape': { - lat: @params[:geopoint][:latitude], - lon: @params[:geopoint][:longitude] + lat: @params[:geodistance][:latitude], + lon: @params[:geodistance][:longitude] } } } diff --git a/test/models/opensearch_test.rb b/test/models/opensearch_test.rb index 15d0e5b..39d1870 100644 --- a/test/models/opensearch_test.rb +++ b/test/models/opensearch_test.rb @@ -277,7 +277,7 @@ class OpensearchTest < ActiveSupport::TestCase test 'can search by geopoint' do os = Opensearch.new os.instance_variable_set(:@params, - { geopoint: { latitude: '42.361145', longitude: '-71.057083', distance: '50mi' } }) + { geodistance: { latitude: '42.361145', longitude: '-71.057083', distance: '50mi' } }) assert( os.query.to_json.include?('{"distance":"50mi","locations.geoshape":{"lat":"42.361145","lon":"-71.057083"}}') @@ -287,7 +287,7 @@ class OpensearchTest < ActiveSupport::TestCase test 'can search for combination of geopoint and keyword' do os = Opensearch.new os.instance_variable_set(:@params, - { geopoint: { latitude: '42.361145', longitude: '-71.057083', distance: '50mi' }, + { geodistance: { latitude: '42.361145', longitude: '-71.057083', distance: '50mi' }, q: 'rail stations' }) assert(os.matches.to_json.include?('{"multi_match":{"query":"rail stations","fields":'))