From 9202717a6b4d6f1bc7f107372e8c807db25377d8 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Mon, 24 Mar 2025 17:51:15 -0600 Subject: [PATCH] Add a special case for hyphens: Replace with space See #484 for details. By adding a special case for hyphens, users can search for these terms: `beta` to match `Alpha-Beta` `queen` to match `Haycraft-Queen` These searches also work as expected: `Alpha-Beta` `Alpha` `Haycraft-Queen` `Haycraft` I don't think these queries should work, and they do not: `AlphaBeta` `HaycraftQueen` This commit changes `IndexableText`, `IndexableAuthors`, and `IndexableCollections`, so existing DBs need an update. This will update all published books: ``` cd /standardebooks.org/ebooks for BOOK in $(find /standardebooks.org/ebooks -maxdepth 1 -type d) do tsp nice /standardebooks.org/web/scripts/deploy-ebook-to-www --verbose --no-build --no-images --no-recompose --no-epubcheck --no-feeds --no-bulk-downloads "$BOOK" done ``` And this PHP code will update placeholders: ``` IsPlaceholder()){ print('Saving ' . $ebook->Identifier . "\n"); // Need to force `Ebook::GetAllContributors()` to be called before `Ebook::Save()`. Otherwise, authors and translators will be deleted. $ebook->Authors; $ebook->Save(); } } ``` --- lib/Ebook.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Ebook.php b/lib/Ebook.php index 9cc757af..86ebf677 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -1706,6 +1706,7 @@ final class Ebook{ } } + $this->IndexableText = str_replace('-', ' ', $this->IndexableText); $this->IndexableText = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableText); if($this->IndexableText == ''){ @@ -1719,6 +1720,7 @@ final class Ebook{ $this->IndexableAuthors .= ' ' . $author->Name; } + $this->IndexableAuthors = str_replace('-', ' ', $this->IndexableAuthors); $this->IndexableAuthors = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableAuthors); // Initialize `IndexableCollections`. @@ -1728,6 +1730,7 @@ final class Ebook{ $this->IndexableCollections .= ' ' . $collectionMembership->Collection->Name; } + $this->IndexableCollections = str_replace('-', ' ', $this->IndexableCollections); $this->IndexableCollections = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableCollections); if($this->IndexableCollections == ''){ @@ -2332,6 +2335,8 @@ final class Ebook{ } if($query !== null && $query != ''){ + $query = str_replace('-', ' ', $query); + // Preserve quotes in the query so the user can enter, e.g., "war and peace" for an exact match. $query = trim(preg_replace('|[^a-zA-Z0-9" ]|ius', '', Formatter::RemoveDiacritics($query)));