Apache Lucene open-source search software
LUCENE-1152 Fix for calling indexDictionary after clearIndex call
Otis Gospodnetica379a6787596
diff --git a/CHANGES.txt b/CHANGES.txtindex 9401bdfcfbd..01f27396b22 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -95,6 +95,10 @@ Bug fixes8. LUCENE-1003: Stop RussianAnalyzer from removing numbers.(TUSUR OpenTeam, Dmitry Lihachev via Otis Gospodnetic)+ 9. LUCENE-1152: SpellChecker fix around clearIndex and indexDictionary+ methods, plus removal of IndexReader reference.+ (Naveen Belkale via Otis Gospodnetic)+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 3c77b7a684b..cab122fd22c 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@@ -72,7 +72,6 @@ public class SpellChecker {private float bStart = 2.0f;private float bEnd = 1.0f;- private IndexReader reader;private IndexSearcher searcher;// minimum score for hits generated by the spell checker query@@ -284,11 +283,12 @@ public class SpellChecker {* @throws IOException*/public void clearIndex() throws IOException {- if (IndexReader.isLocked(spellIndex)){- IndexReader.unlock(spellIndex);- }IndexWriter writer = new IndexWriter(spellIndex, null, true);writer.close();++ //close the old searcher+ searcher.close();+ searcher = new IndexSearcher(this.spellIndex);}/**@@ -298,10 +298,7 @@ public class SpellChecker {* @return true iff the word exists in the index*/public boolean exist(String word) throws IOException {- if (reader == null) {- reader = IndexReader.open(spellIndex);- }- return reader.docFreq(new Term(F_WORD, word)) > 0;+ return searcher.docFreq(new Term(F_WORD, word)) > 0;}/**@@ -310,11 +307,7 @@ public class SpellChecker {* @throws IOException*/public void indexDictionary(Dictionary dict) throws IOException {- if (IndexReader.isLocked(spellIndex)){- IndexReader.unlock(spellIndex);- }- IndexWriter writer = new IndexWriter(spellIndex, new WhitespaceAnalyzer(),- !IndexReader.indexExists(spellIndex));+ IndexWriter writer = new IndexWriter(spellIndex, true, new WhitespaceAnalyzer());writer.setMergeFactor(300);writer.setMaxBufferedDocs(150);@@ -338,12 +331,6 @@ public class SpellChecker {// close writerwriter.optimize();writer.close();- // close reader so it will be re-opened (and see the new content) when exist()- // is called the next time:- if (reader != null) {- reader.close();- reader = null;- }// also re-open the spell index to see our own changes when the next suggestion// is fetched:searcher.close();@@ -395,17 +382,4 @@ public class SpellChecker {}}}-- /**- * Closes the internal IndexReader.- */- protected void finalize() throws Throwable {- try {- if (reader != null) {- reader.close();- }- } finally {- super.finalize();- }- }}