Catch rare exception when searching ebooks

This commit is contained in:
Alex Cabal 2024-11-28 12:10:53 -06:00
parent 3a3795bbbd
commit 347f166e8a

View file

@ -2008,26 +2008,38 @@ class Ebook{
$params[] = $query; $params[] = $query;
} }
$ebooksCount = Db::QueryInt(' try{
SELECT count(distinct e.EbookId) $ebooksCount = Db::QueryInt('
from Ebooks e SELECT count(distinct e.EbookId)
' . $joinContributors . ' from Ebooks e
' . $joinTags . ' ' . $joinContributors . '
' . $whereCondition . ' ' . $joinTags . '
', $params); ' . $whereCondition . '
', $params);
$params[] = $limit; $params[] = $limit;
$params[] = $offset; $params[] = $offset;
$ebooks = Db::Query(' $ebooks = Db::Query('
SELECT distinct e.* SELECT distinct e.*
from Ebooks e from Ebooks e
' . $joinContributors . ' ' . $joinContributors . '
' . $joinTags . ' ' . $joinTags . '
' . $whereCondition . ' ' . $whereCondition . '
order by ' . $orderBy . ' order by ' . $orderBy . '
limit ? limit ?
offset ?', $params, Ebook::class); offset ?', $params, Ebook::class);
}
catch(Exceptions\DatabaseQueryException $ex){
if(stripos($ex->getMessage(), 'General error: 191 Too many words in a FTS phrase or proximity search') !== false){
// This exception occurs when the search string is too long for MariaDB to handle.
$ebooksCount = 0;
$ebooks = [];
}
else{
throw $ex;
}
}
return ['ebooks' => $ebooks, 'ebooksCount' => $ebooksCount]; return ['ebooks' => $ebooks, 'ebooksCount' => $ebooksCount];
} }