Modern Apps git

← Modern-Apps.git

news: Local matching no longer confuses subset-named regions

Commit
dfcf9e8d37a1f003b796613d2015f3aebca6def6
Author
Vayun Mathur <[email protected]>
When
2026-11-30 19:30 UTC (5 days ago)
Parents
8bf8443
Picking Virginia in the Local picker boosted West Virginia
sources to the front of the Local feed: region components were
compared by token-subset containment, so {virginia} matched
{west, virginia} (and {york} matched {new, york}, {hampshire}
matched {new, hampshire}). Every legitimate match in the catalog
(state pick vs its cities, city pick vs statewide outlet,
free-typed single place) only ever needs a whole shared component;
the subset branches served no real case.

Components now compare by exact token-set equality. New regression
test covers Virginia<->West Virginia both directions, York and
Hampshire, plus whole-component positives that must keep matching.
Article extraction, feed staleness, search ranking, story membership
(server storyId only) and language handling were audited and
cleared. Verified: :news:testDevUnitTest + :news:lint BUILD
SUCCESSFUL.

Diff

news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt b/news/src/main/java/com/vayunmathur/news/domain/LocalNews.ktindex adf877d6b6..c8e9435ce7 100644--- a/news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/LocalNews.kt@@ -28,19 +28,20 @@ object LocalNews {      * Rule: drop the trailing country component from both sides when a      * comma hierarchy is present (country alone is not local enough to      * boost), then a match is any remaining component of one side that-     * equals, or token-wise contains / is contained by, a component of-     * the other side. This makes "California" match both-     * "California, United States" and "Los Angeles, California, United-     * States", and "Los Angeles, California, United States" match the-     * statewide "California, United States" (its California component).+     * exactly equals a component of the other side. Components compare+     * as whole token sets, never by subset: "Virginia" must not match+     * "West Virginia", and "York" must not match "New York", however+     * many tokens they share. Exact equality still makes "California"+     * match both "California, United States" and "Los Angeles,+     * California, United States", and "Los Angeles, California, United+     * States" match the statewide "California, United States" (its+     * California component), because those share a whole component.      */     fun matches(sourceRegion: String?, location: String?): Boolean {         val chosen = specificComponents(location)         val region = specificComponents(sourceRegion)         if (chosen.isEmpty() || region.isEmpty()) return false-        return chosen.any { c ->-            region.any { r -> c == r || c.containsAll(r) || r.containsAll(c) }-        }+        return chosen.any { c -> region.any { r -> c == r } }     }      /**
news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt b/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.ktindex 9b24182c81..3b6bec9f94 100644--- a/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt+++ b/news/src/test/java/com/vayunmathur/news/domain/LocalNewsTest.kt@@ -59,6 +59,23 @@ class LocalNewsTest {         assertFalse(LocalNews.matches("California, United States", "  "))     } +    @Test fun tokenSubsetComponentsNeverMatchAcrossRegions() {+        // Regression: matching used to accept token-subset components, so+        // one region boosted a different region that merely shares tokens.+        // Both states are real catalog regions (statewide outlets).+        assertFalse(LocalNews.matches("West Virginia, United States", "Virginia"))+        assertFalse(LocalNews.matches("West Virginia, United States", "Virginia, United States"))+        assertFalse(LocalNews.matches("Virginia, United States", "West Virginia, United States"))+        // "York" (e.g. the English city) is not New York.+        assertFalse(LocalNews.matches("New York City, New York, United States", "York"))+        assertFalse(LocalNews.matches("New York, United States", "York"))+        assertFalse(LocalNews.matches("New Hampshire, United States", "Hampshire"))+        // Whole-component sharing still matches, in both directions.+        assertTrue(LocalNews.matches("New York, United States", "New York City, New York, United States"))+        assertTrue(LocalNews.matches("Virginia, United States", "Virginia"))+        assertTrue(LocalNews.matches("West Virginia, United States", "West Virginia"))+    }+     @Test fun catalogMatchingUsesSourceRegions() {         assertTrue(SourceCatalog.matchesLocalLocation("latimes", "California"))         assertTrue(SourceCatalog.matchesLocalLocation("calmatters", "Los Angeles, California, United States"))