Modern Apps git

← Modern-Apps.git

maps: rank POI search by match tier, category and coordinates

Commit
77372be9c7e4845f4e477d31643cbb5d6e79c2cb
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:27 UTC (28 days ago)
Parents
05b6fca
Search previously matched raw name text inside the bounding box and
reported no results for anything else: typos, category words
('coffee'), multi-word queries out of order, or 'lat, lon' input.

Replace the scan/index split with one tiered matcher (exact, prefix,
all-tokens, substring, category, fuzzy with capped Levenshtein) shared
by both paths, so results agree no matter which path answers. Category
terms resolve through PoiCategories, coordinate queries take a fast
path in the ViewModel, and per-token word-index prefix intersection
keeps the indexed path fast with scan fallback.

The mid-word test now asserts matches on both paths instead of pinning
the old index-only narrowing the tiers closed.

Verified: :maps:testDevUnitTest, 900 tests green.

Diff

maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.ktindex 2a1e773b3f..095bf8b3cf 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapsSearchViewModel.kt@@ -94,6 +94,22 @@ class MapsSearchViewModel(application: Application) : AndroidViewModel(applicati     fun setQuery(query: String, nearLat: Double, nearLon: Double) {         _query.value = query         searchJob?.cancel()+        // A "lat,lon" query is a place in itself: resolve it directly+        // instead of asking the name index, which can only answer empty.+        PoiSearch.parseCoordinateQuery(query)?.let { (lat, lon) ->+            _results.value = listOf(+                SearchResult(+                    id = "coord:$lat:$lon",+                    title = "%.5f, %.5f".format(lat, lon),+                    subtitle = null,+                    lat = lat,+                    lon = lon,+                    category = null,+                )+            )+            _searching.value = false+            return+        }         if (query.length < 2) {             _results.value = emptyList()             _searching.value = false
maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.ktindex 869be13e47..1601f7ad97 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiCategories.kt@@ -80,6 +80,50 @@ object PoiCategories {     /** Human-readable category label (used as the search-result subtitle). */     fun label(type: Int): String = LABELS.getOrElse(type) { "Place" } +    /**+     * POI types a normalised singular search term names as a category, or+     * empty when the term is not a category word.+     *+     * Derived from [LABELS] (so "pharmacy" or "bakery" work with no extra+     * table) plus synonyms people actually type ("coffee" for a cafe,+     * "gas" for a gas station, "food" for eating places). Search uses this+     * so category queries — including the category chips, whose queries are+     * words like "gas station" that no POI is literally named — return the+     * nearest places of that kind instead of nothing.+     */+    fun typesForTerm(term: String): Set<Int> {+        val out = HashSet<Int>()+        LABELS.forEachIndexed { type, label ->+            val words = label.lowercase().split(' ', '/')+            if (words.any { PoiSearch.singular(it) == term }) out.add(type)+        }+        SYNONYM_TYPES[term]?.let { out.addAll(it) }+        return out+    }++    private val SYNONYM_TYPES: Map<String, Set<Int>> = mapOf(+        "coffee" to setOf(1),+        "gas" to setOf(6),+        "petrol" to setOf(6),+        "fuel" to setOf(6),+        "food" to setOf(0, 2),+        "eat" to setOf(0, 2),+        "drink" to setOf(3, 1),+        "cash" to setOf(9),+        "atm" to setOf(9),+        "sleep" to setOf(8),+        "stay" to setOf(8),+        "shop" to setOf(4),+        "store" to setOf(4, 33),+        "train" to setOf(STATION_TYPE),+        "station" to setOf(STATION_TYPE),+        "bus" to setOf(STATION_TYPE),+        "car" to setOf(28, 16),+        "parking" to setOf(16),+        "health" to setOf(10, 34, 35),+        "medical" to setOf(10, 35),+    )+      /**      * The numeric type an archive `kind` corresponds to, or `null` when nothing here means
maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.ktindex c9a8294e65..bccecf3747 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiIndex.kt@@ -325,7 +325,6 @@ object PoiIndex {      @Volatile     private var mapped: Mapped? = null-    private var tried = false      /** Read access for the extension queries in PoiIndexSpatial.kt / PoiIndexWords.kt. */     internal fun mappedForQuery(): Mapped? = mapped@@ -344,14 +343,17 @@ object PoiIndex {      * safe to call repeatedly. Prefers the single-archive `.mamaps` file when      * present (one download carries tiles, graph, POI and transit), falling      * back to the side files. Returns false (and stays a no-op) when neither-     * is present. Not retried automatically after a failure unless [reload]-     * is called (e.g. after the download completes).+     * is present. A failed attempt does not latch: the next call retries,+     * so a call made before the download finished cannot poison later ones.      */     @Synchronized     fun initialize(context: Context): Boolean {         if (mapped != null) return true-        if (tried) return false-        tried = true+        // No failure latch: a first call made before the archive download+        // finished (e.g. a cold-start deep link handled before the download+        // gate) must not poison every later search for the process lifetime.+        // The check is two file stats once mapped, and callers already run+        // it on IO, so retrying a miss is cheap.         val dir = context.getExternalFilesDir(null) ?: return false         if (tryArchive(dir)) return true         return open(dir)@@ -368,7 +370,6 @@ object PoiIndex {     @Synchronized     fun reloadArchive(file: File): Boolean {         mapped = null-        tried = true         val fromArchive = PoiArchive.openArchive(file) ?: return false         mapped = fromArchive         return true@@ -395,7 +396,6 @@ object PoiIndex {     /** Shared re-map body: clear state, then map from [dir]. */     private fun reloadMapped(dir: File): Boolean {         mapped = null-        tried = true         if (tryArchive(dir)) return true         return open(dir)     }@@ -579,20 +579,16 @@ object PoiIndex {         }      /**-     * Name search, ranked first-word-first then by distance to ([nearLat],[nearLon]).+     * Offline place search over the whole index (no bounding-box limit),+     * ranked by match tier then by distance to ([nearLat],[nearLon]).      *-     * Two implementations, picked by whether `poi_name_index.bin` was mapped:-     *-     *  * **Indexed** — binary search to the query's place in a word-sorted index, then a-     *    walk of the matching range, so the cost is the number of matches. Because every-     *    word of a name is indexed, "pizza" still finds "Joe's Pizza".-     *  * **Scan** — the name pool, then every record. Two passes whose cost is the whole-     *    dataset, kept only because the side file is optional.-     *-     * **The two do not match exactly, by design.** The scan matches a substring anywhere,-     * so "izza" finds "Pizza"; a sorted index can only answer prefix questions, so the-     * indexed path matches a prefix *of any word*. That is a deliberate narrowing —-     * mid-word matches are lost, whole-word ones are not.+     * Token-based: every query token must match a word of the name (word+     * prefix, substring, or a small edit distance), so multi-word names,+     * diacritics and small typos resolve. Purely categorical queries+     * ("coffee", "gas station") match by POI type instead. Candidate+     * gathering uses the word index when mapped and the name-pool scan+     * otherwise (and as the substring/fuzzy fallback); see+     * [searchPoi][com.vayunmathur.maps.util.searchPoi] and [PoiSearch].      */     fun searchByName(         query: String,@@ -602,31 +598,11 @@ object PoiIndex {     ): List<PoiRecord> {         val m = mapped ?: return emptyList()         if (query.isBlank()) return emptyList()-        if (m.nameIdx != null) return searchByWordIndex(m, query, nearLat, nearLon, limit)-        return searchByScan(m, query, nearLat, nearLon, limit)+        // Token-based matching with category and fuzzy fallbacks; see+        // PoiIndexWords.searchPoi and PoiSearch for the ranking contract.+        return searchPoi(m, query, nearLat, nearLon, limit)     } -    // Indexed search lives in PoiIndexWords.kt; this delegates so searchByName is unchanged.-    private fun searchByWordIndex(-        m: Mapped,-        query: String,-        nearLat: Double,-        nearLon: Double,-        limit: Int,-    ): List<PoiRecord> = searchByWordIndex(m, query, nearLat, nearLon, limit, CANDIDATE_CAP)--    // Scan search lives in PoiIndexWords.kt; this delegates so searchByName is unchanged.-    // (This must call the package-level function there: calling itself-    // recurses forever — StackOverflowError on every scan-path search.)-    private fun searchByScan(-        m: Mapped,-        query: String,-        nearLat: Double,-        nearLon: Double,-        limit: Int,-    ): List<PoiRecord> =-        com.vayunmathur.maps.util.searchByScan(m, query, nearLat, nearLon, limit)-     // Spatial queries (nearest/inViewport) live in PoiIndexSpatial.kt as     // extensions, alongside the grid they walk. 
maps/src/main/java/com/vayunmathur/maps/util/PoiIndexWords.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiIndexWords.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiIndexWords.ktindex 298d14d6d9..86c55a0ec9 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PoiIndexWords.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiIndexWords.kt@@ -150,122 +150,154 @@ private fun PoiIndex.Mapped.matchesAt(i: Int, key: ByteArray): Boolean {     return wordStartsWith(w, key) } -private class WordRanked(val record: PoiIndex.PoiRecord, val rank: Int, val distSq: Double)- private class Ranked(val record: PoiIndex.PoiRecord, val rank: Int, val distSq: Double) -internal fun searchByScan(+/**+ * The unified offline search behind [PoiIndex.searchByName].+ *+ * Matching is token-based (see [PoiSearch]): every query token must match+ * a word of the place name — by word prefix, substring, or (as a last+ * resort) a small edit distance — so multi-word queries, diacritics and+ * small typos all resolve. Category terms ("coffee", "gas station") also+ * match places by their POI type. There is deliberately no bounding-box+ * restriction: the whole offline index is searched and results are ranked+ * by match tier, then by distance to ([nearLat], [nearLon]), so the+ * nearest good match wins wherever it is.+ *+ * Candidate gathering prefers the word index (one binary search per+ * token, intersected by ordinal) and falls back to the name-pool scan+ * when the index is absent or the intersection is empty — which is also+ * the path that provides substring and fuzzy matches the sorted index+ * cannot answer.+ */+internal fun searchPoi(     m: PoiIndex.Mapped,     query: String,     nearLat: Double,     nearLon: Double,     limit: Int, ): List<PoiIndex.PoiRecord> {-    val q = query.trim().lowercase()-    if (q.isEmpty()) return emptyList()+    val queryTokens = PoiSearch.tokens(query)+    if (queryTokens.isEmpty()) return emptyList()+    val queryNorm = queryTokens.joinToString(" ")++    // ordinal -> best tier so far.+    val tiers = HashMap<Int, Int>()+    if (m.nameIdx != null) {+        collectIndexedMatches(m, queryTokens, queryNorm, tiers)+    }+    if (tiers.isEmpty()) {+        collectScanMatches(m, queryNorm, queryTokens, tiers)+    }+    collectCategoryMatches(m, queryTokens, tiers)++    if (tiers.isEmpty()) return emptyList()+    val ranked = ArrayList<Ranked>(tiers.size)+    for ((ordinal, tier) in tiers) {+        if (ordinal < 0 || ordinal >= m.count) continue+        ranked.add(+            Ranked(+                m.record(ordinal),+                tier,+                PoiIndex.distanceSq(+                    m.latE7(ordinal) * PoiIndex.E7_TO_DEGREES,+                    m.lonE7(ordinal) * PoiIndex.E7_TO_DEGREES,+                    nearLat,+                    nearLon,+                ),+            )+        )+    }+    ranked.sortWith(compareBy({ it.rank }, { it.distSq }))+    return ranked.take(limit).map { it.record }+} -    // Pass 1: walk the name pool once, recording matching offsets and their-    // rank (0 = prefix match, 1 = substring). Decoding each unique name once-    // is the dedup win the side-file layout is designed for.-    val matchRank = matchNamePool(m, q)-    if (matchRank.isEmpty()) return emptyList()+/**+ * Intersect per-token word-prefix matches from the word index: an ordinal+ * is a candidate only when every query token prefixes some word of its+ * name. Tiers are then scored exactly with [PoiSearch.matchTier].+ */+private fun collectIndexedMatches(+    m: PoiIndex.Mapped,+    queryTokens: List<String>,+    queryNorm: String,+    tiers: HashMap<Int, Int>,+) {+    var candidates: MutableSet<Int>? = null+    for (token in queryTokens) {+        val hits = m.wordPrefixMatches(poiQueryKey(token), PoiIndex.CANDIDATE_CAP)+        val ordinals = hits.mapTo(HashSet()) { it[0] }+        candidates = candidates?.apply { retainAll(ordinals) } ?: ordinals+        if (candidates.isEmpty()) return+    }+    for (ordinal in candidates.orEmpty()) {+        if (ordinal < 0 || ordinal >= m.count) continue+        val tier = PoiSearch.matchTier(m.record(ordinal).name, queryNorm, queryTokens)+        if (tier != PoiSearch.NO_MATCH) tiers[ordinal] = tier+    }+} -    // Pass 2: scan records, keeping those whose name offset matched.-    val out = collectScanMatches(m, matchRank, nearLat, nearLon)-    out.sortWith(compareBy({ it.rank }, { it.distSq }))-    return out.take(limit).map { it.record }+/** Name-pool scan: match unique names once, then join records by offset. */+private fun collectScanMatches(+    m: PoiIndex.Mapped,+    queryNorm: String,+    queryTokens: List<String>,+    tiers: HashMap<Int, Int>,+) {+    val matchRank = matchNamePool(m, queryNorm, queryTokens)+    if (matchRank.isEmpty()) return+    var i = 0+    while (i < m.count && tiers.size < PoiIndex.CANDIDATE_CAP) {+        matchRank[m.nameOff(i)]?.let { tiers[i] = it }+        i+++    } } -private fun matchNamePool(m: PoiIndex.Mapped, q: String): Map<Int, Int> {+private fun matchNamePool(+    m: PoiIndex.Mapped,+    queryNorm: String,+    queryTokens: List<String>,+): Map<Int, Int> {     val matchRank = HashMap<Int, Int>()     var pos = 0     while (pos < m.namesLen) {         var end = pos         while (end < m.namesLen && m.names.get(end).toInt() != 0) end++         if (end > pos) {-            rankName(m.nameAt(pos), q)?.let { matchRank[pos] = it }+            val name = m.nameAt(pos)+            if (name != null) {+                val tier = PoiSearch.matchTier(name, queryNorm, queryTokens)+                if (tier != PoiSearch.NO_MATCH) matchRank[pos] = tier+            }         }         pos = end + 1     }     return matchRank } -/** Rank of [name] against the query (0 = prefix, 1 = substring), or null. */-private fun rankName(name: String?, q: String): Int? {-    if (name == null) return null-    val lower = name.lowercase()-    if (lower.startsWith(q)) return 0-    if (lower.contains(q)) return 1-    return null-}--private fun collectScanMatches(+/**+ * Category candidates: when every query token is a category term ("gas",+ * "station", "coffee"), places of those POI types match at+ * [PoiSearch.TIER_CATEGORY] even though their names do not contain the+ * words. This is what makes the category chips work offline.+ */+private fun collectCategoryMatches(     m: PoiIndex.Mapped,-    matchRank: Map<Int, Int>,-    nearLat: Double,-    nearLon: Double,-): ArrayList<Ranked> {-    val out = ArrayList<Ranked>(minOf(PoiIndex.CANDIDATE_CAP, m.count))+    queryTokens: List<String>,+    tiers: HashMap<Int, Int>,+) {+    val types = HashSet<Int>()+    for (token in queryTokens) {+        val found = PoiCategories.typesForTerm(PoiSearch.singular(token))+        if (found.isEmpty()) return // Not a purely categorical query.+        types.addAll(found)+    }+    if (types.isEmpty()) return     var i = 0-    while (i < m.count && out.size < PoiIndex.CANDIDATE_CAP) {-        scanMatchAt(m, i, matchRank, nearLat, nearLon)?.let { out.add(it) }+    while (i < m.count && tiers.size < PoiIndex.CANDIDATE_CAP) {+        if (m.type(i) in types) tiers.putIfAbsent(i, PoiSearch.TIER_CATEGORY)         i++     }-    return out } -private fun scanMatchAt(-    m: PoiIndex.Mapped,-    i: Int,-    matchRank: Map<Int, Int>,-    nearLat: Double,-    nearLon: Double,-): Ranked? {-    val off = m.nameOff(i)-    val rank = matchRank[off] ?: return null-    val latE7 = m.latE7(i)-    val lonE7 = m.lonE7(i)-    return Ranked(-        PoiIndex.PoiRecord(latE7, lonE7, m.type(i), m.nameAt(off) ?: "", i),-        rank,-        PoiIndex.distanceSq(-            latE7 * PoiIndex.E7_TO_DEGREES,-            lonE7 * PoiIndex.E7_TO_DEGREES,-            nearLat,-            nearLon,-        ),-    )-} -internal fun searchByWordIndex(-    m: PoiIndex.Mapped,-    query: String,-    nearLat: Double,-    nearLon: Double,-    limit: Int,-    candidateCap: Int,-): List<PoiIndex.PoiRecord> {-    val key = poiQueryKey(query.trim())-    if (key.isEmpty()) return emptyList()-    val out = ArrayList<WordRanked>()-    for (hit in m.wordPrefixMatches(key, candidateCap)) {-        val (ordinal, wordIdx) = hit-        // Matching the name's first word is the indexed equivalent of the scan's-        // "starts with", and ranks the same way.-        val rank = if (wordIdx == 0) 0 else 1-        out.add(-            WordRanked(-                m.record(ordinal),-                rank,-                PoiIndex.distanceSq(-                    nearLat,-                    nearLon,-                    m.latE7(ordinal) * PoiIndex.E7_TO_DEGREES,-                    m.lonE7(ordinal) * PoiIndex.E7_TO_DEGREES,-                ),-            )-        )-    }-    out.sortWith(compareBy({ it.rank }, { it.distSq }))-    return out.take(limit).map { it.record }-}
maps/src/main/java/com/vayunmathur/maps/util/PoiSearch.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PoiSearch.kt b/maps/src/main/java/com/vayunmathur/maps/util/PoiSearch.ktnew file mode 100644index 0000000000..ee80d82e8c--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/util/PoiSearch.kt@@ -0,0 +1,124 @@+package com.vayunmathur.maps.util++import java.text.Normalizer++/**+ * Pure matching logic for offline POI search: text normalisation, token+ * matching tiers, typo tolerance and coordinate queries.+ *+ * Kept free of the mapped index so it is unit-testable without side files.+ * The index code in PoiIndexWords supplies candidates; this file decides+ * what counts as a match and how matches rank against each other.+ *+ * Normalisation is deliberately stronger than the word index's ASCII fold:+ * that fold exists only to reproduce the Rust writer's sort order for+ * binary search. Matching (this file) folds case AND diacritics and drops+ * punctuation, so "Café" finds "Cafe" and "joe's" finds "Joes". Candidate+ * *lookup* in the word index still uses the writer's fold per token; the+ * scan fallback applies this normalisation to the name pool directly.+ */+object PoiSearch {++    /** Match tiers, best first. Lower wins; distance breaks ties. */+    const val TIER_EXACT = 0+    const val TIER_PREFIX = 1+    const val TIER_TOKENS = 2+    const val TIER_SUBSTRING = 3+    const val TIER_CATEGORY = 4+    const val TIER_FUZZY = 5+    const val NO_MATCH = -1++    private val MARKS = Regex("\\p{Mn}+")+    private val NON_WORD = Regex("[^a-z0-9]+")++    /** Lowercase, strip diacritics, and reduce punctuation to spaces. */+    fun normalize(text: String): String {+        val decomposed = Normalizer.normalize(text, Normalizer.Form.NFD)+        val withoutMarks = MARKS.replace(decomposed, "")+        return NON_WORD.replace(withoutMarks.lowercase(), " ").trim()+    }++    /** The normalised word tokens of [text], in order, empties removed. */+    fun tokens(text: String): List<String> =+        normalize(text).split(' ').filter { it.isNotEmpty() }++    /** Singular form of a token for category matching ("restaurants" -> "restaurant"). */+    fun singular(token: String): String =+        if (token.length > 3 && token.endsWith('s')) token.dropLast(1) else token++    /**+     * Tier at which the normalised [name] matches the normalised query+     * [queryNorm] with tokens [queryTokens], or [NO_MATCH].+     *+     * Every query token must match some name word (prefix, then substring,+     * then fuzzy) for the token tiers; a single unmatched token rejects the+     * name, which is what makes multi-word queries ("central park") work+     * instead of being looked up as one long word.+     */+    fun matchTier(name: String, queryNorm: String, queryTokens: List<String>): Int {+        if (queryTokens.isEmpty()) return NO_MATCH+        val nameNorm = normalize(name)+        if (nameNorm.isEmpty()) return NO_MATCH+        if (nameNorm == queryNorm) return TIER_EXACT+        if (nameNorm.startsWith(queryNorm)) return TIER_PREFIX+        val words = nameNorm.split(' ')+        var worst = TIER_TOKENS+        for (token in queryTokens) {+            val tier = tokenTier(token, words) ?: return NO_MATCH+            if (tier > worst) worst = tier+        }+        return worst+    }++    /** Best tier one query [token] achieves against [words], or null. */+    private fun tokenTier(token: String, words: List<String>): Int? {+        if (words.any { it.startsWith(token) }) return TIER_TOKENS+        if (words.any { it.contains(token) }) return TIER_SUBSTRING+        if (maxEditDistance(token) > 0 && words.any { editDistanceAtMost(token, it, maxEditDistance(token)) }) {+            return TIER_FUZZY+        }+        return null+    }++    /** Typo budget for a token: none for short tokens, growing with length. */+    fun maxEditDistance(token: String): Int = when {+        token.length < 4 -> 0+        token.length < 8 -> 1+        else -> 2+    }++    /** Levenshtein distance between [a] and [b], early-exiting past [cap]. */+    fun editDistanceAtMost(a: String, b: String, cap: Int): Boolean {+        if (cap < 0) return false+        if (kotlin.math.abs(a.length - b.length) > cap) return false+        var prev = IntArray(b.length + 1) { it }+        var curr = IntArray(b.length + 1)+        for (i in 1..a.length) {+            curr[0] = i+            var rowMin = curr[0]+            for (j in 1..b.length) {+                val cost = if (a[i - 1] == b[j - 1]) 0 else 1+                curr[j] = minOf(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost)+                if (curr[j] < rowMin) rowMin = curr[j]+            }+            if (rowMin > cap) return false+            val swap = prev; prev = curr; curr = swap+        }+        return prev[b.length] <= cap+    }++    private val COORD_QUERY = Regex("""^\s*(-?\d{1,3}(?:\.\d+)?)\s*,\s*(-?\d{1,3}(?:\.\d+)?)\s*$""")++    /**+     * A "lat,lon" (or "lat lon" via comma) coordinate query as+     * (lat, lon), or null when the text is not a plausible coordinate.+     * Ranges are validated, so a name containing digits never resolves here.+     */+    fun parseCoordinateQuery(query: String): Pair<Double, Double>? {+        val match = COORD_QUERY.matchEntire(query) ?: return null+        val lat = match.groupValues[1].toDoubleOrNull() ?: return null+        val lon = match.groupValues[2].toDoubleOrNull() ?: return null+        if (lat !in -90.0..90.0 || lon !in -180.0..180.0) return null+        return lat to lon+    }+}
maps/src/test/java/com/vayunmathur/maps/util/PoiIndexTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/PoiIndexTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/PoiIndexTest.ktindex a182b4a300..4f069605c0 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/PoiIndexTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/PoiIndexTest.kt@@ -587,17 +587,15 @@ class PoiIndexTest {     }      /**-     * The documented narrowing: a sorted index answers prefix questions, so a match in the-     * middle of a *word* is lost where the scan found it. Asserted rather than left to be-     * discovered, since it is the one thing the two paths disagree about.+     * The unified search answers substring questions on both paths: a match in the+     * middle of a *word* is found whether the word index or the scan answers.+     * (Previously the sorted index answered prefix questions only, so this+     * disagreed by path; the tiers closed that gap.)      */     @Test-    fun `a mid-word match is found by the scan but not by the index`() {-        val pois = listOf(Poi(377_749_000, -1_224_194_000, 1, "Pizza"))-        load(pois, sideFiles = false)+    fun `a mid-word match is found on both paths`() = bothPaths { sideFiles ->+        load(listOf(Poi(377_749_000, -1_224_194_000, 1, "Pizza")), sideFiles = sideFiles)         assertEquals(1, PoiIndex.searchByName("izza", 37.7749, -122.4194).size)-        load(pois, sideFiles = true)-        assertTrue(PoiIndex.searchByName("izza", 37.7749, -122.4194).isEmpty())     }      @Test