Skip to content

Commit

Permalink
Search using postcode, not entire address
Browse files Browse the repository at this point in the history
This fixes #4.
  • Loading branch information
legoscia committed Apr 16, 2016
1 parent 1c14791 commit de740ea
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion firefox/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ function startListening(worker) {
worker.port.on("queryRestaurant", function(restaurant) {
//console.log(restaurant);

var url = "http://api.ratings.food.gov.uk/Establishments?name=" + encodeURIComponent(restaurant.name) + "&address=" + encodeURIComponent(restaurant.address);
var postcodeRegexp = /[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1} [0-9][A-Z]{2}/;
var postcodeIndex = restaurant.address.search(postcodeRegexp);
var address;
if (postcodeIndex === -1) {
// this should never happen
address = restaurant.address;
}
else {
address = restaurant.address.substring(postcodeIndex);
}
var url = "http://api.ratings.food.gov.uk/Establishments?name=" + encodeURIComponent(restaurant.name) + "&address=" + encodeURIComponent(address);
var rating = 0;
var ratingDate = '';

Expand Down

0 comments on commit de740ea

Please sign in to comment.