lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r659013 - in /lucene/java/trunk: CHANGES.txt contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
Date Thu, 22 May 2008 06:21:18 GMT
Author: otis
Date: Wed May 21 23:21:17 2008
New Revision: 659013

URL: http://svn.apache.org/viewvc?rev=659013&view=rev
Log:
LUCENE-1152 Fix for calling indexDictionary after clearIndex call

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=659013&r1=659012&r2=659013&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed May 21 23:21:17 2008
@@ -95,6 +95,10 @@
  8. 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 features
 
  1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about
a Token through the analysis

Modified: lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java?rev=659013&r1=659012&r2=659013&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
(original)
+++ lucene/java/trunk/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
Wed May 21 23:21:17 2008
@@ -72,7 +72,6 @@
   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 @@
    * @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 @@
    * @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 @@
    * @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 @@
     // close writer
     writer.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 @@
       }
     }
   }
-
-  /**
-   * Closes the internal IndexReader.
-   */
-  protected void finalize() throws Throwable {
-    try {
-      if (reader != null) {
-        reader.close();
-      }
-    } finally {
-      super.finalize();
-    }
-  }
 }



Mime
View raw message