Class: OvertureMaps::SearchController

Inherits:
ApplicationController show all
Defined in:
app/controllers/overture_maps/search_controller.rb

Overview

Division geocoding: GET /overture/search?q=Seattle Resolves from the local overture_divisions table when populated, falling back to Overture's bucket.

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/overture_maps/search_controller.rb', line 8

def index
  query = params[:q].to_s.strip
  return render json: { error: "q is required" }, status: :unprocessable_entity if query.empty?

  results = DivisionSearch.search(query: query)
  render json: {
    data: results.map do |result|
      {
        id: result[:id],
        name: result[:name],
        subtype: result[:subtype],
        country: result[:country],
        region: result[:region],
        area_km2: result[:area_km2],
        bbox: [result[:bbox].min_lng, result[:bbox].min_lat,
               result[:bbox].max_lng, result[:bbox].max_lat]
      }
    end
  }
rescue OvertureMaps::Error => e
  render json: { error: e.message }, status: :bad_gateway
end