if (curDiff < suggestionDistance) { suggestionDistance = curDiff; toRet = new LinkedList<String>(); toRet.add(curText); }
SpellSuggestQueryInfo.Suggestion sug = new SpellSuggestQueryInfo.Suggestion(); sug.mStr = curText; sug.mEditDist = curDiff; sug.mDocs = fuzzyEnum.docFreq(); toRet.add(sug);
    private List<String> suggestSpelling(String field, String token) throws ServiceException {        LinkedList<String> toRet = new LinkedList<String>();        token = token.toLowerCase();        try {            CountedIndexReader reader = this.getCountedIndexReader();            try {                IndexReader iReader = reader.getReader();                Term term = new Term(field, token);                int freq = iReader.docFreq(term);                int numDocs = iReader.numDocs();                if (freq == 0 && numDocs > 0) {//                  float frequency = ((float)freq)/((float)numDocs);//                  System.out.println("Term: "+token+" appears in "+frequency*100+"% of documents");                    int suggestionDistance = Integer.MAX_VALUE;                    FuzzyTermEnum fuzzyEnum = new FuzzyTermEnum(iReader, term, 0.5f, 1);                    if (fuzzyEnum != null) {                        do {                            Term cur = fuzzyEnum.term();                            if (cur != null) {                                String curText = cur.text();                                System.out.println("\tSUGGEST: "+curText+" ["+fuzzyEnum.docFreq()+" docs]");                                int curDiff = editDistance(curText, token, curText.length(), token.length());                                if (curDiff < suggestionDistance) {                                    suggestionDistance = curDiff;                                    toRet = new LinkedList<String>();                                    toRet.add(curText);                                }                            }                        } while(fuzzyEnum.next());                    }                }            } finally {                reader.release();            }        } catch (IOException e) {            throw ServiceException.FAILURE("Caught IOException opening index", e);        }        return toRet;    }