Skip to content

Commit

Permalink
Trigger autocomplete for 2 letter query if that is "US" (datacommonso…
Browse files Browse the repository at this point in the history
…rg#4730)

Autocomplete queries only trigger on 3+ letter words. With this change,
we add one exception, to trigger on a two letter word if that is "US"

US Triggers:  https://screenshot.googleplex.com/AzqxmiqBBr2ocVn
Other 2 letter words do not:
https://screenshot.googleplex.com/7tXxN8p34MT4SUU
Life expectancy in us: https://screenshot.googleplex.com/6k7WK2oiJqWedxK
  • Loading branch information
gmechali authored Nov 12, 2024
1 parent 0bce14d commit 8b7bdf7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions server/routes/shared_api/autocomplete/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
'place_dcid': 'asia'
}] + TWO_WORD_CUSTOM_PLACES

# Exceptions for the 3 letter trigger rule. These queries can trigger on only two letters.
TWO_LETTER_TRIGGERS = {"us"}


def find_queries(user_query: str) -> List[str]:
"""Extracts subqueries to send to the Google Maps Predictions API from the entire user input.
Expand All @@ -78,8 +81,9 @@ def find_queries(user_query: str) -> List[str]:
else:
cumulative = word

# Only send queries 3 characters or longer.
if (len(cumulative) >= MIN_CHARACTERS_PER_QUERY):
# Only send queries 3 characters or longer, except for the exceptions in TWO_LETTER_TRIGGERS.
if (len(cumulative) >= MIN_CHARACTERS_PER_QUERY or
(len(cumulative) == 2 and cumulative.lower() in TWO_LETTER_TRIGGERS)):
queries.append(cumulative)

# Start by running the longer queries.
Expand Down

0 comments on commit 8b7bdf7

Please sign in to comment.