diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php index 016b7ccbaac780f8f1e960862f8578e6062d29e5..1175ab33433126d99a3cde1806130df11b8891db 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php @@ -547,6 +547,10 @@ class QueryBuilder implements QueryBuilderInterface $input = preg_replace($parenRegex, '', $input); } + // Remove surrounding slashes and whitespace -- these serve no purpose + // and can cause problems. + $input = trim($input, '/ '); + return $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 eeb4b82b371eed0410135d6e32ffe6824b05644f..d2a41ba6e60171ec2ae0b9e529697a4f1e98ee8e 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 @@ -136,7 +136,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase array("()", "*:*"), // empty parens array("((()))", "*:*"), // nested empty parens array("((())", "*:*"), // mismatched parens - array("this that ()", "this that "), // text mixed w/ empty parens + array("this that ()", "this that"), // text mixed w/ empty parens array('"()"', '"()"'), // empty parens in quotes array('title - sub', 'title sub'), // freestanding hyphen array('"title - sub"', '"title - sub"'),// freestanding hyphen in quotes @@ -154,6 +154,7 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase array('^10', '10'), // invalid boosts array('test^ test^6', 'test test6'), // invalid boosts array('test^1 test^2', 'test^1 test^2'),// valid boosts + array('title /', 'title'), // trailing slash ); // @codingStandardsIgnoreEnd