Index: modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java =================================================================== --- modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java (revision 1302782) +++ modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java (working copy) @@ -43,6 +43,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.spell.Dictionary.SuggestCheckWords; import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; @@ -511,27 +512,28 @@ boolean isEmpty = termsEnums.isEmpty(); try { - BytesRefIterator iter = dict.getWordsIterator(); - BytesRef currentTerm; + Iterator iter = dict.getWordsIterator(); + SuggestCheckWords currentTerm; terms: while ((currentTerm = iter.next()) != null) { - - String word = currentTerm.utf8ToString(); - int len = word.length(); + + String suggestWord = currentTerm.getSuggestWord().utf8ToString(); + String checkWord = currentTerm.getCheckWord(); + int len = checkWord != null ? checkWord.length() : suggestWord.length(); if (len < 3) { continue; // too short we bail but "too long" is fine... } if (!isEmpty) { for (TermsEnum te : termsEnums) { - if (te.seekExact(currentTerm, false)) { + if (te.seekExact(currentTerm.getSuggestWord(), false)) { continue terms; } } } // ok index the word - Document doc = createDocument(word, getMin(len), getMax(len)); + Document doc = createDocument(suggestWord, checkWord, getMin(len), getMax(len)); writer.addDocument(doc); } } finally { @@ -571,13 +573,13 @@ return 2; } - private static Document createDocument(String text, int ng1, int ng2) { + private static Document createDocument(String suggestText, String checkText, int ng1, int ng2) { Document doc = new Document(); // the word field is never queried on... its indexed so it can be quickly // checked for rebuild (and stored for retrieval). Doesn't need norms or TF/pos - Field f = new Field(F_WORD, text, StringField.TYPE_STORED); + Field f = new Field(F_WORD, suggestText, StringField.TYPE_STORED); doc.add(f); // orig term - addGram(text, doc, ng1, ng2); + addGram(checkText == null ? suggestText : checkText, doc, ng1, ng2); return doc; } Index: modules/suggest/src/java/org/apache/lucene/search/spell/Dictionary.java =================================================================== --- modules/suggest/src/java/org/apache/lucene/search/spell/Dictionary.java (revision 1302782) +++ modules/suggest/src/java/org/apache/lucene/search/spell/Dictionary.java (working copy) @@ -17,8 +17,10 @@ */ import java.io.IOException; -import org.apache.lucene.util.BytesRefIterator; +import java.util.Iterator; +import org.apache.lucene.util.BytesRef; + /** * A simple interface representing a Dictionary. A Dictionary * here is just a list of words. @@ -31,5 +33,13 @@ * Return all words present in the dictionary * @return Iterator */ - BytesRefIterator getWordsIterator() throws IOException; + Iterator getWordsIterator() throws IOException; + + public static class SuggestCheckWords { + BytesRef suggestWord; + String checkWord; + + public BytesRef getSuggestWord(){ return suggestWord; } + public String getCheckWord(){ return checkWord; } + } }