mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
wip.. inject personSearch results in similaritySearch to avoid duplicates results
error message : --------------- [Semantical Error] line 0, col 13 near 'p.id) FROM ChillPersonBundle:Person': Error: 'p' is used outside the scope of its declaration.
This commit is contained in:
parent
99ca79d86e
commit
ecf3f541ef
@ -17,6 +17,7 @@ services:
|
||||
- "@security.token_storage"
|
||||
- "@chill.main.security.authorization.helper"
|
||||
- "@chill_main.paginator_factory"
|
||||
- '@chill.person.search_person'
|
||||
calls:
|
||||
- ['setContainer', ["@service_container"]]
|
||||
tags:
|
||||
|
@ -201,7 +201,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
|
||||
* @param array $terms
|
||||
* @return \Doctrine\ORM\QueryBuilder
|
||||
*/
|
||||
protected function createQuery(array $terms)
|
||||
public function createQuery(array $terms)
|
||||
{
|
||||
//get from cache
|
||||
$cacheKey = md5(serialize($terms));
|
||||
|
@ -50,6 +50,12 @@ class SimilarityPersonSearch extends AbstractSearch
|
||||
|
||||
const NAME = "person_similarity";
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PersonSearch
|
||||
*/
|
||||
private $personSearch;
|
||||
|
||||
|
||||
/**
|
||||
* SimilarityPersonSearch constructor.
|
||||
@ -58,17 +64,20 @@ class SimilarityPersonSearch extends AbstractSearch
|
||||
* @param TokenStorage $tokenStorage
|
||||
* @param AuthorizationHelper $helper
|
||||
* @param PaginatorFactory $paginatorFactory
|
||||
* @param PersonSearch $personSearch
|
||||
*/
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
TokenStorage $tokenStorage,
|
||||
AuthorizationHelper $helper,
|
||||
PaginatorFactory $paginatorFactory)
|
||||
PaginatorFactory $paginatorFactory,
|
||||
PersonSearch $personSearch)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->helper = $helper;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->personSearch = $personSearch;
|
||||
|
||||
// throw an error if user is not a valid user
|
||||
if (!$this->user instanceof \Chill\MainBundle\Entity\User) {
|
||||
@ -218,28 +227,42 @@ class SimilarityPersonSearch extends AbstractSearch
|
||||
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
|
||||
$qb->from('ChillPersonBundle:Person', 'p');
|
||||
$qb->from('ChillPersonBundle:Person', 'simi');
|
||||
|
||||
if ($terms['_default'] !== '') {
|
||||
$grams = explode(' ', $terms['_default']);
|
||||
|
||||
foreach($grams as $key => $gram) {
|
||||
$qb->andWhere(
|
||||
'SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:default_'.$key.'))) >= 0.15')
|
||||
$qb->andWhere('SIMILARITY(simi.fullnameCanonical, UNACCENT(LOWER(:default_'.$key.')) ) >= 0.15')
|
||||
->setParameter('default_'.$key, '%'.$gram.'%');
|
||||
}
|
||||
|
||||
///
|
||||
//dump($this->personSearch->createQuery($terms)->addSelect('p.id')->getDQL());
|
||||
|
||||
$qb->andWhere($qb->expr()
|
||||
->notIn(
|
||||
'simi.id',
|
||||
$this->personSearch->createQuery($terms)
|
||||
->select('p.id')
|
||||
->getDQL()
|
||||
)
|
||||
);
|
||||
|
||||
///
|
||||
}
|
||||
|
||||
//restraint center for security
|
||||
$reachableCenters = $this->helper->getReachableCenters($this->user,
|
||||
new Role('CHILL_PERSON_SEE'));
|
||||
$qb->andWhere($qb->expr()
|
||||
->in('p.center', ':centers'))
|
||||
->in('simi.center', ':centers'))
|
||||
->setParameter('centers', $reachableCenters)
|
||||
;
|
||||
|
||||
$this->_cacheQuery[$cacheKey] = $qb;
|
||||
|
||||
dump($qb->getDQL());
|
||||
return clone $qb;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user