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:
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, Zaragoza
Lagos de coronas, Madrid
After 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_contains is slow and imprecise.
start_with/end_with are faster, but data in the Address schema 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_source uses a googleplaceid prefix, which prevents effective searches.
- Additional
address_source entries must be saved in a start_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 suggestions
Questions:
- Thoughts on implementation approach?
- Will the team handle this or should I fix it?
- Recommendations for functions/implementation?
Thank you for your time!
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:
Test queries:
Proposed solution:
For every
itemfromsuggest, search the DB for string matches and augment the results.Example:
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_sourcewith sources formatted as:country, region, street, house.Modifications needed for
searchByGooglePlaceId:address_sourceuses agoogleplaceidprefix, which prevents effective searches.address_sourceentries must be saved in astart_with-compatible format.Pseudocode for
GoogleSuggestionProvider.js:Questions:
Thank you for your time!