Add a new config item to ignore a category in search. Simplify the queries. re #123

This commit is contained in:
Sébastien Lucas 2013-12-08 21:01:17 +01:00
parent 21f31d92aa
commit 7ba85d150b
3 changed files with 56 additions and 19 deletions

View File

@ -745,14 +745,13 @@ class PageQueryResult extends Page
}
$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 (array ($crit, $crit, $crit, $crit, $crit), 1, $i, 1);
list ($array, $totalNumber) = Book::getBooksByQuery (array ("all" => $crit), 1, $i, 1);
array_push ($this->entryArray, new Entry ($key, DB . ":query:{$i}",
str_format (localize ("bookword", $totalNumber), $totalNumber), "text",
array ( new LinkNavigation ("?" . DB . "={$i}&page=9&query=" . $this->query))));
@ -772,14 +771,14 @@ class PageQueryResult extends Page
break;
case self::SCOPE_BOOK :
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery (
array ($bad, $bad, $bad, $bad, $crit), $this->n);
array ("book" => $crit), $this->n);
break;
case self::SCOPE_PUBLISHER :
$this->entryArray = Publisher::getAllPublishersByQuery ($this->query);
break;
default:
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery (
array ($crit, $crit, $crit, $crit, $crit), $this->n);
array ("all" => $crit), $this->n);
}
}
}

View File

@ -63,6 +63,8 @@ class Book extends Base {
const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY;
const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT;
const BAD_SEARCH = "QQQQQ";
public $id;
public $title;
public $timestamp;
@ -555,7 +557,24 @@ where data.book = books.id and data.id = ?');
}
public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
return self::getEntryArray (self::SQL_BOOKS_QUERY, $query, $n, $database, $numberPerPage);
global $config;
$i = 0;
$critArray = array ();
foreach (array ("author", "tag", "series", "publisher", "book") as $key) {
if (in_array($key, $config ['cops_ingored_search_scope']) ||
(!array_key_exists ($key, $query) && !array_key_exists ("all", $query))) {
$critArray [$i] = self::BAD_SEARCH;
}
else {
if (array_key_exists ($key, $query)) {
$critArray [$i] = $query [$key];
} else {
$critArray [$i] = $query ["all"];
}
}
$i++;
}
return self::getEntryArray (self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage);
}
public static function getBooks($n) {
@ -634,21 +653,28 @@ function getJson ($complete = false) {
return $out;
}
$arrayPublisher = Publisher::getAllPublishersByQuery ($query);
foreach (array ("book", "author", "series", "tag", "publisher") as $key) {
if (in_array($key, $config ['cops_ingored_search_scope'])) {
continue;
}
switch ($key) {
case "book" :
$array = Book::getBooksByStartingLetter ('%' . $query, 1, NULL, 5);
break;
case "author" :
$array = Author::getAuthorsByStartingLetter ('%' . $query);
break;
case "series" :
$array = Serie::getAllSeriesByQuery ($query);
break;
case "tag" :
$array = Tag::getAllTagsByQuery ($query, 1, NULL, 5);
break;
case "publisher" :
$array = Publisher::getAllPublishersByQuery ($query);
break;
}
$arrayTag = Tag::getAllTagsByQuery ($query, 1, NULL, 5);
$arraySeries = Serie::getAllSeriesByQuery ($query);
$arrayAuthor = Author::getAuthorsByStartingLetter ('%' . $query);
$arrayBook = Book::getBooksByStartingLetter ('%' . $query, 1, NULL, 5);
foreach (array ("book" => $arrayBook,
"author" => $arrayAuthor,
"series" => $arraySeries,
"tag" => $arrayTag,
"publisher" => $arrayPublisher) as $key => $array) {
$i = 0;
if (count ($array) == 2 && is_array ($array [0])) {
$total = $array [1];

View File

@ -234,3 +234,15 @@
* This item is used as regular expression so "." will force server side rendering for all devices
*/
$config['cops_server_side_render'] = "Kindle|EBRD1101|EBRD1201|cybook";
/*
* Specify the ignored categories with autocomplete search and standard search
* Meaning that if you don't want to search in publishers or tags just add them from the list
* Only accepted values :
* - author
* - book
* - series
* - tag
* - publisher
*/
$config ['cops_ingored_search_scope'] = array ();