fix: store multiple postal codes as array, not last-write-wins scalar#90
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #89.
Problem
_alternateNames[geoNameId]["post"]was a scalar, so cities with multiple ZIP codes inalternateNames.txtwould silently clobber all but the last entry. Paris, TX (geoNameId 4717560) has three ZIP codes — 75460, 75461, 75462 — but only 75462 was returned because it happened to be last in the dump.Fix
In
_parseGeoNamesAlternateNamesCsv: whenisoLanguage === 'post', accumulate entries into an array instead of overwriting:In
_lookUp: thealternateName.postfield is now an array of all ZIP codes, sorted alphabetically for a stable ordering. All ZIP codes are accessible to callers viaalternateName.post[].Notes on a true centroid approach
alternateNames.txtdoes not carry per-ZIP lat/lon centroids, so it isn't possible to pick the nearest ZIP to the query point using only data already loaded. A future enhancement could integrate GeoNames'postalCodes.txt(which does include lat/lon per ZIP) to implement genuine nearest-centroid selection. For now, exposing the full array is the honest and correct fix — callers get all ZIP codes rather than an arbitrary one.Backwards compatibility
alternateName.postchanges from a{altName, ...}object to an array of such objects for cities with multiple ZIP codes. Cities with a single ZIP code will now also have an array of length 1 for consistency. Callers readingalternateName.post.altNamewill need to update toalternateName.post[0].altName(or whichever index they need).