Skip to content

Commit

Permalink
Rename parameter from geopoint to geodistance
Browse files Browse the repository at this point in the history
  • Loading branch information
JPrevost committed Feb 5, 2024
1 parent 159986d commit 0c70302
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/models/opensearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,22 @@ 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: {
match_all: {}
},
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]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/models/opensearch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}')
Expand All @@ -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":'))
Expand Down

0 comments on commit 0c70302

Please sign in to comment.