Skip to content

Commit

Permalink
Making search more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss committed Nov 10, 2023
1 parent 67b5581 commit b219304
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/dispatch/database/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,13 @@ def search(*, query_str: str, query: Query, model: str, sort=False):

vector = search_model.search_vector

# determine if we have a name and use it for exact matching
# TODO we could make the exact match field configurable in the future
# Also include searches formatted as "-xxxx" for Jira-created ticket names
if hasattr(search_model, "name"):
query = query.filter(
or_(
vector.op("@@")(func.tsq_parse(query_str)),
search_model.name == query_str,
vector.op("@@")(f"-{query_str}"),
)
query = query.filter(
or_(
vector.op("@@")(func.tsq_parse(query_str)),
search_model.name.ilike(f"%{query_str}%"),
search_model.name == query_str,
)
else:
query = query.filter(vector.op("@@")(func.tsq_parse(query_str)))
)

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

0 comments on commit b219304

Please sign in to comment.