Skip to content

fix(geocode): index-load only supports the prebuilt cities15000 index#3883

Merged
jqnatividad merged 3 commits into
masterfrom
fix/geocode-index-load-prebuilt-15000
May 21, 2026
Merged

fix(geocode): index-load only supports the prebuilt cities15000 index#3883
jqnatividad merged 3 commits into
masterfrom
fix/geocode-index-load-prebuilt-15000

Conversation

@jqnatividad
Copy link
Copy Markdown
Collaborator

Summary

Only the cities15000 Geonames index is prebuilt and published to the qsv GitHub releases. The index-load numeric shortcut and its USAGE text, however, advertised 500, 1000, 5000 and 15000. As a result, qsv geocode index-load 5000 would pass validation and then fail with an opaque 404 download error.

This PR restricts the index-load numeric shortcut to 15000 only:

  • check_index_file() now rejects non-15000 numeric shortcuts early with a clear, actionable message.
  • load_engine_data() numeric branch narrowed to 15000.
  • USAGE docstrings (the index-* load description and the <index-file> argument) updated; docs/help/geocode.md regenerated.

The error messages point users at index-update --cities-url for other city sets (Geonames publishes cities500/1000/5000/15000.zip, so the --cities-url numeric shortcut for index-update remains valid and is unchanged).

Testing

  • cargo build --locked --bin qsv -F all_features — clean
  • cargo test --test tests -F all_features geocode — 46 passed, 26 ignored (MaxMind-license tests)
  • cargo clippy — no new warnings (one pre-existing unnecessary_unwrap warning in unrelated code at geocode.rs:2347 left untouched)

🤖 Generated with Claude Code

Only the cities15000 Geonames index is prebuilt and published to the
qsv GitHub releases. The index-load numeric shortcut and its USAGE text
incorrectly advertised 500/1000/5000 as well, so `index-load 5000` would
pass validation and then fail with an opaque 404 download error.

Restrict the numeric shortcut to 15000 in both check_index_file() and
load_engine_data(), returning a clear error that points users at
`index-update --cities-url` for other city sets. Update the USAGE
docstrings accordingly and regenerate docs/help/geocode.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 21, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity

Metric Results
Complexity 9

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Restructure the cityrecord selection in format_result() from an
`is_none()` check followed by `.unwrap()` into an `if let Some(...)`
match, swapping the branches accordingly. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns qsv geocode index-load behavior and documentation with what is actually published in qsv GitHub releases by restricting the numeric shortcut to the only prebuilt Geonames index (cities15000), and improves the suggest-path admin1 filtering control flow.

Changes:

  • Restrict index-load numeric shortcuts to 15000 with earlier, clearer validation errors.
  • Narrow the numeric-shortcut download branch in load_engine_data() to 15000 and update CLI USAGE/doc output accordingly.
  • Refactor search_index() suggest logic to avoid unwrap() when handling admin1_filter_list.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/cmd/geocode.rs Updates numeric-shortcut validation/download behavior for index-load and refactors suggest search filtering.
docs/help/geocode.md Regenerates help docs to reflect the updated index-load numeric shortcut behavior.

Comment thread src/cmd/geocode.rs Outdated
Comment thread src/cmd/geocode.rs
Comment thread src/cmd/geocode.rs
Addresses Copilot review on PR #3883:

- load_engine_data() detected the numeric shortcut from the file *stem*,
  so a real local file like `15000.rkyv` (stem `15000`) was treated as
  the download shortcut and silently overwritten. Only treat input as
  the shortcut when it has no file extension.
- load_engine_data() compared the raw stem string to "15000" while
  check_index_file() compared the parsed u16 to 15000, so `015000` was
  accepted by one and rejected by the other. Both now compare the
  parsed numeric value (against DEFAULT_GEONAMES_CITIES_INDEX), and the
  download URL uses the numeric value too.
- Add tests/test_geocode.rs coverage: index-load with a non-15000
  number fails with the actionable error, and a numeric-named .rkyv
  file is loaded (not overwritten by a download).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jqnatividad jqnatividad merged commit 276de55 into master May 21, 2026
16 of 17 checks passed
@jqnatividad jqnatividad deleted the fix/geocode-index-load-prebuilt-15000 branch May 21, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants