From 729691d8e9f18ebe8e929847dc5d2614404527f7 Mon Sep 17 00:00:00 2001 From: gggeek Date: Wed, 4 Jul 2018 17:13:56 +0100 Subject: [PATCH] Allow FullText criterion to work with quoted text --- .../Gateway/CriterionHandler/FullText.php | 31 +++++++++++++------ WHATSNEW.md | 16 ++++++---- composer.json | 2 +- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Core/Persistence/eZFind/Content/Search/Common/Gateway/CriterionHandler/FullText.php b/Core/Persistence/eZFind/Content/Search/Common/Gateway/CriterionHandler/FullText.php index 04af1c1..3d71184 100644 --- a/Core/Persistence/eZFind/Content/Search/Common/Gateway/CriterionHandler/FullText.php +++ b/Core/Persistence/eZFind/Content/Search/Common/Gateway/CriterionHandler/FullText.php @@ -24,25 +24,38 @@ public function accept(Criterion $criterion) */ public function handle(CriteriaConverter $converter, Criterion $criterion) { - // Search for all - if (trim($criterion->value) == '*') { + $value = trim($criterion->value); + + if ($value == '*') { + // Pure wildcard query return 'ezf_df_text:*'; - } - $value = $this->escapeValue(trim($criterion->value)); + } else if (preg_match('/^".+"$/', $value)) { + // Quoted-string query: escape everything but the outher quotes + $value = '"' . $this->escapeValue(substr($value, 1, -1)) . '"'; + + } else if (preg_match('/(^\*|\*$)/', $value)) { + // Wildcard query: make the exacth match stronger than the wildcard + + // @bug we do not support wildcard chars in the middle of phrases + + $value = $this->escapeValue($value); - // Check if wildcard query - if ($value && $value != '*' && trim($value, '*') != $value) { // Escape spaces $value = str_replace(' ', '\\ ', $value); - // Un-escape wildcard + // wildcard match: un-escape wildcard char $wildcard = str_replace('\\*', '*', $value); - // Non-wildcard value - $value = trim($value, '\*'); + // Non-wildcard match + $value = trim($value, '*'); + $value = rtrim($value, '\\'); $value = $value . '^2 OR ' . $wildcard; + + } else { + // plain query + $value = $this->escapeValue($value); } return 'ezf_df_text:(' . $value . ')'; diff --git a/WHATSNEW.md b/WHATSNEW.md index 96b573e..6f706ac 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -1,8 +1,13 @@ -Version 1.3 (unreleased) -======================== +Version 1.3 +=========== * Improved: made it easier to change the default values for QueryHandler, EnableElevation and ForceElevation by - subclassing the SearchService + subclassing the SearchService + +* Improved: the FullText Criterion will now treat text surrounded by double quotes as meaning 'exact match', + while still doing its magic mangling for text beginning or ending with a wildcard character + +* Improved: declare compatibility with Kaliop Migrations bundle v5 Version 1.2 @@ -10,12 +15,11 @@ Version 1.2 * Changed: the SearchService will now throw exceptions by default when there is an error reported by eZFind in the communication to SOLR. - + You can disable this behaviour by altering symfony parameter `ezfind_search_engine.search_settings.throw_errors`. - + For the moment the exception thrown is a `Kaliop\EzFindSearchEngineBundle\Core\Base\Exception\eZFindException`; in the future we might be able to identify better the different error cases using subclasses thereof. - * BC: the constructor of the SearchService has changed signature. In case you had extended it, please revise your subclasses. diff --git a/composer.json b/composer.json index 5cc42af..b883698 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "ezsystems/ezfind-ls": "*" }, "require-dev": { - "kaliop/ezmigrationbundle": "~4.0", + "kaliop/ezmigrationbundle": "~4.0 || ~5.0", "phpunit/phpunit": "~4.0 || ~5.0", "codeclimate/php-test-reporter": "~0.4" },