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:
1 parent
f3dd37dd4e
commit
e2461f794c
3 files changed
+18
-9
No files matched your search
@@ -63,7 +63,7 @@ independence from connectivity.
|
||||
|
||||
* [x] Unified search box — one query across every data source, not just what's currently on the map. `GET /api/search` (`lib/maptool/search.rb`) for local sources, online ones queried from the browser (`public/js/search.js`)
|
||||
** [x] Every layer under Tracks & Points (GPX, FIT, GeoJSON, notes, plugin output) and offline hiking trails — shown *and* hidden ones. Matches name + description, case/diacritics-insensitive ("kosice" finds "Košice"); parsed features cached in memory per file by mtime
|
||||
** [x] Offline vector data — every named OSM object in each country's Geofabrik `.osm.pbf` (`osmium tags-filter nwr/name` + `osmium export -f geojsonseq`) into a SQLite FTS5 index, `data/places/<CODE>.sqlite` (`lib/maptool/places.rb`), built as the last offline-build step ("indexing places") and cached by mtime like hiking trails. Prefix + diacritics-insensitive matching, street segments merged per ~2 km cell; named buildings and land-use areas dropped (unless they're also a shop/amenity/…), names searchable without their apostrophes ("mcdonalds") and by `brand`. `Places::SCHEMA_VERSION` makes `rake places:index` rebuild older indexes by itself
|
||||
** [x] Offline vector data — every named OSM object in each country's Geofabrik `.osm.pbf` (`osmium tags-filter nwr/name` + `osmium export -f geojsonseq`) into a SQLite FTS5 index, `data/places/<CODE>.sqlite` (`lib/maptool/places.rb`), built as the last offline-build step ("indexing places") and cached by mtime like hiking trails. Prefix + diacritics-insensitive matching, street segments merged per ~2 km cell; named buildings, land-use areas, `place=locality`/`isolated_dwelling` and objects with no recognized kind dropped (a shop in a building stays), names searchable without their apostrophes ("mcdonalds") and by `brand`. `Places::SCHEMA_VERSION` makes `rake places:index` rebuild older indexes by itself
|
||||
** [x] Every result shows where it was found (layer file / "Hiking trails SK" / "Online · Nominatim"); clicking one zooms to it (fitBounds for a track) and switches its layer on if it was off
|
||||
** [x] Source checklist in the search panel (all on by default), re-runs the search on change
|
||||
** [x] Online sources pluggable — one more entry in search.js's `SOURCES`; Nominatim already in, its failure only adds a "no connection" line under the local results
|
||||
|
||||
+13
-7
@@ -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]
|
||||
|
||||
+4
-1
@@ -20,6 +20,9 @@ class PlacesTest < Minitest::Test
|
||||
feature("Point", [18.0, 48.0], "highway" => "crossing"), # no name -> skipped
|
||||
feature("Polygon", [[[17.0, 48.0], [17.01, 48.0], [17.01, 48.01], [17.0, 48.0]]], "name" => "Bytovka Lidl", "building" => "yes"),
|
||||
feature("Polygon", [[[17.0, 48.0], [17.01, 48.0], [17.01, 48.01], [17.0, 48.0]]], "name" => "Družstvo", "landuse" => "farmland"),
|
||||
feature("Point", [17.3, 48.3], "name" => "Pod Družstvom", "place" => "locality"),
|
||||
feature("Point", [17.3, 48.31], "name" => "Samota Družstevná", "place" => "isolated_dwelling"),
|
||||
feature("LineString", [[17.0, 48.0], [17.5, 48.5]], "name" => "Bus 31 Družstvo", "type" => "route"),
|
||||
feature("Polygon", [[[17.2, 48.1], [17.21, 48.1], [17.21, 48.11], [17.2, 48.1]]],
|
||||
"name" => "Lidl Petržalka", "brand" => "Lidl", "shop" => "supermarket", "building" => "retail"),
|
||||
feature("Point", [17.15, 48.15], "name" => "McDonald's", "amenity" => "fast_food", "brand" => "McDonald's"),
|
||||
@@ -63,7 +66,7 @@ class PlacesTest < Minitest::Test
|
||||
|
||||
def test_buildings_and_land_use_are_dropped_but_a_shop_in_a_building_is_kept
|
||||
assert_empty search("bytovka")
|
||||
assert_empty search("druzstvo")
|
||||
assert_empty search("druzstv") # landuse, locality, isolated dwelling, no kind at all
|
||||
assert_equal [["Lidl Petržalka", "supermarket"]], search("lidl").map { |r| r.values_at(:name, :kind) }
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user