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');
if ($options['simplify'] ?? false) {
$qb->select(
'p.id',
'sp.id',
$qb->expr()->concat(
'p.firstName',
'sp.firstName',
$qb->expr()->literal(' '),
'p.lastName'
'sp.lastName'
).'AS text'
);
} else {
$qb->select('p');
$qb->select('sp');
}
$qb
@ -188,8 +189,8 @@ class SimilarityPersonSearch extends AbstractSearch
//order by firstname, lastname
$qb
->orderBy('p.firstName')
->addOrderBy('p.lastName');
->orderBy('sp.firstName')
->addOrderBy('sp.lastName');
if ($options['simplify'] ?? false) {
return $qb->getQuery()->getResult(Query::HYDRATE_ARRAY);
@ -204,7 +205,7 @@ class SimilarityPersonSearch extends AbstractSearch
$qb = $this->createQuery($terms);
$qb->select('COUNT(p.id)');
$qb->select('COUNT(sp.id)');
return $qb->getQuery()->getSingleScalarResult();
}
@ -227,8 +228,7 @@ class SimilarityPersonSearch extends AbstractSearch
$qb = $this->em->createQueryBuilder();
$qb
->select('sp')
$qb ->select('sp')
->from('ChillPersonBundle:Person', 'sp');
if ($terms['_default'] !== '') {
@ -239,24 +239,15 @@ class SimilarityPersonSearch extends AbstractSearch
->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()
->notIn(
'sp.id',
$subquery->getDQL()
$this->personSearch
->createQuery($terms)
->addSelect('p.id')
->getDQL()
)
);
dump($subquery->getDQL());
dump($subquery->getQuery()->getResult());
///
}
//restraint center for security
@ -269,15 +260,7 @@ class SimilarityPersonSearch extends AbstractSearch
$this->_cacheQuery[$cacheKey] = $qb;
dump($qb->getDQL());
dump($qb->getQuery()->getResult()); //////////// <---- le résultat attendu !!
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.
///
}
}