diff --git a/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php b/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php index 4144db6a0..a50d35cf2 100644 --- a/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php +++ b/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php @@ -93,12 +93,18 @@ class ThirdPartyApiSearch implements SearchApiInterface parent.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%') "; $whereArgs[] = [$str, $str, $str, $str]; - $pertinence[] = 'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized) + ' . - "(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int + " . + $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]; } }