Places index: drop buildings and land use, search without apostrophes and by brand
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 12s

Named buildings and land-use areas are skipped unless they're also a
shop/amenity/etc. A second, unshown FTS column holds the name without
apostrophes and the brand tag, so "mcdonalds" finds McDonald's and
"lidl" finds "Lidl Petržalka". The index records a schema version;
rake places:index rebuilds older ones by itself.
This commit is contained in:
randy committed 2026-11-12 12:58:31 +01:00
1 parent 8e4c466829
commit f3dd37dd4e
5 files changed
+67 -12

No files matched your search

+27 -1
View File
@@ -1,5 +1,6 @@
require_relative "test_helper"
require "maptool/places"
require "maptool/search"
require "stringio"
# No real osmium — import is fed canned `osmium export -f geojsonseq`
@@ -17,6 +18,11 @@ class PlacesTest < Minitest::Test
feature("LineString", [[17.103, 48.143], [17.104, 48.144]], "name" => "Hlavná", "highway" => "residential"),
feature("Polygon", [[[19.0, 48.0], [19.2, 48.0], [19.2, 48.2], [19.0, 48.0]]], "name" => "Košické jazero", "natural" => "water"),
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("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"),
"not json",
]
Maptool::Places.import(StringIO.new(lines.join("\n")), @db)
@@ -55,10 +61,30 @@ class PlacesTest < Minitest::Test
assert_empty search("crossing")
end
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_equal [["Lidl Petržalka", "supermarket"]], search("lidl").map { |r| r.values_at(:name, :kind) }
end
def test_apostrophes_and_brand_are_searchable
assert_equal ["McDonald's"], search("mcdonalds").map { |r| r[:name] }
assert_equal ["McDonald's"], search("McDonald's").map { |r| r[:name] }
assert_equal ["McDonald's"], search("mcdonald").map { |r| r[:name] }
assert_equal ["Lidl Petržalka"], search("lidl").map { |r| r[:name] } # also via brand
end
def test_an_index_from_an_older_schema_is_not_current
assert Maptool::Places.current?(@db)
SQLite3::Database.new(@db) { |db| db.execute("PRAGMA user_version = 1") }
refute Maptool::Places.current?(@db)
refute Maptool::Places.current?(File.join(@dir, "missing.sqlite"))
end
private
def search(text, **opts)
words = text.unicode_normalize(:nfkd).gsub(/\p{Mn}/, "").downcase.split
words = Maptool::Search.normalize(text).split
Maptool::Places.search(@db, words, **opts).map { |r| r.except(:rank) }
end