Skip to content

Commit

Permalink
update Nominatim
Browse files Browse the repository at this point in the history
  • Loading branch information
breunigs committed Jul 24, 2024
1 parent e38dcb5 commit 5543987
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/basemap/nominatim.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Basemap.Nominatim do
require Benchmark
require Logger

@full_ref {"Nominatim", {:remote, "mediagis/nominatim", "4.3"}}
@full_ref {"Nominatim", {:remote, "mediagis/nominatim", "4.4"}}
@queries [:search, :area]

def export(query, where \\ :cache) when query in @queries,
Expand Down
22 changes: 16 additions & 6 deletions lib/search/meilisearch/nominatim.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ defmodule Search.Meilisearch.Nominatim do

human = lookup(result, [["extratags", "building"], "type", ["extratags", "border_type"]])
bbox = Geo.BoundingBox.parse(f.("bbox"))
addr = f.("address")
names = f.("name")
addr = f.("address")
street = "#{addr["street"]} #{addr["housenumber"]}"

name =
~w[name:de name alt_name old_name addr:housename official_name brand]
Expand All @@ -57,24 +58,28 @@ defmodule Search.Meilisearch.Nominatim do
|> Kernel.++([f.("extratags")["operator"]])
|> dedupe()

street = "#{addr["street"]} #{addr["housenumber"]}"
name = if name == "", do: street, else: name
name =
cond do
!blank?(name) -> name
result["type"] in ~w[office building public_building house apartment apartments] -> street
true -> human
end

subtext =
dedupe(
[
f.("extratags")["name:prefix"],
human,
f.("extratags")["operator"],
"#{addr["street"]} #{addr["housenumber"]}",
street,
addr["suburb"],
addr["postcode"] || f.("parents_postcode"),
f.("parents_name"),
addr["city"]
] -- [name]
)

{name, subtext} = if name == "", do: {subtext, nil}, else: {name, subtext}
{name, subtext} = if blank?(name), do: {subtext, nil}, else: {name, subtext}

%Search.Result{
bounds: bbox,
Expand Down Expand Up @@ -193,10 +198,11 @@ defmodule Search.Meilisearch.Nominatim do
defp into(_into, nil), do: nil
defp into(into, ms), do: Enum.into(ms, into)

@spec dedupe([binary() | nil]) :: binary()
def dedupe(list) do
list
|> List.flatten()
|> Enum.reject(fn e -> e == nil || String.trim(e) == "" end)
|> Enum.reject(&blank?/1)
|> Enum.map(&String.trim/1)
|> Enum.uniq()
|> Enum.join(", ")
Expand Down Expand Up @@ -244,4 +250,8 @@ defmodule Search.Meilisearch.Nominatim do
end

defp lookup(_result, []), do: nil

defp blank?(nil), do: true
defp blank?(""), do: true
defp blank?(str) when is_binary(str), do: String.trim(str) == ""
end

0 comments on commit 5543987

Please sign in to comment.