(using docker-compose)
docker-compose run web npm install
docker-compose run web npm run indexer
docker-compose up
Webservice is now accessible at url http://YOUR_DOCKER_HOST:8080/suggestions
, you can access to a simple UI at `http://YOUR_DOCKER_HOST:8080
Launch test
docker-compose run web npm test
- Babeljs for ES6
- Elasticsearch to store and query city data, the script for indexing data is located in
app/indexer
, and could be launch usingnpm run indexer
- I configure elasticsearch score function to boost city with large population, and geolocation if provided
- I use circleci for CI https://circleci.com/gh/nchaulet/coding-challenge-backend-c
Problems:
- It's really hard to provide a score between 0 and 1 with elasticsearch so I quickly do a javascript score implementation using Dice's Coefficient, it could be improved using geo distance if a location is provided
Improvements:
- Elasticsearch score function could be tuned to be more relevant
- the project could be unit tested, in particular confidence and name formating function
Design an API endpoint that provides auto-complete suggestions for large cities. The suggestions should be restricted to cities in the USA and Canada with a population above 5000 people.
- the endpoint is exposed at
/suggestions
- the partial (or complete) search term is passed as a querystring parameter
q
- the caller's location can optionally be supplied via querystring parameters
latitude
andlongitude
to help improve relative scores - the endpoint returns a JSON response with an array of scored suggested matches
- the suggestions are sorted by descending score
- each suggestion has a score between 0 and 1 (inclusive) indicating confidence in the suggestion (1 is most confident)
- each suggestion has a name which can be used to disambiguate between similarly named locations
- each suggestion has a latitude and longitude
- all functional tests should pass (additional tests may be implemented as necessary).
- the final application should be deployed to Heroku.
- feel free to add more features if you like!
These responses are meant to provide guidance. The exact values can vary based on the data source and scoring algorithm
Near match
GET /suggestions?q=Londo&latitude=43.70011&longitude=-79.4163
{
"suggestions": [
{
"name": "London, ON, Canada",
"latitude": "42.98339",
"longitude": "-81.23304",
"score": 0.9
},
{
"name": "London, OH, USA",
"latitude": "39.88645",
"longitude": "-83.44825",
"score": 0.5
},
{
"name": "London, KY, USA",
"latitude": "37.12898",
"longitude": "-84.08326",
"score": 0.5
},
{
"name": "Londontowne, MD, USA",
"latitude": "38.93345",
"longitude": "-76.54941",
"score": 0.3
}
]
}
No match
GET /suggestions?q=SomeRandomCityInTheMiddleOfNowhere
{
"suggestions": []
}
- All code should be written in Javascript
- Mitigations to handle high levels of traffic should be implemented
- Work should be submitted as a pull-request to this repo
- Documentation and maintainability is a plus
- Geonames provides city lists Canada and the USA http://download.geonames.org/export/dump/readme.txt
- http://www.nodejs.org/
- http://ejohn.org/blog/node-js-stream-playground/
Begin by forking this repo and cloning your fork. GitHub has apps for Mac and Windows that make this easier.
Get started by installing nodejs.
For OS X users, use Homebrew and brew install nvm
Once that's done, from the project directory, run
nvm use
In the project directory run
npm install
The test suite can be run with
npm test
To start a local server run
PORT=3456 npm start
which should produce output similar to
Server running at http://127.0.0.1:2345/suggestions