From d7a28146d702cfffcc9a79b7c554d3cd43a754ea Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 10 May 2013 09:44:11 -0400
Subject: [PATCH] Resolving VUFIND-537 (out of range fuzzy search error).

---
 .../src/VuFindSearch/Backend/Solr/QueryBuilder.php         | 4 ++--
 .../src/VuFindTest/Backend/Solr/QueryBuilderTest.php       | 7 ++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
index 92c4fa22fe9..0e22e4a8c87 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
@@ -522,8 +522,8 @@ class QueryBuilder
         $input = preg_replace('/\s+-\s+' . $lookahead . '/', ' ', $input);
 
         // A proximity of 1 is illegal and meaningless -- remove it:
-        $input = preg_replace('/~1$/', '', $input);
-        $input = preg_replace('/~1\s+' . $lookahead . '/', ' ', $input);
+        $input = preg_replace('/~1(\.0*)?$/', '', $input);
+        $input = preg_replace('/~1(\.0*)?\s+' . $lookahead . '/', ' ', $input);
 
         // Remove empty parentheses outside of quotation marks -- these will
         // cause a fatal Solr error and should be ignored.
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 1c409d0e9a8..b4aa3d9046b 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
@@ -141,10 +141,15 @@ class QueryBuilderTest extends PHPUnit_Framework_TestCase
             array('title - sub', 'title sub'),      // freestanding hyphen
             array('"title - sub"', '"title - sub"'),// freestanding hyphen in quotes
             array('test~1', 'test'),                // meaningless proximity
+            array('test~1.', 'test'),               // meaningless proximity w/dec.
+            array('test~1.000', 'test'),            // meaningless proximity w/dec.
             array('test~1 fish', 'test fish'),      // meaningless proximity
+            array('test~1. fish', 'test fish'),     // meaningless proximity w/dec.
+            array('test~1.000 fish', 'test fish'),  // meaningless proximity w/dec.
             array('"test~1"', '"test~1"'),          // meaningless prox. in quotes
             array('test~0.9', 'test~0.9'),          // valid proximity
-            array('test~11', 'test~11'),            // illegal prox. (leave alone)
+            array('test~10', 'test~10'),            // illegal prox. (leave alone)
+            array('test~10 fish', 'test~10 fish'),  // illegal prox. (leave alone)
         );
         // @codingStandardsIgnoreEnd
 
-- 
GitLab