From b2193043542009c7b300174ade84df9032f4ad12 Mon Sep 17 00:00:00 2001 From: Kevin Glisson Date: Fri, 10 Nov 2023 08:08:26 -0800 Subject: [PATCH] Making search more reliable --- 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))))