Skip to content

Improve address autocomplete: Augment Google suggestions with DB-stored addresses #6485

@paulo-rossy

Description

@paulo-rossy

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:

  1. With types:
    https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Lagos%20de%20Coronas&key=[]&types=street_address  
    
  2. 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:

  1. Thoughts on implementation approach?
  2. Will the team handle this or should I fix it?
  3. Recommendations for functions/implementation?

Thank you for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions