diff --git a/CHANGELOG.md b/CHANGELOG.md index c1076ffd8..ab6f9d146 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [thirdparty] Extend the thirdparty search to thirdparty children (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/448) * [person]: AddPersons: allow creation of person or thirdparty only (no users) (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) * [person]: AddPersons: allow creation of person or thirdparty depending on allowed types (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) * [person]: AddPersons: add suggestion of name when creating new person or thirdparty (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422) diff --git a/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php b/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php index 994b9d65c..e4b7f43af 100644 --- a/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php +++ b/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php @@ -87,14 +87,24 @@ class ThirdPartyApiSearch implements SearchApiInterface foreach ($strs as $str) { if (!empty($str)) { $wheres[] = "(LOWER(UNACCENT(?)) <<% tparty.canonicalized OR - tparty.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%')"; - $whereArgs[] = [$str, $str]; - $pertinence[] = 'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized) + ' . - "(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int + " . + tparty.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%') + OR + (LOWER(UNACCENT(?)) <<% parent.canonicalized OR + parent.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%') + "; + $whereArgs[] = [$str, $str, $str, $str]; + $pertinence[] = 'GREATEST( + STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized), + STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), parent.canonicalized) + ) + ' . + "GREATEST( + (tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int, + (parent.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int + ) + " . // take postcode label into account, but lower than the canonicalized field "COALESCE((LOWER(UNACCENT(cmpc.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0) + " . "COALESCE((LOWER(UNACCENT(cmpc_p.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0)"; - $pertinenceArgs[] = [$str, $str, $str, $str]; + $pertinenceArgs[] = [$str, $str, $str, $str, $str, $str]; } }