From ff3b521998898d1666a360e06039a60ed32a5891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 4 Jan 2015 21:56:04 +0100 Subject: [PATCH] Enable unaccent in search - Add unaccent function to queries - Adapt tests accordingly refs #377 --- Search/PersonSearch.php | 6 +++--- Tests/Search/PersonSearchTest.php | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Search/PersonSearch.php b/Search/PersonSearch.php index 98e7c19a4..3b7c40800 100644 --- a/Search/PersonSearch.php +++ b/Search/PersonSearch.php @@ -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.'%'); } } diff --git a/Tests/Search/PersonSearchTest.php b/Tests/Search/PersonSearchTest.php index 07cb1e825..20f1d3317 100644 --- a/Tests/Search/PersonSearchTest.php +++ b/Tests/Search/PersonSearchTest.php @@ -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();