Skip to content

Commit

Permalink
Merge pull request #356 from jangliss/Beta
Browse files Browse the repository at this point in the history
#355 Use built in encoding function for URI search string.
  • Loading branch information
mapomatic authored Dec 30, 2018
2 parents c4d5f5a + bfed6cc commit c2f62b4
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions WME-Place-Harmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,25 +418,24 @@

function buildSearchUrl(searchName, address) {
searchName = searchName
.replace(/&/g, '%26')
.replace(/[ \/]/g, '%20')
.replace(/[\/]/g, ' ')
.trim();
address = address
.replace(/No street, /, '')
.replace(/No address/, '')
.replace(/ /g, '%20')
.replace(/CR-/g, 'County%20Rd%20')
.replace(/SR-/g, 'State%20Hwy%20')
.replace(/US-/g, 'US%20Hwy%20')
.replace(/ CR /g, '%20County%20Rd%20')
.replace(/ SR /g, '%20State%20Hwy%20')
.replace(/ US /g, '%20US%20Hwy%20')
.replace(/$CR /g, 'County%20Rd%20')
.replace(/$SR /g, 'State%20Hwy%20')
.replace(/$US /g, 'US%20Hwy%20')
.replace(/CR-/g, 'County Rd ')
.replace(/SR-/g, 'State Hwy ')
.replace(/US-/g, 'US Hwy ')
.replace(/ CR /g, ' County Rd ')
.replace(/ SR /g, ' State Hwy ')
.replace(/ US /g, ' US Hwy ')
.replace(/$CR /g, 'County Rd ')
.replace(/$SR /g, 'State Hwy ')
.replace(/$US /g, 'US Hwy ')
.trim();

return 'http://www.google.com/search?q=' + searchName + (address.length > 0 ? ',%20' + address: '');
searchName = encodeURIComponent(searchName + (address.length > 0 ? ', ' + address: ''));
return 'http://www.google.com/search?q=' + searchName;
}

function openWebSearch() {
Expand Down Expand Up @@ -6328,30 +6327,28 @@
// Build a Google search url based on place name and address
function buildGLink(searchName,addr,HN) {
var searchHN = '', searchStreet = '', searchCity = '';
searchName = searchName.replace(/&/g, '%26');
searchName = searchName.replace(/[ \/]/g, '%20');
searchName = searchName.replace(/\//g, ' ');
if ('string' === typeof addr.street.name && addr.street.name !== null && addr.street.name !== '') {
searchStreet = addr.street.name + ',%20';
}
searchStreet = searchStreet.replace(/ /g, '%20');
searchStreet = searchStreet.replace(/CR-/g, 'County%20Rd%20');
searchStreet = searchStreet.replace(/SR-/g, 'State%20Hwy%20');
searchStreet = searchStreet.replace(/US-/g, 'US%20Hwy%20');
searchStreet = searchStreet.replace(/ CR /g, '%20County%20Rd%20');
searchStreet = searchStreet.replace(/ SR /g, '%20State%20Hwy%20');
searchStreet = searchStreet.replace(/ US /g, '%20US%20Hwy%20');
searchStreet = searchStreet.replace(/$CR /g, 'County%20Rd%20');
searchStreet = searchStreet.replace(/$SR /g, 'State%20Hwy%20');
searchStreet = searchStreet.replace(/$US /g, 'US%20Hwy%20');
searchStreet = addr.street.name + ', ';
}
searchStreet = searchStreet.replace(/CR-/g, 'County Rd ');
searchStreet = searchStreet.replace(/SR-/g, 'State Hwy ');
searchStreet = searchStreet.replace(/US-/g, 'US Hwy ');
searchStreet = searchStreet.replace(/ CR /g, ' County Rd ');
searchStreet = searchStreet.replace(/ SR /g, ' State Hwy ');
searchStreet = searchStreet.replace(/ US /g, ' US Hwy ');
searchStreet = searchStreet.replace(/$CR /g, 'County Rd ');
searchStreet = searchStreet.replace(/$SR /g, 'State Hwy ');
searchStreet = searchStreet.replace(/$US /g, 'US Hwy ');
if ('string' === typeof HN && searchStreet !== '') {
searchHN = HN + '%20';
searchHN = HN + ' ';
}
if ('string' === typeof addr.city.attributes.name && addr.city.attributes.name !== '') {
searchCity = addr.city.attributes.name + ',%20';
searchCity = addr.city.attributes.name + ', ';
}
searchCity = searchCity.replace(/ /g, '%20');

return 'http://www.google.com/search?q=' + searchName + (searchName ? ',%20' : '') + searchHN + searchStreet + searchCity + addr.state.name;
searchName = searchName + (searchName ? ', ' : '') + searchHN + searchStreet + searchCity + addr.state.name;
return 'http://www.google.com/search?q=' + encodeURIComponent(searchName);
} // END buildGLink function

// WME Category translation from Natural language to object language (Bank / Financial --> BANK_FINANCIAL)
Expand Down

0 comments on commit c2f62b4

Please sign in to comment.