diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php index b69955e4304b12692279721fe16974655f2fa99e..39c4ecbf140350c0054297eb103895067bcb9546 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/LuceneSyntaxHelper.php @@ -487,11 +487,21 @@ class LuceneSyntaxHelper { // Freestanding hyphens and slashes can cause problems: $lookahead = self::$insideQuotes; + // remove freestanding hyphens $input = preg_replace( - '/(\s+[-\/]$|\s+[-\/]\s+|^[-\/]\s+)' . $lookahead . '/', + '/(\s+[-]$|\s+[-]\s+|^[-]\s+)' . $lookahead . '/', + ' ', $input + ); + // wrap quotes on standalone slashes + $input = preg_replace( + '/(\s+[\/]\s+)' . $lookahead . '/', + ' "/" ', $input + ); + // remove trailing and leading slashes + $input = preg_replace( + '/(\s+[\/]$|^[\/]\s+)' . $lookahead . '/', ' ', $input ); - // A proximity of 1 is illegal and meaningless -- remove it: $input = preg_replace('/~1(\.0*)?$/', '', $input); $input = preg_replace('/~1(\.0*)?\s+' . $lookahead . '/', ' ', $input); diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/QueryBuilderTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/QueryBuilderTest.php index 3c7285b2ce1d1691518476ec5613953139d14dc8..30ea55f23d75edf133dc8ac0508224143e0b857b 100644 --- a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/QueryBuilderTest.php +++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/QueryBuilderTest.php @@ -75,10 +75,9 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase ['^10', '10'], // invalid boosts ['test^ test^6', 'test test6'], // invalid boosts ['test^1 test^2', 'test^1 test^2'], // valid boosts - ['this / that', 'this that'], // freestanding slash + ['this / that', 'this "/" that'], // freestanding slash ['/ this', 'this'], // leading slash ['title /', 'title'], // trailing slash - ['this - that', 'this that'], // freestanding hyphen ['- this', 'this'], // leading hyphen ['title -', 'title'], // trailing hyphen ['AND', 'and'], // freestanding operator