From 8abae60bf6081d18a3fe40df01b5217c44b92c27 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 6 Jan 2014 14:18:20 -0500 Subject: [PATCH] Query builder cleanup. - Moved colon processing to more logical location - Removed unreachable range generation code --- .../Backend/Solr/LuceneSyntaxHelper.php | 16 +++++++++++++++- .../VuFindSearch/Backend/Solr/QueryBuilder.php | 8 -------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php index 34b7c6598b1..dc16a17a548 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php @@ -437,7 +437,20 @@ class LuceneSyntaxHelper return $input; } - + + /** + * Normalize field specifications within the query. + * + * @param string $input String to normalize + * + * @return string + */ + protected function normalizeColons($input) + { + $input = preg_replace('/:+/', ':', $input); + $input = preg_replace('/(\:[:\s]+|[:\s]+:)/', ' ', $input); + return $input == ':' ? '' : $input; + } /** * Prepare input to be used in a SOLR query. * @@ -483,6 +496,7 @@ class LuceneSyntaxHelper $input = $this->normalizeBoosts($input); $input = $this->normalizeBracesAndBrackets($input); $input = $this->normalizeUnquotedText($input); + $input = $this->normalizeColons($input); // Remove surrounding slashes and whitespace -- these serve no purpose // and can cause problems. diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php index 02734b91e72..381b9bb804d 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php @@ -367,9 +367,6 @@ class QueryBuilder implements QueryBuilderInterface return $handler->getFilterQuery(); } - // Strip out any colons that are NOT part of a field specification: - $string = preg_replace('/(\:\s+|\s+:)/', ' ', $string); - // If the query already includes field specifications, we can't easily // apply it to other fields through our defined handlers, so we'll leave // it as-is: @@ -377,11 +374,6 @@ class QueryBuilder implements QueryBuilderInterface return $string; } - // Convert empty queries to return all values in a field: - if (empty($string)) { - $string = '[* TO *]'; - } - // If the query ends in a non-escaped question mark, the user may not really // intend to use the question mark as a wildcard -- let's account for that // possibility -- GitLab