#fuzzy-search #city #fuzzy #search #spellcheck


city-spellcheck is a library that gives city spelling corrections using a fuzzy search that takes distance from supplied gps coordinates into weighting

2 releases

0.1.1 Jan 24, 2019
0.1.0 Jan 24, 2019

#213 in Geospatial

MIT license

515 lines

City Spellcheck

Build Status MIT licensed Released API docs

This crate provides a library for spell correction of city names using a fuzzy search scoring system that has optional weighting for distance.

What that means is that if you supply your current GPS coordinates, then the spelling correction suggested results takes your current location heavily into account when scoring each potential match.

Currently only supports USA and Canada, working on expanding to other countries ASAP.


To use this library just add city-spellcheck to your Cargo.toml file:

city-spellcheck = "0.1.0"

Now you can use it:

use city_spellcheck::*;

To take a look at a very simple RESTful API (with only one route) that uses this library, check out the City-Spellcheck Web Api

Example Use Case

use city_spellcheck::*;

let mut cities = CityData::new();
let london = Coordinate::new(42.98339, -81.23304);

let results = cities.search("London", Some(london));
    format!("{:?}", results),
    "[FuzzyResult { city: \"London, ON, CA\", latitude: 42.98339, longitude: -81.23304, score: 1.0 }, FuzzyResult { city: \"London, OH, US\", latitude: 39.88645, longitude: -83.44825, score: 0.6252391 }, FuzzyResult { city: \"London, KY, US\", latitude: 37.12898, longitude: -84.08326, score: 0.6250727 }, FuzzyResult { city: \"Lemont, IL, US\", latitude: 41.67364, longitude: -88.00173, score: 0.52094036 }, FuzzyResult { city: \"Brant, ON, CA\", latitude: 43.1334, longitude: -80.34967, score: 0.5208334 }]");

Please explore the documentation to learn more. Nearly all useful methods are on the CityData struct.


~176K SLoC