From 789fc5468e1a5581cbecfd2214a288d83965649f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 12 May 2014 21:36:31 +0200 Subject: [PATCH] Tags and publishers can now be searched with normalized search. re #48, #49 --- publisher.php | 10 +++--- tag.php | 2 +- test/BaseWithSomeBooks/metadata.db | Bin 195584 -> 195584 bytes test/pageTest.php | 54 ++++++++++++++++++++++------- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/publisher.php b/publisher.php index 12c31ad..e4ba8a2 100644 --- a/publisher.php +++ b/publisher.php @@ -76,13 +76,13 @@ order by publishers.name'); } public static function getAllPublishersByQuery($query) { - $result = parent::getDb ()->prepare('select publishers.id as id, publishers.name as name, count(*) as count -from publishers, books_publishers_link -where publishers.id = publisher and publishers.name like ? + $columns = "publishers.id as id, publishers.name as name, count(*) as count"; + $sql = 'select {0} from publishers, books_publishers_link +where publishers.id = publisher and upper (publishers.name) like ? group by publishers.id, publishers.name -order by publishers.name'); +order by publishers.name'; + list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), -1); $entryArray = array(); - $result->execute (array ('%' . $query . '%')); while ($post = $result->fetchObject ()) { diff --git a/tag.php b/tag.php index c3dfc92..feb14f1 100644 --- a/tag.php +++ b/tag.php @@ -64,7 +64,7 @@ order by tags.name'); public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { $columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count"; - $sql = 'select {0} from tags where tags.name like ? {1} order by tags.name'; + $sql = 'select {0} from tags where upper (tags.name) like ? {1} order by tags.name'; list ($totalNumber, $result) = parent::executeQuery ($sql, $columns, "", array ('%' . $query . '%'), $n, $database, $numberPerPage); $entryArray = array(); while ($post = $result->fetchObject ()) diff --git a/test/BaseWithSomeBooks/metadata.db b/test/BaseWithSomeBooks/metadata.db index f049dd257b89d931bd12bd304a4906af6845779f..ca8af4280c47d01d4b779ed1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GezfBs=NF$hflc|Z{33T7)NfbQ8AYHC(sh^G&bw4x5aJzQ zHGNPRi*?PN0xmvF!-ZiPr9OZ0uX)Ul8ycpCPZ;Y>9pUk&C417m-f_tukNBqH#_*uO zJW&;eyN><7NFu2j?<$i+HQqlGZHzUt_ggf|_hp3sn zvwZUnj2A@J!6oi^BU8`r!v<<-L5spI{g@~3%94IOLO%cly+l?3 diff --git a/test/pageTest.php b/test/pageTest.php index 7721820..cd6d0da 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -644,29 +644,46 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertFalse ($currentPage->ContainsBook ()); } - public function testPageSearch_WithAccentuatedCharacters () + + /** + * @dataProvider providerAccentuatedCharacters + */ + public function testPageSearch_WithAccentuatedCharacters ($query, $count, $content) { global $config; $page = Base::PAGE_OPENSEARCH_QUERY; - $query = "curée"; $qid = NULL; $n = "1"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - $this->assertEquals ("Search result for *curée*", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("Search result for *curée* in books", $currentPage->entryArray [0]->title); - $this->assertEquals ("1 book", $currentPage->entryArray [0]->content); + $this->assertEquals ("Search result for *$query*", $currentPage->title); + $this->assertCount ($count, $currentPage->entryArray); + if ($count > 0) { + $this->assertEquals ($content, $currentPage->entryArray [0]->content); + } $this->assertFalse ($currentPage->ContainsBook ()); } - public function testPageSearch_WithNormalizedSearch () + public function providerAccentuatedCharacters () + { + return array ( + array ("curée", 1, "1 book"), + array ("Émile zola", 1, "1 author"), + array ("émile zola", 0, NULL), // With standard search upper does not work with diacritics + array ("Littérature", 1, "1 tag"), + array ("Eugène Fasquelle", 1, "1 publisher") + ); + } + + /** + * @dataProvider providerNormalizedSearch + */ + public function testPageSearch_WithNormalizedSearch_Book ($query, $count, $content) { global $config; $page = Base::PAGE_OPENSEARCH_QUERY; - $query = "curee"; $qid = NULL; $n = "1"; $config ['cops_normalized_search'] = "1"; @@ -678,16 +695,29 @@ class PageTest extends PHPUnit_Framework_TestCase $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - $this->assertEquals ("Search result for *curee*", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("Search result for *curee* in books", $currentPage->entryArray [0]->title); - $this->assertEquals ("1 book", $currentPage->entryArray [0]->content); + $this->assertEquals ("Search result for *$query*", $currentPage->title); + $this->assertCount ($count, $currentPage->entryArray); + if ($count > 0) { + $this->assertEquals ($content, $currentPage->entryArray [0]->content); + } $this->assertFalse ($currentPage->ContainsBook ()); $config ['cops_normalized_search'] = "0"; Base::clearDb (); } + public function providerNormalizedSearch () + { + return array ( + array ("curee", 1, "1 book"), + array ("emile zola", 1, "1 author"), + array ("émile zola", 1, "1 author"), + array ("Litterature", 1, "1 tag"), + array ("Litterâture", 1, "1 tag"), + array ("Eugene Fasquelle", 1, "1 publisher") + ); + } + public function testAuthorSearch_ByName () { global $config;