Places index: also drop localities, isolated dwellings and kindless objects

Measured on France (5.3M rows): place=locality ~10% (mostly cadastral
names of fields and woods), isolated_dwelling ~5%, objects with a name
but none of the recognized kind keys ~4% (bus route relations etc.).
Schema version 3, so rake places:index rebuilds existing indexes.
This commit is contained in:
randy committed 2026-11-12 13:42:04 +01:00
1 parent f3dd37dd4e
commit e2461f794c
3 files changed
+18 -9

No files matched your search

+13 -7
View File
@@ -16,17 +16,23 @@ module Maptool
# Bumped whenever the table layout or what goes into it changes —
# PmtilesBuilder rebuilds an index whose user_version is older, so a
# plain `rake places:index` picks the change up.
SCHEMA_VERSION = 2
SCHEMA_VERSION = 3
# Most to least important; the first key a feature carries decides
# its kind and rank. Within "place", the value refines it further.
KIND_KEYS = %w[place natural tourism amenity historic leisure shop aeroway railway highway waterway
boundary landuse man_made office building].freeze
# Named buildings and land-use areas (a farm's fields, an industrial
# estate) are a large share of every country's index and nobody looks
# for them by name — dropped, but only when that's what the object
# *is*: a supermarket drawn as a building is still shop=supermarket.
# estate) are noise in results — nobody looks for them by name — so
# they're dropped, but only when that's what the object *is*: a
# supermarket drawn as a building is still shop=supermarket. (Measured:
# only ~1-7% of an index's size, so this is about result quality.)
SKIPPED_KEYS = %w[landuse building].freeze
# Same idea, measured on France (5.3M rows): place=locality (~10%,
# mostly cadastral names of fields and woods) and isolated_dwelling
# (~5%, single farms/houses) — plus anything named but with none of
# KIND_KEYS (~4%: bus route relations and the like).
SKIPPED_PLACES = %w[locality isolated_dwelling].freeze
APOSTROPHES = "'’ʼ`"
PLACE_RANK = { "city" => 0, "town" => 1, "village" => 2, "suburb" => 3, "hamlet" => 3 }.freeze
# How much closer a settlement counts as when results are ordered by
@@ -108,7 +114,8 @@ module Maptool
geometry = feature["geometry"] || {}
coords = geometry["coordinates"]
key = KIND_KEYS.find { |k| tags[k] }
return nil if name.empty? || !coords.is_a?(Array) || coords.empty? || SKIPPED_KEYS.include?(key)
return nil if name.empty? || !coords.is_a?(Array) || coords.empty? || key.nil? || SKIPPED_KEYS.include?(key)
return nil if key == "place" && SKIPPED_PLACES.include?(tags["place"])
points = positions(coords)
lngs, lats = points.map { |p| p.first(2) }.transpose
@@ -119,8 +126,7 @@ module Maptool
lon, lat = geometry["type"] == "LineString" ? points[points.size / 2] : [(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2]
value = tags[key].to_s
kind = if key.nil? then ""
elsif key == "highway" && geometry["type"] != "Point" then "street"
kind = if key == "highway" && geometry["type"] != "Point" then "street"
else value.tr("_", " ")
end
importance = key == "place" ? PLACE_RANK.fetch(value, KEY_RANK["place"]) : KEY_RANK[key]