mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Enable unaccent in search
- Add unaccent function to queries - Adapt tests accordingly refs #377
This commit is contained in:
parent
e02a10fdfa
commit
ff3b521998
@ -139,12 +139,12 @@ class PersonSearch extends AbstractSearch
|
|||||||
$qb->from('ChillPersonBundle:Person', 'p');
|
$qb->from('ChillPersonBundle:Person', 'p');
|
||||||
|
|
||||||
if (array_key_exists('firstname', $terms)) {
|
if (array_key_exists('firstname', $terms)) {
|
||||||
$qb->andWhere($qb->expr()->like('LOWER(p.firstName)', ':firstname'))
|
$qb->andWhere($qb->expr()->like('UNACCENT(LOWER(p.firstName))', ':firstname'))
|
||||||
->setParameter('firstname', '%'.$terms['firstname'].'%');
|
->setParameter('firstname', '%'.$terms['firstname'].'%');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('lastname', $terms)) {
|
if (array_key_exists('lastname', $terms)) {
|
||||||
$qb->andWhere($qb->expr()->like('LOWER(p.lastName)', ':lastname'))
|
$qb->andWhere($qb->expr()->like('UNACCENT(LOWER(p.lastName))', ':lastname'))
|
||||||
->setParameter('lastname', '%'.$terms['lastname'].'%');
|
->setParameter('lastname', '%'.$terms['lastname'].'%');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class PersonSearch extends AbstractSearch
|
|||||||
|
|
||||||
foreach($grams as $key => $gram) {
|
foreach($grams as $key => $gram) {
|
||||||
$qb->andWhere($qb->expr()
|
$qb->andWhere($qb->expr()
|
||||||
->like('LOWER(CONCAT(p.firstName, \' \', p.lastName))', ':default_'.$key))
|
->like('UNACCENT(LOWER(CONCAT(p.firstName, \' \', p.lastName)))', ':default_'.$key))
|
||||||
->setParameter('default_'.$key, '%'.$gram.'%');
|
->setParameter('default_'.$key, '%'.$gram.'%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ class PersonSearchTest extends WebTestCase
|
|||||||
|
|
||||||
public function testFirstNameAccentued()
|
public function testFirstNameAccentued()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
|
||||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:manço');
|
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:manço');
|
||||||
|
|
||||||
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
|
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
|
||||||
@ -109,7 +108,6 @@ class PersonSearchTest extends WebTestCase
|
|||||||
|
|
||||||
public function testSearchByLastNameAccented()
|
public function testSearchByLastNameAccented()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
|
||||||
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:Gérard');
|
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:Gérard');
|
||||||
|
|
||||||
$this->assertRegExp('/Gérard/', $crawlerSpecial->text());
|
$this->assertRegExp('/Gérard/', $crawlerSpecial->text());
|
||||||
@ -175,6 +173,27 @@ class PersonSearchTest extends WebTestCase
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function testDefaultAccented()
|
||||||
|
{
|
||||||
|
$crawlerSpecial = $this->generateCrawlerForSearch('@person manço');
|
||||||
|
|
||||||
|
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
|
||||||
|
|
||||||
|
|
||||||
|
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person manco');
|
||||||
|
|
||||||
|
$this->assertRegExp('/Manço/', $crawlerNoSpecial->text());
|
||||||
|
|
||||||
|
$crawlerSpecial = $this->generateCrawlerForSearch('@person Étienne');
|
||||||
|
|
||||||
|
$this->assertRegExp('/Étienne/', $crawlerSpecial->text());
|
||||||
|
|
||||||
|
|
||||||
|
$crawlerNoSpecial = $this->generateCrawlerForSearch('@person etienne');
|
||||||
|
|
||||||
|
$this->assertRegExp('/Étienne/', $crawlerNoSpecial->text());
|
||||||
|
}
|
||||||
|
|
||||||
private function generateCrawlerForSearch($pattern)
|
private function generateCrawlerForSearch($pattern)
|
||||||
{
|
{
|
||||||
$client = $this->getAuthenticatedClient();
|
$client = $this->getAuthenticatedClient();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user