Search the offline map and Wikipedia, nearest results first
CI / check (push) Successful in 26s
CI / deploy (push) Successful in 33s

Every named OSM object in each country's Geofabrik extract goes into a
SQLite FTS5 index (data/places/<CODE>.sqlite, lib/maptool/places.rb),
built as the last offline-build step or on its own with
rake places:index. Kiwix full-text search is another source; clicking a
hit opens the article. Results from every source are sorted by distance
from the map center (settlements weighted closer) and show it; each
source is queried separately so a slow one doesn't hold up the list.
This commit is contained in:
randy committed 2026-11-12 12:13:13 +01:00
1 parent ba9c40ac3d
commit 3f973a26d7
14 files changed
+549 -90

No files matched your search

+40
View File
@@ -124,4 +124,44 @@ class KiwixTest < Minitest::Test
geojson = Maptool::Kiwix.nearby("http://127.0.0.1:1", [48.0, 17.0, 48.2, 17.3], open_timeout: 1)
assert_equal({ "type" => "FeatureCollection", "features" => [] }, geojson)
end
def test_search_returns_every_hit_with_its_position_when_it_has_one
server = TCPServer.new("127.0.0.1", 0)
port = server.addr[1]
search_line = nil
thread = Thread.new do
3.times do
client = server.accept
request_line = client.gets
body =
if request_line.include?("/kiwix/search")
search_line = request_line
<<~XML
<rss><channel>
<item><title>Devín</title><link>/kiwix/content/wikipedia/Dev%C3%ADn</link></item>
<item><title>Pivo</title><link>/kiwix/content/wikipedia/Pivo</link></item>
</channel></rss>
XML
elsif request_line.include?("/Dev")
'<meta name="geo.position" content="48.17;16.98">'
else
"no coordinates here"
end
client.print("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: #{body.bytesize}\r\n\r\n#{body}")
client.close
end
end
results = Maptool::Kiwix.search("http://127.0.0.1:#{port}", "hrad devín", limit: 5)
thread.join
server.close
assert_includes search_line, "pattern=hrad+dev%C3%ADn"
assert_equal [["Devín", [16.98, 48.17]], ["Pivo", nil]], results.map { |r| r.values_at(:title, :position) }
end
def test_search_is_empty_without_a_kiwix_url_or_query
assert_empty Maptool::Kiwix.search("", "x")
assert_empty Maptool::Kiwix.search("http://127.0.0.1:1", " ")
end
end