From 347f166e8ac1da8b7717c5adadbc876ca0d51c08 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Thu, 28 Nov 2024 12:10:53 -0600 Subject: [PATCH] Catch rare exception when searching ebooks --- lib/Ebook.php | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index 35d6e9fc..6e5c9458 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -2008,26 +2008,38 @@ class Ebook{ $params[] = $query; } - $ebooksCount = Db::QueryInt(' - SELECT count(distinct e.EbookId) - from Ebooks e - ' . $joinContributors . ' - ' . $joinTags . ' - ' . $whereCondition . ' - ', $params); + try{ + $ebooksCount = Db::QueryInt(' + SELECT count(distinct e.EbookId) + from Ebooks e + ' . $joinContributors . ' + ' . $joinTags . ' + ' . $whereCondition . ' + ', $params); - $params[] = $limit; - $params[] = $offset; + $params[] = $limit; + $params[] = $offset; - $ebooks = Db::Query(' - SELECT distinct e.* - from Ebooks e - ' . $joinContributors . ' - ' . $joinTags . ' - ' . $whereCondition . ' - order by ' . $orderBy . ' - limit ? - offset ?', $params, Ebook::class); + $ebooks = Db::Query(' + SELECT distinct e.* + from Ebooks e + ' . $joinContributors . ' + ' . $joinTags . ' + ' . $whereCondition . ' + order by ' . $orderBy . ' + limit ? + 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]; }