From 3943205b58d5eb7d312586b49948d61abd6c8c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 27 Sep 2013 17:13:31 +0200 Subject: [PATCH] Change the search to look into tags and series (in addition to book title and author). re #34, #47, #78 --- base.php | 31 ++++++++++++++++++++++++------- book.php | 8 ++++++-- templates/default/header.html | 1 - 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/base.php b/base.php index be7c2bc..eecd77e 100644 --- a/base.php +++ b/base.php @@ -664,18 +664,26 @@ class PageRecentBooks extends Page class PageQueryResult extends Page { + const SCOPE_TAG = "tag"; + const SCOPE_SERIES = "series"; + const SCOPE_AUTHOR = "author"; + const SCOPE_BOOK = "book"; + public function InitializeContent () { global $config; $this->title = str_format (localize ("search.result"), $this->query); - $currentPage = getURLParam ("current", NULL); + $scope = getURLParam ("scope"); + + $crit = "%" . $this->query . "%"; + $bad = "QQQQQ"; // Special case when we are doing a search and no database is selected if (is_array ($config['calibre_directory']) && is_null (GetUrlParam (DB))) { $i = 0; foreach ($config['calibre_directory'] as $key => $value) { Base::clearDb (); - list ($array, $totalNumber) = Book::getBooksByQuery ($this->query, $this->n, $i); + list ($array, $totalNumber) = Book::getBooksByQuery (array ($crit, $crit, $crit, $crit), $this->n, $i); array_push ($this->entryArray, new Entry ($key, DB . ":query:{$i}", str_format (localize ("bookword", count($array)), count($array)), "text", array ( new LinkNavigation ("?" . DB . "={$i}&page=9&query=" . $this->query)))); @@ -683,14 +691,23 @@ class PageQueryResult extends Page } return; } - - switch ($currentPage) { - case Base::PAGE_ALL_AUTHORS : - case Base::PAGE_AUTHORS_FIRST_LETTER : + switch ($scope) { + case self::SCOPE_AUTHOR : $this->entryArray = Author::getAuthorsByStartingLetter ('%' . $this->query); break; + case self::SCOPE_TAG : + $this->entryArray = Tag::getAllTagsByQuery ($this->query); + break; + case self::SCOPE_SERIES : + $this->entryArray = Serie::getAllSeriesByQuery ($this->query); + break; + case self::SCOPE_BOOK : + list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery ( + array ($bad, $bad, $bad, $crit), $this->n); + break; default: - list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery ($this->query, $this->n); + list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery ( + array ($crit, $crit, $crit, $crit), $this->n); } } } diff --git a/book.php b/book.php index 09b1dc4..94fcf69 100644 --- a/book.php +++ b/book.php @@ -32,7 +32,11 @@ define ('SQL_BOOKS_BY_LANGUAGE', "select {0} from books_languages_link, books " define ('SQL_BOOKS_BY_CUSTOM', "select {0} from {2}, books " . SQL_BOOKS_LEFT_JOIN . " where {2}.book = books.id and {2}.{3} = ? {1} order by sort"); define ('SQL_BOOKS_QUERY', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " - where (exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or title like ?) {1} order by books.sort"); + where ( + exists (select null from authors, books_authors_link where book = books.id and author = authors.id and authors.name like ?) or + exists (select null from tags, books_tags_link where book = books.id and tag = tags.id and tags.name like ?) or + exists (select null from series, books_series_link on book = books.id and books_series_link.series = series.id and series.name like ?) or + title like ?) {1} order by books.sort"); define ('SQL_BOOKS_RECENT', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " where 1=1 {1} order by timestamp desc limit "); @@ -524,7 +528,7 @@ where data.book = books.id and data.id = ?'); } public static function getBooksByQuery($query, $n, $database = NULL) { - return self::getEntryArray (self::SQL_BOOKS_QUERY, array ("%" . $query . "%", "%" . $query . "%"), $n, $database); + return self::getEntryArray (self::SQL_BOOKS_QUERY, $query, $n, $database); } public static function getAllBooks() { diff --git a/templates/default/header.html b/templates/default/header.html index 13c981b..193a11d 100644 --- a/templates/default/header.html +++ b/templates/default/header.html @@ -17,7 +17,6 @@
- {{? it.databaseId != ""}}