Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Improved searching for users using spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjeerd committed Apr 29, 2016
1 parent 9be1faa commit e5ce327
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/AppBundle/Manager/MembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ public function findMemberships(
$qb = $this->doctrine->getRepository('AppBundle:UserInGroup')->createQueryBuilder('ug');

if (!empty($query)) {
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->like('u.firstName', ':query'),
$qb->expr()->like('u.lastName', ':query'),
$qb->expr()->like('u.loginName', ':query')
)
);

$qb->setParameter('query', '%' . $query . '%');
$terms = explode(' ', $query);

foreach ($terms as $i => $term) {
$qb->andWhere(
$qb->expr()->orX(
$qb->expr()->like('u.firstName', ':term' . $i),
$qb->expr()->like('u.lastName', ':term' . $i),
$qb->expr()->like('u.loginName', ':term' . $i)
)
);

$qb->setParameter('term' . $i, '%' . $term . '%');
}
}

if (!empty($users)) {
Expand Down
4 changes: 2 additions & 2 deletions src/AppBundle/Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function findUsers($query = null, $sort = 'reference', $offset = 0, $limi
}

if (!empty($query)) {
$terms = explode(' ', '%' . $query . '%');
$terms = explode(' ', $query);

foreach ($terms as $i => $term) {
$qb->andWhere(
Expand All @@ -81,7 +81,7 @@ public function findUsers($query = null, $sort = 'reference', $offset = 0, $limi
)
);

$qb->setParameter('term' . $i, $term);
$qb->setParameter('term' . $i, '%' . $term . '%');
}
}

Expand Down

0 comments on commit e5ce327

Please sign in to comment.