mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
FIX [duplicates][birthdate] also verify duplication based on birthdate if available. Modified precision from .15 to .30
This commit is contained in:
parent
5c0d89a88b
commit
e5bc74d11d
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user