Apache Solr open-source search software
LUCENE-1299: Properly handle when IndexReader is not null and Field is in the spell checker
Grant Ingersoll8c97e9b87ba2
diff --git a/CHANGES.txt b/CHANGES.txtindex 28b93ad8b48..b7315ab9c0c 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -117,6 +117,8 @@ Bug fixes11. LUCENE-1189: Fixed the QueryParser to handle escaped characters withinquoted terms correctly. (Tomer Gabel via Michael Busch)+12. LUCENE-1299: Fixed NPE in SpellChecker when IndexReader is not null and field is (Grant Ingersoll)+New features1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about a Token through the analysisdiff --git a/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java b/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.javaindex 9274b26c2cf..05972215aac 100755--- a/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java+++ b/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java@@ -224,7 +224,7 @@ public class SpellChecker {continue;}- if (ir != null) { // use the user index+ if (ir != null && field != null) { // use the user indexsugWord.freq = ir.docFreq(new Term(field, sugWord.string)); // freq in the index// don't suggest a word that is not present in the fieldif ((morePopular && goalFreq > sugWord.freq) || sugWord.freq < 1) {diff --git a/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java b/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.javaindex 169905fae97..763c76a3201 100755--- a/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java+++ b/contrib/spellchecker/src/test/org/apache/lucene/search/spell/TestSpellChecker.java@@ -109,6 +109,14 @@ public class TestSpellChecker extends TestCase {similar = spellChecker.suggestSimilar("tousand", 10, r, "field2", false);assertEquals(1, similar.length); // there is the term thousand in the field field2++ try {+ similar = spellChecker.suggestSimilar("tousand", 10, r, null, false);+ } catch (NullPointerException e) {+ assertTrue("threw an NPE, and it shouldn't have", false);+ }++}private void addwords(IndexReader r, String field) throws IOException {