diff --git a/author.php b/author.php index 5eb71df..a60ad2c 100644 --- a/author.php +++ b/author.php @@ -13,6 +13,7 @@ class Author extends Base { const AUTHOR_COLUMNS = "authors.id as id, authors.name as name, authors.sort as sort, count(*) as count"; const SQL_AUTHORS_BY_FIRST_LETTER = "select {0} from authors, books_authors_link where author = authors.id and upper (authors.sort) like ? group by authors.id, authors.name, authors.sort order by sort"; + const SQL_AUTHORS_FOR_SEARCH = "select {0} from authors, books_authors_link where author = authors.id and (upper (authors.sort) like ? or upper (authors.name) like ?) group by authors.id, authors.name, authors.sort order by sort"; const SQL_ALL_AUTHORS = "select {0} from authors, books_authors_link where author = authors.id group by authors.id, authors.name, authors.sort order by sort"; public $id; @@ -64,6 +65,10 @@ order by substr (upper (sort), 1, 1)'); return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); } + public static function getAuthorsForSearch($query) { + return self::getEntryArray (self::SQL_AUTHORS_FOR_SEARCH, array ($query . "%", $query . "%")); + } + public static function getAllAuthors() { return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); } diff --git a/base.php b/base.php index b7b8861..544046e 100644 --- a/base.php +++ b/base.php @@ -801,7 +801,7 @@ class PageQueryResult extends Page $array = Book::getBooksByStartingLetter ('%' . $this->query, $n, NULL, $numberPerPage); break; case self::SCOPE_AUTHOR : - $array = Author::getAuthorsByStartingLetter ('%' . $this->query); + $array = Author::getAuthorsForSearch ('%' . $this->query); break; case self::SCOPE_SERIES : $array = Serie::getAllSeriesByQuery ($this->query); diff --git a/test/pageTest.php b/test/pageTest.php index a7d3803..5afa5d3 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -681,6 +681,42 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertFalse ($currentPage->ContainsBook ()); } + public function testAuthorSearch_ByName () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $query = "Lewis Carroll"; + $_GET ["scope"] = "author"; + $qid = NULL; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *Lewis Carroll* in authors", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testAuthorSearch_BySort () + { + global $config; + $page = Base::PAGE_OPENSEARCH_QUERY; + $query = "Carroll, Lewis"; + $_GET ["scope"] = "author"; + $qid = NULL; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *Carroll, Lewis* in authors", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + public function testPageSearchScopeAuthors () { $page = Base::PAGE_OPENSEARCH_QUERY;