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(
|
public function matchPerson(
|
||||||
Person $person,
|
Person $person,
|
||||||
float $precision = 0.15,
|
float $precision = 0.30,
|
||||||
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY,
|
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY,
|
||||||
bool $addYearComparison = false
|
bool $addYearComparison = false
|
||||||
) {
|
) {
|
||||||
@ -72,41 +72,50 @@ class SimilarPersonMatcher
|
|||||||
);
|
);
|
||||||
$query = $this->em->createQuery();
|
$query = $this->em->createQuery();
|
||||||
|
|
||||||
$dql = 'SELECT p from ChillPersonBundle:Person p '
|
$qb = $this->em->createQueryBuilder();
|
||||||
. ' WHERE ('
|
|
||||||
. ' SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= :precision '
|
$qb->select('p')
|
||||||
. ' ) '
|
->from(Person::class, 'p')
|
||||||
. ' AND p.center IN (:centers)';
|
->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) {
|
if ($person->getId() !== null) {
|
||||||
$dql .= ' AND p.id != :personId ';
|
$qb->andWhere($qb->expr()->neq('p.id', ':personId'));
|
||||||
$notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person);
|
|
||||||
|
|
||||||
$query->setParameter('personId', $person->getId());
|
$query->setParameter('personId', $person->getId());
|
||||||
|
|
||||||
|
$notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||||
|
|
||||||
if (count($notDuplicatePersons)) {
|
if (count($notDuplicatePersons)) {
|
||||||
$dql .= ' AND p.id not in (:notDuplicatePersons)';
|
$qb->andWhere($qb->expr()->notIn('p.id', ':notDuplicatePersons'));
|
||||||
$query->setParameter('notDuplicatePersons', $notDuplicatePersons);
|
$query->setParameter('notDuplicatePersons', $notDuplicatePersons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($orderBy) {
|
switch ($orderBy) {
|
||||||
case self::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL:
|
case self::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL:
|
||||||
$dql .= ' ORDER BY p.fullnameCanonical ASC ';
|
$qb->orderBy('p.fullnameCanonical', 'ASC');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY:
|
case self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY:
|
||||||
default:
|
default:
|
||||||
$dql .= ' ORDER BY SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) DESC ';
|
$qb->orderBy('SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName)))', 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $query
|
$qb
|
||||||
->setDQL($dql)
|
|
||||||
->setParameter('fullName', $this->personRender->renderString($person, []))
|
->setParameter('fullName', $this->personRender->renderString($person, []))
|
||||||
->setParameter('centers', $centers)
|
->setParameter('centers', $centers)
|
||||||
->setParameter('precision', $precision);
|
->setParameter('precision', $precision);
|
||||||
|
|
||||||
return $query->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user