similaritySearch works, without duplicate personSearch results

This commit is contained in:
Mat 2018-11-13 11:04:03 +01:00
parent 387d3b53c1
commit d118f60dc3

View File

@ -168,17 +168,18 @@ class SimilarityPersonSearch extends AbstractSearch
{ {
$qb = $this->createQuery($terms, 'search'); $qb = $this->createQuery($terms, 'search');
if ($options['simplify'] ?? false) { if ($options['simplify'] ?? false) {
$qb->select( $qb->select(
'p.id', 'sp.id',
$qb->expr()->concat( $qb->expr()->concat(
'p.firstName', 'sp.firstName',
$qb->expr()->literal(' '), $qb->expr()->literal(' '),
'p.lastName' 'sp.lastName'
).'AS text' ).'AS text'
); );
} else { } else {
$qb->select('p'); $qb->select('sp');
} }
$qb $qb
@ -188,8 +189,8 @@ class SimilarityPersonSearch extends AbstractSearch
//order by firstname, lastname //order by firstname, lastname
$qb $qb
->orderBy('p.firstName') ->orderBy('sp.firstName')
->addOrderBy('p.lastName'); ->addOrderBy('sp.lastName');
if ($options['simplify'] ?? false) { if ($options['simplify'] ?? false) {
return $qb->getQuery()->getResult(Query::HYDRATE_ARRAY); return $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
@ -204,7 +205,7 @@ class SimilarityPersonSearch extends AbstractSearch
$qb = $this->createQuery($terms); $qb = $this->createQuery($terms);
$qb->select('COUNT(p.id)'); $qb->select('COUNT(sp.id)');
return $qb->getQuery()->getSingleScalarResult(); return $qb->getQuery()->getSingleScalarResult();
} }
@ -227,8 +228,7 @@ class SimilarityPersonSearch extends AbstractSearch
$qb = $this->em->createQueryBuilder(); $qb = $this->em->createQueryBuilder();
$qb $qb ->select('sp')
->select('sp')
->from('ChillPersonBundle:Person', 'sp'); ->from('ChillPersonBundle:Person', 'sp');
if ($terms['_default'] !== '') { if ($terms['_default'] !== '') {
@ -239,24 +239,15 @@ class SimilarityPersonSearch extends AbstractSearch
->setParameter('default_'.$key, '%'.$gram.'%'); ->setParameter('default_'.$key, '%'.$gram.'%');
} }
///
/// Testé avec http://localhost:8001/fr/search?q=matthieu
/// personSearch: 1 result
/// similaritySearch: 6 results - 1 = 5 results
///
$subquery = $this->personSearch->createQuery($terms)
->addSelect('p.id');
$qb->andWhere($qb->expr() $qb->andWhere($qb->expr()
->notIn( ->notIn(
'sp.id', 'sp.id',
$subquery->getDQL() $this->personSearch
->createQuery($terms)
->addSelect('p.id')
->getDQL()
) )
); );
dump($subquery->getDQL());
dump($subquery->getQuery()->getResult());
///
} }
//restraint center for security //restraint center for security
@ -269,15 +260,7 @@ class SimilarityPersonSearch extends AbstractSearch
$this->_cacheQuery[$cacheKey] = $qb; $this->_cacheQuery[$cacheKey] = $qb;
dump($qb->getDQL());
dump($qb->getQuery()->getResult()); //////////// <---- le résultat attendu !!
return clone $qb; return clone $qb;
///
/// [Semantical Error] line 0, col 13 near 'p.id) FROM ChillPersonBundle:Person':
/// Error: 'p' is used outside the scope of its declaration.
///
} }
} }