Try to simplify a little the search.

This commit is contained in:
Sébastien Lucas 2014-01-02 12:23:04 +01:00
parent 61f3bdc928
commit dbe6dedd44

View file

@ -753,6 +753,37 @@ class PageQueryResult extends Page
return !is_null (getURLParam ("search")); return !is_null (getURLParam ("search"));
} }
private function searchByScope ($scope, $limit = FALSE) {
$n = $this->n;
$numberPerPage = NULL;
if ($limit) {
$n = 1;
$numberPerPage = 5;
}
switch ($scope) {
case self::SCOPE_BOOK :
$array = Book::getBooksByStartingLetter ('%' . $this->query, $n, NULL, $numberPerPage);
break;
case self::SCOPE_AUTHOR :
$array = Author::getAuthorsByStartingLetter ('%' . $this->query);
break;
case self::SCOPE_SERIES :
$array = Serie::getAllSeriesByQuery ($this->query);
break;
case self::SCOPE_TAG :
$array = Tag::getAllTagsByQuery ($this->query, $n, NULL, $numberPerPage);
break;
case self::SCOPE_PUBLISHER :
$array = Publisher::getAllPublishersByQuery ($this->query);
break;
default:
$array = Book::getBooksByQuery (
array ("all" => "%" . $this->query . "%"), $n);
}
return $array;
}
public function doSearchByCategory () { public function doSearchByCategory () {
$database = GetUrlParam (DB); $database = GetUrlParam (DB);
$out = array (); $out = array ();
@ -780,23 +811,7 @@ class PageQueryResult extends Page
if (in_array($key, getCurrentOption ('ignored_categories'))) { if (in_array($key, getCurrentOption ('ignored_categories'))) {
continue; continue;
} }
switch ($key) { $array = $this->searchByScope ($key, TRUE);
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;
}
$i = 0; $i = 0;
if (count ($array) == 2 && is_array ($array [0])) { if (count ($array) == 2 && is_array ($array [0])) {
@ -867,26 +882,12 @@ class PageQueryResult extends Page
$this->doSearchByCategory (); $this->doSearchByCategory ();
return; return;
} }
switch ($scope) {
case self::SCOPE_AUTHOR : $array = $this->searchByScope ($scope);
$this->entryArray = Author::getAuthorsByStartingLetter ('%' . $this->query); if (count ($array) == 2 && is_array ($array [0])) {
break; list ($this->entryArray, $this->totalNumber) = $array;
case self::SCOPE_TAG : } else {
list ($this->entryArray, $this->totalNumber) = Tag::getAllTagsByQuery ($this->query, -1); $this->entryArray = $array;
break;
case self::SCOPE_SERIES :
$this->entryArray = Serie::getAllSeriesByQuery ($this->query);
break;
case self::SCOPE_BOOK :
list ($this->entryArray, $this->totalNumber) = Book::getBooksByQuery (
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 ("all" => $crit), $this->n);
} }
} }
} }