Clean up restaurant name and city from Toast/order.online imports
Strip common suffixes like "Order pickup and delivery" and embedded street addresses from business names. Clean city field when it contains state/zip/country (e.g. "Santa Monica, CA 90405, USA" → "Santa Monica"). Fixes applied in both CFML parser and JS frontend as safety net. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
28c0de9f09
commit
977f2bf98e
2 changed files with 44 additions and 8 deletions
|
|
@ -2037,15 +2037,37 @@
|
|||
</cfif>
|
||||
</cfif>
|
||||
|
||||
<!--- Clean business name: strip address if it was embedded in the name --->
|
||||
<cfif structKeyExists(toastBusiness, "name") AND structKeyExists(toastBusiness, "address")>
|
||||
<cfset bizAddr1 = listFirst(toastBusiness.address, ",")>
|
||||
<cfif len(bizAddr1) AND findNoCase(bizAddr1, toastBusiness.name)>
|
||||
<cfset toastBusiness["name"] = trim(replaceNoCase(toastBusiness.name, bizAddr1, ""))>
|
||||
<!--- Clean business name: strip address and common ordering-site suffixes --->
|
||||
<cfif structKeyExists(toastBusiness, "name")>
|
||||
<cfset bizName = toastBusiness.name>
|
||||
|
||||
<!--- Strip common ordering-site suffixes (after dash/pipe/en-dash) --->
|
||||
<cfset bizName = reReplaceNoCase(bizName, "\s*[-|]+\s*(Order\s+(pickup|online|delivery|food)|Online\s+Order|Delivery\s*[&and]+\s*Takeout|Takeout\s*[&and]+\s*Delivery|Menu\s*[&and]+\s*Order).*$", "")>
|
||||
|
||||
<!--- Strip embedded address (addressLine1) from the name --->
|
||||
<cfif structKeyExists(toastBusiness, "addressLine1") AND len(toastBusiness.addressLine1)>
|
||||
<cfif findNoCase(toastBusiness.addressLine1, bizName)>
|
||||
<cfset bizName = trim(replaceNoCase(bizName, toastBusiness.addressLine1, ""))>
|
||||
</cfif>
|
||||
</cfif>
|
||||
<!--- Also strip leading/trailing dashes or pipes left over --->
|
||||
<cfset toastBusiness["name"] = trim(reReplace(toastBusiness.name, "[\-\|]+$", ""))>
|
||||
<cfset toastBusiness["name"] = trim(reReplace(toastBusiness.name, "^[\-\|]+", ""))>
|
||||
<!--- Also try the first part of the combined address field --->
|
||||
<cfif structKeyExists(toastBusiness, "address")>
|
||||
<cfset addrFirst = trim(listFirst(toastBusiness.address, ","))>
|
||||
<cfif len(addrFirst) AND findNoCase(addrFirst, bizName)>
|
||||
<cfset bizName = trim(replaceNoCase(bizName, addrFirst, ""))>
|
||||
</cfif>
|
||||
</cfif>
|
||||
|
||||
<!--- Strip leading/trailing dashes, pipes --->
|
||||
<cfset bizName = trim(reReplace(bizName, "[-|]+$", ""))>
|
||||
<cfset bizName = trim(reReplace(bizName, "^[-|]+", ""))>
|
||||
|
||||
<cfset toastBusiness["name"] = trim(bizName)>
|
||||
</cfif>
|
||||
|
||||
<!--- Clean city: if Toast embedded state/zip/country, take just the city name --->
|
||||
<cfif structKeyExists(toastBusiness, "city") AND findNoCase(",", toastBusiness.city)>
|
||||
<cfset toastBusiness["city"] = trim(listFirst(toastBusiness.city, ","))>
|
||||
</cfif>
|
||||
|
||||
<!--- Build parent/child category hierarchy if multiple menus --->
|
||||
|
|
|
|||
|
|
@ -2079,12 +2079,26 @@
|
|||
|
||||
console.log('Business data:', biz);
|
||||
|
||||
// Clean business name: strip ordering-site suffixes and embedded address
|
||||
let bizDisplayName = (biz.name || '').trim();
|
||||
bizDisplayName = bizDisplayName.replace(/\s*[-–—|]\s*(Order\s+(pickup|online|delivery|food)|Online\s+Order|Delivery\s*[&and]+\s*Takeout|Takeout\s*[&and]+\s*Delivery|Menu\s*[&and]+\s*Order).*$/i, '');
|
||||
if (biz.addressLine1 && bizDisplayName.toLowerCase().includes(biz.addressLine1.toLowerCase())) {
|
||||
bizDisplayName = bizDisplayName.replace(new RegExp(biz.addressLine1.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i'), '').trim();
|
||||
}
|
||||
bizDisplayName = bizDisplayName.replace(/[-–—|]+$/, '').replace(/^[-–—|]+/, '').trim();
|
||||
biz.name = bizDisplayName || biz.name;
|
||||
|
||||
// Parse address into components if it's a single string
|
||||
let addressLine1 = biz.addressLine1 || '';
|
||||
let city = biz.city || '';
|
||||
let state = biz.state || '';
|
||||
let zip = biz.zip || '';
|
||||
|
||||
// Clean city: if it contains commas (e.g. "Santa Monica, CA 90405, USA"), take just the city part
|
||||
if (city.includes(',')) {
|
||||
city = city.split(',')[0].trim();
|
||||
}
|
||||
|
||||
if (biz.address && !addressLine1) {
|
||||
console.log('Parsing address:', biz.address);
|
||||
|
||||
|
|
|
|||
Reference in a new issue