Skip to content
Snippets Groups Projects
Commit 26bba845 authored by Eoin Kilfeather's avatar Eoin Kilfeather Committed by Demian Katz
Browse files

Improve standalone slash handling (#1182)

- Rather than eliminating standalone slashes, quote them. This still prevents syntax errors, but it causes less loss of information.
parent 056ab097
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment