Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/case-id-route-reminder
Browse files Browse the repository at this point in the history
  • Loading branch information
wssheldon authored Dec 1, 2023
2 parents 160db31 + 919b6dd commit ae586c6
Show file tree
Hide file tree
Showing 5 changed files with 729 additions and 14 deletions.
18 changes: 10 additions & 8 deletions src/dispatch/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,22 @@ def search(*, query_str: str, query: Query, model: str, sort=False):
if not query_str.strip():
return query

search = []
if hasattr(search_model, "search_vector"):
vector = search_model.search_vector
query = query.filter(vector.op("@@")(func.tsq_parse(query_str)))
search.append(vector.op("@@")(func.tsq_parse(query_str)))

elif hasattr(search_model, "name"):
query = query.filter(
or_(
search_model.name.ilike(f"%{query_str}%"),
search_model.name == query_str,
)
if hasattr(search_model, "name"):
search.append(
search_model.name.ilike(f"%{query_str}%"),
)
else:
search.append(search_model.name == query_str)

if not search:
raise Exception(f"Search not supported for model: {model}")

query = query.filter(or_(*search))

if sort:
query = query.order_by(desc(func.ts_rank_cd(vector, func.tsq_parse(query_str))))

Expand Down
Loading

0 comments on commit ae586c6

Please sign in to comment.