optimize query for person

This commit is contained in:
2021-09-10 18:22:50 +02:00
parent 6bc83edfe9
commit f63d4fcfba
6 changed files with 82 additions and 25 deletions

View File

@@ -12,7 +12,6 @@ use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Security;
@@ -126,7 +125,7 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
).'AS text'
);
} else {
$qb->select('p');
$qb->select('sp');
}
$qb
@@ -254,18 +253,14 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
$grams = explode(' ', $pattern);
foreach($grams as $key => $gram) {
$qb->andWhere('SIMILARITY(sp.fullnameCanonical, UNACCENT(LOWER(:default_'.$key.')) ) >= 0.15')
$qb->andWhere('STRICT_WORD_SIMILARITY_OPS(:default_'.$key.', sp.fullnameCanonical) = TRUE')
->setParameter('default_'.$key, '%'.$gram.'%');
}
$qb->andWhere($qb->expr()
->notIn(
'sp.id',
$this->createSearchQuery($pattern)
->addSelect('p.id')
->getDQL()
)
);
// remove the perfect matches
$qb->andWhere($qb->expr()
->notLike('sp.fullnameCanonical', 'UNACCENT(LOWER(:not_default_'.$key.'))'))
->setParameter('not_default_'.$key, '%'.$gram.'%');
}
return $qb;
}