Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
alex75 committed Oct 24, 2024
1 parent fe4129a commit 7660de1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cads_catalogue_api_service/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
def apply_filters_typeahead(
session: sa.orm.Session,
chars: str,
search: sa.orm.Query | None,
search: sa.orm.Query | None = None,
portals: list[str] | None = None,
limit: int | None = None,
):
"""Apply filters to return words matching initial input characters, as suggestions for searching datasets.
Args:
session: sqlalchemy session object
chars: characters of the words to find
chars: initial characters of the words to find
search: current dataset query
portals: list of datasets portals to consider
limit: if specified, limit length of resulting words
Expand Down Expand Up @@ -71,17 +71,19 @@ def apply_filters_typeahead(
if limit is not None:
search = search.limit(limit) # type: ignore

# final sql should be something like:
# final sql for `apply_filters_typeahead(session, 'er', portals=['cams', 'c3s'], limit=10)`:
# SELECT suggestion FROM
# (
# SELECT unnest(array_agg(DISTINCT t.g)) AS suggestion FROM
# SELECT unnest(array_agg(distinct(t.g))) AS suggestion FROM
# (
# SELECT unnest(string_to_array(lower(title), ' ')) AS g FROM resources
# WHERE resources.hidden = true AND resources.portal IN ('cams', 'c3s')
# )
# as t
# ) as tt
# WHERE length(tt.suggestion) > 2 and tt.suggestion ilike 'er%' limit 10;
# AS t
# ) AS tt
# WHERE length(tt.suggestion) > 2 AND tt.suggestion ILIKE 'er%'
# ORDER BY tt.suggestion
# LIMIT 10;

return search

Expand Down

0 comments on commit 7660de1

Please sign in to comment.