From 557203ac6abf5b72ff8061c9dee4f2dbd4fc820f Mon Sep 17 00:00:00 2001 From: kevgliss Date: Mon, 13 Nov 2023 08:37:00 -0800 Subject: [PATCH] Making search more reliable (#3967) Co-authored-by: Will Sheldon <114631109+wssheldon@users.noreply.github.com> Co-authored-by: David Whittaker Co-authored-by: David Whittaker <84562015+whitdog47@users.noreply.github.com> --- src/dispatch/database/service.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/dispatch/database/service.py b/src/dispatch/database/service.py index b01f20c0bf68..65ba1142b972 100644 --- a/src/dispatch/database/service.py +++ b/src/dispatch/database/service.py @@ -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))))