Enable unaccent in search

- Add unaccent function to queries
- Adapt tests accordingly

refs #377
This commit is contained in:
Julien Fastré 2015-01-04 21:56:04 +01:00
parent e02a10fdfa
commit ff3b521998
2 changed files with 24 additions and 5 deletions

View File

@ -139,12 +139,12 @@ class PersonSearch extends AbstractSearch
$qb->from('ChillPersonBundle:Person', 'p');
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'].'%');
}
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'].'%');
}
@ -192,7 +192,7 @@ class PersonSearch extends AbstractSearch
foreach($grams as $key => $gram) {
$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.'%');
}
}

View File

@ -75,7 +75,6 @@ class PersonSearchTest extends WebTestCase
public function testFirstNameAccentued()
{
$this->markTestSkipped();
$crawlerSpecial = $this->generateCrawlerForSearch('@person firstname:manço');
$this->assertRegExp('/Manço/', $crawlerSpecial->text());
@ -109,7 +108,6 @@ class PersonSearchTest extends WebTestCase
public function testSearchByLastNameAccented()
{
$this->markTestSkipped();
$crawlerSpecial = $this->generateCrawlerForSearch('@person lastname:Gérard');
$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)
{
$client = $this->getAuthenticatedClient();