From 8a4da08a66f28987fa0cc8448a607e387d3eec2c Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Thu, 20 Mar 2025 22:07:54 -0600 Subject: [PATCH] Remove non-alphanumerics (except quotes) from search query That is, don't replace non-alphanumerics with a space. This matches the behavior of Formatter::RemoveDiacriticsAndNonalphanumerics(), which would be used here except that function would also remove quotes. We actually discussed not introducing spaces previously, but I made a mistake and didn't apply the same change to the user's search query: https://github.com/standardebooks/web/pull/470#discussion_r1929591492 This change fixes queries with compound words like: `Haycraft-Queen` and also fixes queries for authors with apostrophes: `O'Neill` No changes to existing DBs are necessary because they already have terms like `haycraftqueen` and `oneill` stored in `IndexableCollections` and `IndexableAuthors`. --- lib/Ebook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index ec051185..9cc757af 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -2333,7 +2333,7 @@ final class Ebook{ if($query !== null && $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))); + $query = trim(preg_replace('|[^a-zA-Z0-9" ]|ius', '', Formatter::RemoveDiacritics($query))); $whereCondition .= ' and match(e.IndexableText, e.Title, e.IndexableAuthors, e.IndexableCollections) against(?) '; $params[] = $query;