Tags and publishers can now be searched with normalized search. re #48, #49

这个提交包含在:
Sébastien Lucas 2014-05-12 21:36:31 +02:00
父节点 3661be17d1
当前提交 789fc5468e
共有 4 个文件被更改,包括 48 次插入18 次删除

查看文件

@ -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 ())
{

查看文件

@ -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 ())

二进制文件未显示。

查看文件

@ -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;