diff --git a/lib/Ebook.php b/lib/Ebook.php index a4143d20..d2d787fc 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -1152,51 +1152,6 @@ class Ebook{ return null; } - public function Contains(string $query): bool{ - // When searching an ebook, we search the title, alternate title, author(s), SE tags, series data, and LoC tags. - // Also, if the ebook is shorts or poetry, search the ToC as well. - - $searchString = $this->FullTitle ?? $this->Title; - - $searchString .= ' ' . $this->AlternateTitle; - - foreach($this->CollectionMemberships as $collectionMembership){ - $searchString .= ' ' . $collectionMembership->Collection->Name; - } - - foreach($this->Authors as $author){ - $searchString .= ' ' . $author->Name; - } - - foreach($this->Tags as $tag){ - $searchString .= ' ' . $tag->Name; - } - - foreach($this->LocSubjects as $subject){ - $searchString .= ' ' . $subject->Name; - } - - if($this->TocEntries !== null){ - foreach($this->TocEntries as $item){ - $searchString .= ' ' . $item; - } - } - - // Remove diacritics and non-alphanumeric characters - $searchString = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', Formatter::RemoveDiacritics($searchString))); - $query = trim(preg_replace('|[^a-zA-Z0-9 ]|ius', ' ', Formatter::RemoveDiacritics($query))); - - if($query == ''){ - return false; - } - - if(mb_stripos($searchString, $query) !== false){ - return true; - } - - return false; - } - public function GenerateJsonLd(): string{ $output = new stdClass(); $output->{'@context'} = 'https://schema.org'; diff --git a/lib/Library.php b/lib/Library.php index a11283e9..09062a73 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -429,23 +429,6 @@ class Library{ return $results; } - /** - * @return array - * @throws Exceptions\AppException - */ - public static function Search(string $query): array{ - $ebooks = Library::GetEbooks(); - $matches = []; - - foreach($ebooks as $ebook){ - if($ebook->Contains($query)){ - $matches[] = $ebook; - } - } - - return $matches; - } - /** * @return array */ diff --git a/www/ebooks/opensearch.php b/www/ebooks/opensearch.php index 3cea6b05..428a7d88 100644 --- a/www/ebooks/opensearch.php +++ b/www/ebooks/opensearch.php @@ -11,8 +11,8 @@ print(''); UTF-8 UTF-8 - - - + + + diff --git a/www/ebooks/opensearch.xml b/www/ebooks/opensearch.xml index 4e9e0ea6..18445fe0 100644 --- a/www/ebooks/opensearch.xml +++ b/www/ebooks/opensearch.xml @@ -8,8 +8,8 @@ UTF-8 UTF-8 - - - + + + diff --git a/www/feeds/atom/search.php b/www/feeds/atom/search.php index dd79db62..6c4e85df 100644 --- a/www/feeds/atom/search.php +++ b/www/feeds/atom/search.php @@ -5,9 +5,11 @@ $ebooks = []; try{ $query = HttpInput::Str(GET, 'query') ?? ''; + $startPage = HttpInput::Int(GET, 'page') ?? 1; + $count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; if($query !== ''){ - $ebooks = Library::Search($query); + $ebooks = Library::FilterEbooks($query, [], EbookSortType::Newest, $startPage, $count)['ebooks']; } } catch(\Exception){ diff --git a/www/feeds/opds/search.php b/www/feeds/opds/search.php index ab2071ab..0fcf5a79 100644 --- a/www/feeds/opds/search.php +++ b/www/feeds/opds/search.php @@ -5,9 +5,11 @@ $ebooks = []; try{ $query = HttpInput::Str(GET, 'query') ?? ''; + $startPage = HttpInput::Int(GET, 'page') ?? 1; + $count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; if($query !== ''){ - $ebooks = Library::Search($query); + $ebooks = Library::FilterEbooks($query, [], EbookSortType::Newest, $startPage, $count)['ebooks']; } } catch(\Exception){ diff --git a/www/feeds/rss/search.php b/www/feeds/rss/search.php index 9fac0ae7..be070929 100644 --- a/www/feeds/rss/search.php +++ b/www/feeds/rss/search.php @@ -5,9 +5,11 @@ $ebooks = []; try{ $query = HttpInput::Str(GET, 'query') ?? ''; + $startPage = HttpInput::Int(GET, 'page') ?? 1; + $count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; if($query !== ''){ - $ebooks = Library::Search($query); + $ebooks = Library::FilterEbooks($query, [], EbookSortType::Newest, $startPage, $count)['ebooks']; } } catch(\Exception){