mirror of https://github.com/apache/lucene.git
LUCENE-1152 Fix for calling indexDictionary after clearIndex call
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@659013 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2175d84d64
commit
a379a67875
|
@ -95,6 +95,10 @@ Bug fixes
|
|||
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
|
||||
|
|
|
@ -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 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 @@ public class SpellChecker {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the internal IndexReader.
|
||||
*/
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue