From 49be75b800559c8e1e07508e98b89fe8705cb2e4 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 2 Dec 2019 12:13:05 -0500
Subject: [PATCH] Fix spell check handling of numeric terms. (#1515)

- Thanks to Katy Earl for reporting the problem and proposing a fix.
---
 .../Backend/Solr/Response/Json/Spellcheck.php |  2 +-
 .../Solr/Response/Json/SpellcheckTest.php     | 21 ++++++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Response/Json/Spellcheck.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Response/Json/Spellcheck.php
index 12d1a70b449..d11dd237146 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Response/Json/Spellcheck.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/Response/Json/Spellcheck.php
@@ -165,7 +165,7 @@ class Spellcheck implements IteratorAggregate, Countable
      *
      * @return bool
      */
-    protected function contains($term)
+    protected function contains(string $term)
     {
         if ($this->terms->offsetExists($term)) {
             return true;
diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/Response/Json/SpellcheckTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/Response/Json/SpellcheckTest.php
index ffc63f597bc..4e7dcd3b3f8 100644
--- a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/Response/Json/SpellcheckTest.php
+++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Solr/Response/Json/SpellcheckTest.php
@@ -53,7 +53,8 @@ class SpellcheckTest extends TestCase
             [
                 ['this is a phrase', []],
                 ['foo', []],
-                ['foobar', []]
+                ['foobar', []],
+                ['1842', []],   // test numeric handling (can cause problems)
             ],
             'fake query'
         );
@@ -61,13 +62,27 @@ class SpellcheckTest extends TestCase
             [
                 ['is a', []],
                 ['bar', []],
-                ['foo bar', []]
+                ['foo bar', []],
+                ['1842', []],
+                ['1843', []]
             ],
             'fake query'
         );
         $s1->mergeWith($s2);
-        $this->assertCount(5, $s1);
+        $this->assertCount(7, $s1);
         $this->assertEquals($s2, $s1->getSecondary());
+        $this->assertEquals(
+            [
+                'this is a phrase' => [],
+                'foobar' => [],
+                'foo' => [],
+                'bar' => [],
+                'foo bar' => [],
+                '1842' => [],
+                '1843' => [],
+            ],
+            iterator_to_array($s1->getIterator())
+        );
     }
 
     /**
-- 
GitLab