From e5bc74d11db74c794aa41de2e7f5a6f99c76e65b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 31 Jan 2023 16:10:12 +0100 Subject: [PATCH] FIX [duplicates][birthdate] also verify duplication based on birthdate if available. Modified precision from .15 to .30 --- .../Search/SimilarPersonMatcher.php | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php index afbaee07e..b8209eaeb 100644 --- a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php +++ b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php @@ -62,7 +62,7 @@ class SimilarPersonMatcher public function matchPerson( Person $person, - float $precision = 0.15, + float $precision = 0.30, string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY, bool $addYearComparison = false ) { @@ -72,41 +72,50 @@ class SimilarPersonMatcher ); $query = $this->em->createQuery(); - $dql = 'SELECT p from ChillPersonBundle:Person p ' - . ' WHERE (' - . ' SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= :precision ' - . ' ) ' - . ' AND p.center IN (:centers)'; + $qb = $this->em->createQueryBuilder(); + + $qb->select('p') + ->from(Person::class, 'p') + ->where('SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= :precision') + ->andWhere($qb->expr()->in('p.center', ':centers')); + + if (null !== $person->getBirthdate()) { + $qb->andWhere($qb->expr()->orX( + $qb->expr()->eq('p.birthdate', ':personBirthdate'), + $qb->expr()->isNull('p.birthdate') + )); + + $qb->setParameter('personBirthdate', $person->getBirthdate()); + } if ($person->getId() !== null) { - $dql .= ' AND p.id != :personId '; - $notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person); - + $qb->andWhere($qb->expr()->neq('p.id', ':personId')); $query->setParameter('personId', $person->getId()); + $notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person); + if (count($notDuplicatePersons)) { - $dql .= ' AND p.id not in (:notDuplicatePersons)'; + $qb->andWhere($qb->expr()->notIn('p.id', ':notDuplicatePersons')); $query->setParameter('notDuplicatePersons', $notDuplicatePersons); } } switch ($orderBy) { case self::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL: - $dql .= ' ORDER BY p.fullnameCanonical ASC '; + $qb->orderBy('p.fullnameCanonical', 'ASC'); break; case self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY: default: - $dql .= ' ORDER BY SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) DESC '; + $qb->orderBy('SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName)))', 'DESC'); } - $query = $query - ->setDQL($dql) + $qb ->setParameter('fullName', $this->personRender->renderString($person, [])) ->setParameter('centers', $centers) ->setParameter('precision', $precision); - return $query->getResult(); + return $qb->getQuery()->getResult(); } }