Skip to content

Commit

Permalink
Allow FullText criterion to work with quoted text
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Jul 4, 2018
1 parent 0c87655 commit 729691d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ')';
Expand Down
16 changes: 10 additions & 6 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
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
===========

* 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.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 729691d

Please sign in to comment.