Skip to content

Commit

Permalink
Vebt 885 - update gibct institutions controller to handle combined na…
Browse files Browse the repository at this point in the history
…me and location searches (#1272)

* add name and location combined search

* fix comments

* fix comments

* fix comments

* remove unneeded location code

* remove unneeded tests

* update for backward compatability for non CT pages calling controller

* clean up code, remove recent index changes

* clean up comments
  • Loading branch information
GcioGregg authored Dec 23, 2024
1 parent 4c1143e commit 6f29037
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/controllers/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ def index
def location
@query ||= normalized_query_params

location_results = Institution.approved_institutions(@version).location_search(@query).filter_result_v1(@query)
results = location_results.location_select(@query).location_order
# Start with location-based search
location_results = Institution.approved_institutions(@version)
.location_search(@query)
.filter_result_v1(@query)

# Add name search if name parameter is present
location_results = location_results.search_v1(name: @query[:name]) if @query[:name].present?

results = location_results.location_select(@query).location_order
results = results.filter_high_school if @query[:excluded_school_types]&.include?('HIGH SCHOOL')

@meta = {
Expand Down Expand Up @@ -125,7 +131,7 @@ def normalized_query_params
end
%i[name category student_veteran_group yellow_ribbon_scholarship principles_of_excellence
eight_keys_to_veteran_success stem_offered independent_study priority_enrollment
online_only distance_learning location].each do |k|
online_only distance_learning].each do |k|
query[k].try(:downcase!)
end
%i[latitude longitude distance].each do |k|
Expand Down
49 changes: 49 additions & 0 deletions spec/controllers/v1/institutions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,55 @@ def check_boolean_facets(facets)
expect(response.media_type).to eq('application/json')
expect(response).to match_response_schema('institution_search_results')
end

# tests for coordinate-based name+location search
it 'returns filtered results when searching by both name and coordinates' do
create(:institution, :production_version, :location, institution: 'HARVARD UNIVERSITY')
create(:institution, :production_version, :location, institution: 'BOSTON UNIVERSITY')

get(:location, params: {
latitude: '32.7876',
longitude: '-79.9403',
distance: '50',
name: 'harvard'
})

results = JSON.parse(response.body)['data']
expect(results.count).to eq(1)
expect(results[0]['attributes']['name']).to eq('HARVARD UNIVERSITY')
expect(response).to match_response_schema('institution_search_results')
end

it 'returns no results when name does not match within location radius' do
create(:institution, :production_version, :location, institution: 'HARVARD UNIVERSITY')

get(:location, params: {
latitude: '32.7876',
longitude: '-79.9403',
distance: '50',
name: 'stanford'
})

expect(JSON.parse(response.body)['data'].count).to eq(0)
expect(response).to match_response_schema('institution_search_results')
end

it 'maintains accurate count in meta for coordinate and name search' do
create_list(:institution, 3, :production_version, :location)
create(:institution, :production_version, :location, institution: 'HARVARD UNIVERSITY')

get(:location, params: {
latitude: '32.7876',
longitude: '-79.9403',
distance: '50',
name: 'harvard'
})

body = JSON.parse(response.body)
expect(body['data'].count).to eq(1)
expect(body['meta']['count']).to eq(1)
expect(response).to match_response_schema('institution_search_results')
end
end

context 'with compare results' do
Expand Down

0 comments on commit 6f29037

Please sign in to comment.