Handle better search of multiple databases at once. Optimize a little typeahead search. re #34
This commit is contained in:
parent
caa46c50e3
commit
58c48a71a8
3 changed files with 53 additions and 22 deletions
52
book.php
52
book.php
|
@ -553,12 +553,12 @@ order by substr (upper (sort), 1, 1)");
|
|||
return $entryArray;
|
||||
}
|
||||
|
||||
public static function getBooksByStartingLetter($letter, $n) {
|
||||
return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n);
|
||||
public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) {
|
||||
return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage);
|
||||
}
|
||||
|
||||
public static function getEntryArray ($query, $params, $n, $database = NULL) {
|
||||
list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database);
|
||||
public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) {
|
||||
list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage);
|
||||
$entryArray = array();
|
||||
while ($post = $result->fetchObject ())
|
||||
{
|
||||
|
@ -582,30 +582,59 @@ function getJson ($complete = false) {
|
|||
$page = getURLParam ("page", Base::PAGE_INDEX);
|
||||
$query = getURLParam ("query");
|
||||
$search = getURLParam ("search");
|
||||
$multi = getURLParam ("multi");
|
||||
$qid = getURLParam ("id");
|
||||
$n = getURLParam ("n", "1");
|
||||
$database = GetUrlParam (DB);
|
||||
|
||||
if ($search) {
|
||||
$out = array ();
|
||||
$arrayTag = Tag::getAllTagsByQuery ($query);
|
||||
$arraySeries = Serie::getAllSeriesByQuery ($query);
|
||||
$arrayAuthor = Author::getAuthorsByStartingLetter ('%' . $query);
|
||||
list ($arrayBook, $totalNumber) = Book::getBooksByStartingLetter ('%' . $query, -1);
|
||||
$pagequery = Base::PAGE_OPENSEARCH_QUERY;
|
||||
|
||||
if (is_array ($config['calibre_directory']) && $multi === "1") {
|
||||
$i = 0;
|
||||
foreach ($config['calibre_directory'] as $key => $value) {
|
||||
Base::clearDb ();
|
||||
array_push ($out, array ("title" => $key,
|
||||
"class" => "tt-header",
|
||||
"navlink" => "index.php?db={$i}"));
|
||||
list ($array, $total) = Book::getBooksByStartingLetter ('%' . $query, 1, $i, 5);
|
||||
array_push ($out, array ("title" => str_format (localize("bookword", $total), $total),
|
||||
"class" => "",
|
||||
"navlink" => "index.php?page={$pagequery}&query={$query}&db={$i}&scope=book"));
|
||||
$i++;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$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) as $key => $array) {
|
||||
$i = 0;
|
||||
$pagequery = Base::PAGE_OPENSEARCH_QUERY;
|
||||
if (count($array) > 0) {
|
||||
if (count ($array) == 2 && is_array ($array [0])) {
|
||||
$total = $array [1];
|
||||
$array = $array [0];
|
||||
} else {
|
||||
$total = count($array);
|
||||
}
|
||||
if ($total > 0) {
|
||||
// Comment to help the perl i18n script
|
||||
// str_format (localize("bookword", count($array))
|
||||
// str_format (localize("authorword", count($array)
|
||||
// str_format (localize("seriesword", count($array)
|
||||
// str_format (localize("tagword", count($array)
|
||||
array_push ($out, array ("title" => str_format (localize("{$key}word", count($array)), count($array)),
|
||||
array_push ($out, array ("title" => str_format (localize("{$key}word", $total), $total),
|
||||
"class" => "tt-header",
|
||||
"navlink" => "index.php?page={$pagequery}&query={$query}&db={$database}&scope={$key}"));
|
||||
}
|
||||
|
@ -636,6 +665,7 @@ function getJson ($complete = false) {
|
|||
$out ["databaseId"] = GetUrlParam (DB, "");
|
||||
$out ["databaseName"] = Base::getDbName ();
|
||||
$out ["page"] = $page;
|
||||
$out ["multipleDatabase"] = Base::isMultipleDatabaseEnabled () ? 1 : 0;
|
||||
$out ["entries"] = $entries;
|
||||
$out ["isPaginated"] = 0;
|
||||
if ($currentPage->isPaginated ()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue