diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
index 0e22e4a8c874fe36ca72b6422ec55f7326c2460f..9a218b5c377dac490d9f6b9cc00b4a2f420c657a 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
@@ -377,13 +377,13 @@ class QueryBuilder
         // 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
-        if (substr($query, -1) == '?' && substr($query, -2) != '\?') {
+        if (substr($string, -1) == '?' && substr($string, -2) != '\?') {
             // Make sure all question marks are properly escaped (first unescape
             // any that are already escaped to prevent double-escapes, then escape
             // all of them):
             $strippedQuery
-                = str_replace('?', '\?', str_replace('\?', '?', $query));
-            $query = "({$query}) OR (" . $strippedQuery . ")";
+                = str_replace('?', '\?', str_replace('\?', '?', $string));
+            $string = "({$string}) OR (" . $strippedQuery . ")";
         }
 
         return $handler
@@ -641,4 +641,4 @@ class QueryBuilder
         return array('from' => trim($matches[1]), 'to' => trim($matches[2]));
     }
 
-}
\ No newline at end of file
+}