Merge branch 'setop/mobilizon-fix-addok'

This commit is contained in:
Thomas Citharel 2020-06-30 09:16:55 +02:00
commit f4137eb2e3
5 changed files with 48 additions and 25 deletions

View File

@ -54,7 +54,7 @@ config :mobilizon, Mobilizon.Service.Geospatial.Nominatim,
### Addok
[Addok](https://github.com/addok/addok) is a WTFPL licenced search engine for address (and only address). It's written in Python and uses Redis.
[Addok](https://github.com/addok/addok) is a MIT licenced search engine for address (and only address). It's written in Python and uses Redis.
It's used by French government for [adresse.data.gouv.fr](https://adresse.data.gouv.fr).
!!! warning "Terms"
@ -66,6 +66,18 @@ config :mobilizon, Mobilizon.Service.Geospatial.Addok,
endpoint: "https://api-adresse.data.gouv.fr"
```
The default endpoint is limited to France. Geo coding outside of France will return an empty result. Moreover, as France is implicit for this endpoint, country is not part of the result.
To conform to `Provider` interface, this provider return "France" as the country.
If plugged to another endpoint, in another country, it could be useful to change the default country. This can be done in `prod.secret.exs`:
** change endpoint default country **
```elixir
config :mobilizon, Mobilizon.Service.Geospatial.Addok,
endpoint: "https://another-endpoint.tld"
default_country: "Country"
```
### Photon
[Photon](https://photon.komoot.de/) is an Apache 2.0 licenced search engine written in Java and powered by ElasticSearch.

View File

@ -12,6 +12,8 @@ defmodule Mobilizon.Service.Geospatial.Addok do
@behaviour Provider
@endpoint Application.get_env(:mobilizon, __MODULE__) |> get_in([:endpoint])
@default_country Application.get_env(:mobilizon, __MODULE__) |> get_in([:default_country]) ||
"France"
@http_options [
follow_redirect: true,
@ -79,9 +81,9 @@ defmodule Mobilizon.Service.Geospatial.Addok do
features
|> Enum.map(fn %{"geometry" => geometry, "properties" => properties} ->
%Address{
country: Map.get(properties, "country"),
country: Map.get(properties, "country", @default_country),
locality: Map.get(properties, "city"),
region: Map.get(properties, "state"),
region: Map.get(properties, "context"),
description: Map.get(properties, "name") || street_address(properties),
geom: geometry |> Map.get("coordinates") |> Provider.coordinates(),
postal_code: Map.get(properties, "postcode"),

View File

@ -2,7 +2,10 @@
{
"request": {
"body": "",
"headers": [],
"headers": {
"Accept": "*/*",
"Accept-Encoding":"deflate, gzip"
},
"method": "get",
"options": [],
"request_body": "",
@ -10,16 +13,16 @@
},
"response": {
"binary": false,
"body": "{\"limit\": 1, \"features\": [{\"geometry\": {\"coordinates\": [4.842569, 45.751718], \"type\": \"Point\"}, \"properties\": {\"y\": 6518613.6, \"city\": \"Lyon\", \"label\": \"10 Rue Jangot 69007 Lyon\", \"score\": 1.0, \"distance\": 0, \"type\": \"housenumber\", \"street\": \"Rue Jangot\", \"name\": \"10 Rue Jangot\", \"x\": 843191.7, \"id\": \"69387_3650_f5ec2a\", \"housenumber\": \"10\", \"citycode\": \"69387\", \"context\": \"69, Rh\\u00f4ne, Auvergne-Rh\\u00f4ne-Alpes (Rh\\u00f4ne-Alpes)\", \"postcode\": \"69007\", \"importance\": 0.3164}, \"type\": \"Feature\"}], \"attribution\": \"BAN\", \"version\": \"draft\", \"type\": \"FeatureCollection\", \"licence\": \"ODbL 1.0\"}",
"body": "{\"type\": \"FeatureCollection\", \"version\": \"draft\", \"features\": [{\"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [4.842569, 45.751718]}, \"properties\": {\"label\": \"10 Rue Jangot 69007 Lyon\", \"score\": 0.9999999999926557, \"housenumber\": \"10\", \"id\": \"69387_3650_00010\", \"type\": \"housenumber\", \"x\": 843232.29, \"y\": 6518573.31, \"importance\": 0.5454797306366062, \"name\": \"10 Rue Jangot\", \"postcode\": \"69007\", \"citycode\": \"69387\", \"city\": \"Lyon\", \"district\": \"Lyon 7e Arrondissement\", \"context\": \"69, Rh\u00f4ne, Auvergne-Rh\u00f4ne-Alpes\", \"street\": \"Rue Jangot\", \"distance\": 0}}], \"attribution\": \"BAN\", \"licence\": \"ETALAB-2.0\", \"limit\": 1}",
"headers": {
"Server": "nginx/1.13.4",
"Date": "Wed, 13 Mar 2019 17:22:17 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "598",
"Connection": "keep-alive",
"X-Cache-Status": "MISS",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "X-Requested-With"
"Server": "nginx/1.9.3",
"Date": "Thu, 14 Mar 2019 10:46:45 GMT",
"Content-type":"application/json; charset=utf-8",
"Vary":"Accept-Encoding",
"X-cache-status":"MISS",
"Access-control-allow-origin":"*",
"Access-control-allow-headers":"X-Requested-With,Content-Type",
"Content-encoding":"gzip"
},
"status_code": 200,
"type": "ok"

View File

@ -2,25 +2,27 @@
{
"request": {
"body": "",
"headers": [],
"headers": {
"Accept": "*/*",
"Accept-Encoding":"deflate, gzip"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://api-adresse.data.gouv.fr/search/?q=10%20rue%20Jangot&limit=10"
"url": "https://api-adresse.data.gouv.fr/search/?q=10%20Rue%20Jangot"
},
"response": {
"binary": false,
"body": "{\"limit\": 10, \"features\": [{\"geometry\": {\"coordinates\": [4.842569, 45.751718], \"type\": \"Point\"}, \"properties\": {\"y\": 6518573.3, \"city\": \"Lyon\", \"label\": \"10 Rue Jangot 69007 Lyon\", \"score\": 0.8469454545454544, \"type\": \"housenumber\", \"street\": \"Rue Jangot\", \"name\": \"10 Rue Jangot\", \"x\": 843232.2, \"id\": \"ADRNIVX_0000000260022046\", \"housenumber\": \"10\", \"citycode\": \"69387\", \"context\": \"69, Rh\\u00f4ne, Auvergne-Rh\\u00f4ne-Alpes (Rh\\u00f4ne-Alpes)\", \"postcode\": \"69007\", \"importance\": 0.3164}, \"type\": \"Feature\"}, {\"geometry\": {\"coordinates\": [2.440118, 50.371066], \"type\": \"Point\"}, \"properties\": {\"y\": 7030518.3, \"city\": \"Bailleul-aux-Cornailles\", \"label\": \"Rue Jangon 62127 Bailleul-aux-Cornailles\", \"score\": 0.5039055944055943, \"name\": \"Rue Jangon\", \"x\": 660114.7, \"id\": \"62070_0100_9b8d3c\", \"type\": \"street\", \"citycode\": \"62070\", \"context\": \"62, Pas-de-Calais, Hauts-de-France (Nord-Pas-de-Calais)\", \"postcode\": \"62127\", \"importance\": 0.0045}, \"type\": \"Feature\"}], \"attribution\": \"BAN\", \"version\": \"draft\", \"type\": \"FeatureCollection\", \"licence\": \"ODbL 1.0\", \"query\": \"10 rue Jangot\"}",
"body": "{\"type\": \"FeatureCollection\", \"version\": \"draft\", \"features\": [{\"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [4.842569, 45.751718]}, \"properties\": {\"label\": \"10 Rue Jangot 69007 Lyon\", \"score\": 0.8677708846033279, \"housenumber\": \"10\", \"id\": \"69387_3650_00010\", \"type\": \"housenumber\", \"x\": 843232.29, \"y\": 6518573.31, \"importance\": 0.5454797306366062, \"name\": \"10 Rue Jangot\", \"postcode\": \"69007\", \"citycode\": \"69387\", \"city\": \"Lyon\", \"district\": \"Lyon 7e Arrondissement\", \"context\": \"69, Rh\u00f4ne, Auvergne-Rh\u00f4ne-Alpes\", \"street\": \"Rue Jangot\"}}, {\"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [2.440319, 50.371266]}, \"properties\": {\"label\": \"Rue Jangon 62127 Bailleul-aux-Cornailles\", \"score\": 0.5269641371131077, \"id\": \"62070_0100\", \"type\": \"street\", \"x\": 660129.18, \"y\": 7030540.46, \"importance\": 0.25814396978264664, \"name\": \"Rue Jangon\", \"postcode\": \"62127\", \"citycode\": \"62070\", \"city\": \"Bailleul-aux-Cornailles\", \"context\": \"62, Pas-de-Calais, Hauts-de-France\"}}], \"attribution\": \"BAN\", \"licence\": \"ETALAB-2.0\", \"query\": \"10 Rue Jangot\", \"limit\": 5}",
"headers": {
"Server": "nginx/1.13.4",
"Date": "Wed, 13 Mar 2019 17:01:21 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "1087",
"Connection": "keep-alive",
"Vary": "Accept-Encoding",
"X-Cache-Status": "MISS",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "X-Requested-With"
"Server":"nginx/1.10.3",
"Date":"Thu, 25 Jun 2020 11:23:54 GMT",
"Content-type":"application/json; charset=utf-8",
"Vary":"Accept-Encoding",
"X-cache-status":"MISS",
"Access-control-allow-origin":"*",
"Access-control-allow-headers":"X-Requested-With,Content-Type",
"Content-encoding":"gzip"
},
"status_code": 200,
"type": "ok"

View File

@ -63,6 +63,8 @@ defmodule Mobilizon.Service.Geospatial.AddokTest do
test "returns a valid address from search" do
use_cassette "geospatial/addok/search" do
assert %Address{
country: "France",
region: "69, Rhône, Auvergne-Rhône-Alpes",
locality: "Lyon",
description: "10 Rue Jangot",
postal_code: "69007",
@ -75,6 +77,8 @@ defmodule Mobilizon.Service.Geospatial.AddokTest do
test "returns a valid address from reverse geocode" do
use_cassette "geospatial/addok/geocode" do
assert %Address{
country: "France",
region: "69, Rhône, Auvergne-Rhône-Alpes",
locality: "Lyon",
description: "10 Rue Jangot",
postal_code: "69007",