Example usage for org.apache.lucene.search.spell SpellChecker F_WORD

List of usage examples for org.apache.lucene.search.spell SpellChecker F_WORD

Introduction

In this page you can find the example usage for org.apache.lucene.search.spell SpellChecker F_WORD.

Prototype

String F_WORD

To view the source code for org.apache.lucene.search.spell SpellChecker F_WORD.

Click Source Link

Document

Field name for each word in the ngram index.

Usage

From source file:prman.model.SpellCheckManager.java

License:Open Source License

public String getBestEnd(String begin, Locale loc) {
    String toReturn = null;/*from w  w  w  . j a v a 2s .c  o m*/

    SpellChecker sc = getSpellChecker(loc);
    try {
        if (sc == null || sc.exist(begin))
            return null;
        IndexSearcher searcher = new IndexSearcher(sc.getSpellIndex());

        int bestLength = begin.length() + 3;

        toReturn = getBestEnd(searcher, new WildcardQuery(new Term(SpellChecker.F_WORD, begin + "????")),
                bestLength);
        if (toReturn == null) {
            toReturn = getBestEnd(searcher, new WildcardQuery(new Term(SpellChecker.F_WORD, begin + "???")),
                    bestLength);
            if (toReturn == null) {
                toReturn = getBestEnd(searcher,
                        new WildcardQuery(new Term(SpellChecker.F_WORD, begin + "?????")), bestLength);
                if (toReturn == null) {
                    toReturn = getBestEnd(searcher, new PrefixQuery(new Term(SpellChecker.F_WORD, begin)),
                            bestLength);
                }
            }
        }
    } catch (Throwable _t) {
        Logger.getLogger(getClass().getName()).log(Level.WARNING, "Spell checker error", _t);
        toReturn = null;
    }

    return toReturn;
}

From source file:prman.model.SpellCheckManager.java

License:Open Source License

private String getBestEnd(IndexSearcher searcher, Query query, int bestLength) throws IOException {
    String toReturn = null;/*from ww  w. j a  va2s  .  c om*/
    Hits hits = searcher.search(query);
    int length = hits.length();
    for (int iCnt = 0; (toReturn == null || toReturn.length() != bestLength) && iCnt < length; iCnt++) {
        String word = hits.doc(iCnt).get(SpellChecker.F_WORD);
        if (toReturn == null || Math.abs(toReturn.length() - bestLength) > Math.abs(word.length() - bestLength))
            toReturn = word;
        // else if (!word.startsWith(begin))
        // System.out.print(word+", ");
    }
    return toReturn;
}