-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Hello team!
I'm experiencing an issue with the address service that uses the Google provider.
Expected behavior:
When entering a street name (e.g., Lagos de coronas), the service should return multiple houses from that street, including the street itself.
Problem with Google API:
Autocomplete requires users to start typing numbers (house numbers) and returns only up to 5 exact addresses.
Relevant references:
- StackOverflow: Autocomplete house number
- StackOverflow: Not returning street numbers
- Google Documentation
Test queries:
- With types:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Lagos%20de%20Coronas&key=[]&types=street_address - Without types (default):
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Lagos%20de%20Coronas&key=[]
Proposed solution:
For every item from suggest, search the DB for string matches and augment the results.
Example:
Query:
Lagos de coronas
Google’s response:
Lagos de coronas, ZaragozaLagos de coronas, MadridAfter DB search:
Lagos de coronas, Zaragoza(from Google)
Lagos de coronas, Zaragoza 1(from DB)Lagos de coronas, Zaragoza 2(from DB)Lagos de coronas, Zaragoza 3(from DB)Lagos de coronas, Madrid(from Google)
Lagos de coronas, Madrid 1(from DB)Lagos de coronas, Madrid 2(from DB)
DB search challenge:
address_containsis slow and imprecise.start_with/end_withare faster, but data in theAddressschema is normalized (e.g.,C. de los Lagos de Coronas, 23, 50011 Zaragoza, España), making it incompatible with direct searches for"Lagos de coronas".
Proposed fix:
Use address_source with sources formatted as: country, region, street, house.
Modifications needed for searchByGooglePlaceId:
- Currently,
address_sourceuses agoogleplaceidprefix, which prevents effective searches. - Additional
address_sourceentries must be saved in astart_with-compatible format.
Pseudocode for GoogleSuggestionProvider.js:
for (const suggestion of suggestions) {
const existedAddressSources = await AddressSource.getAll(context, {
source_starts_with: 'transformed suggestion to search',
})
if (existedAddressSources.length > 0) {
for (const existedSource of existedAddressSources) {
const existedAddress = await Address.getOne(context, { id: existedSource.address })
// index of suggestion, insert into suggestions
}
}
}
return suggestionsQuestions:
- Thoughts on implementation approach?
- Will the team handle this or should I fix it?
- Recommendations for functions/implementation?
Thank you for your time!