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:

```
<?
require_once('/standardebooks.org/web/lib/Core.php');

$ebooks = Ebook::GetAll();

foreach($ebooks as $ebook){
        if($ebook->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();
        }
}
```
This commit is contained in:
Mike Colagrosso 2025-03-24 17:51:15 -06:00 committed by Alex Cabal
parent 8a4da08a66
commit 9202717a6b

View file

@ -1706,6 +1706,7 @@ final class Ebook{
} }
} }
$this->IndexableText = str_replace('-', ' ', $this->IndexableText);
$this->IndexableText = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableText); $this->IndexableText = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableText);
if($this->IndexableText == ''){ if($this->IndexableText == ''){
@ -1719,6 +1720,7 @@ final class Ebook{
$this->IndexableAuthors .= ' ' . $author->Name; $this->IndexableAuthors .= ' ' . $author->Name;
} }
$this->IndexableAuthors = str_replace('-', ' ', $this->IndexableAuthors);
$this->IndexableAuthors = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableAuthors); $this->IndexableAuthors = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableAuthors);
// Initialize `IndexableCollections`. // Initialize `IndexableCollections`.
@ -1728,6 +1730,7 @@ final class Ebook{
$this->IndexableCollections .= ' ' . $collectionMembership->Collection->Name; $this->IndexableCollections .= ' ' . $collectionMembership->Collection->Name;
} }
$this->IndexableCollections = str_replace('-', ' ', $this->IndexableCollections);
$this->IndexableCollections = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableCollections); $this->IndexableCollections = Formatter::RemoveDiacriticsAndNonalphanumerics($this->IndexableCollections);
if($this->IndexableCollections == ''){ if($this->IndexableCollections == ''){
@ -2332,6 +2335,8 @@ final class Ebook{
} }
if($query !== null && $query != ''){ 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. // 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))); $query = trim(preg_replace('|[^a-zA-Z0-9" ]|ius', '', Formatter::RemoveDiacritics($query)));