From 1c02eb23fdc7136616d0dc950be8dd12fff41626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 31 Jan 2022 10:41:08 +0100 Subject: [PATCH] fix user search --- .../Search/Entity/SearchUserApiProvider.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Search/Entity/SearchUserApiProvider.php b/src/Bundle/ChillMainBundle/Search/Entity/SearchUserApiProvider.php index 5c3c6b057..32c0a3b43 100644 --- a/src/Bundle/ChillMainBundle/Search/Entity/SearchUserApiProvider.php +++ b/src/Bundle/ChillMainBundle/Search/Entity/SearchUserApiProvider.php @@ -45,13 +45,15 @@ class SearchUserApiProvider implements SearchApiInterface $query ->setSelectKey('user') ->setSelectJsonbMetadata("jsonb_build_object('id', u.id)") - ->setSelectPertinence('GREATEST(SIMILARITY(LOWER(UNACCENT(?)), u.usernamecanonical), - SIMILARITY(LOWER(UNACCENT(?)), u.emailcanonical))', [$pattern, $pattern]) + ->setSelectPertinence('GREATEST(SIMILARITY(LOWER(UNACCENT(?)), u.label), + SIMILARITY(LOWER(UNACCENT(?)), u.usernamecanonical))', [$pattern, $pattern]) ->setFromClause('users AS u') - ->setWhereClauses('SIMILARITY(LOWER(UNACCENT(?)), u.usernamecanonical) > 0.15 - OR - SIMILARITY(LOWER(UNACCENT(?)), u.emailcanonical) > 0.15 - ', [$pattern, $pattern]); + ->setWhereClauses(' + SIMILARITY(LOWER(UNACCENT(?)), u.usernamecanonical) > 0.15 + OR u.usernamecanonical LIKE \'%\' || LOWER(UNACCENT(?)) || \'%\' + OR SIMILARITY(LOWER(UNACCENT(?)), LOWER(UNACCENT(u.label))) > 0.15 + OR u.label LIKE \'%\' || LOWER(UNACCENT(?)) || \'%\' + ', [$pattern, $pattern, $pattern, $pattern]); return $query; }