Example usage for org.apache.lucene.search.spell NGramDistance NGramDistance

List of usage examples for org.apache.lucene.search.spell NGramDistance NGramDistance

Introduction

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

Prototype

public NGramDistance() 

Source Link

Document

Creates an N-Gram distance measure using n-grams of size 2.

Usage

From source file:org.apache.solr.spelling.ConjunctionSolrSpellCheckerTest.java

License:Apache License

@Test
public void test() throws Exception {
    ConjunctionSolrSpellChecker cssc = new ConjunctionSolrSpellChecker();
    MockSolrSpellChecker levenstein1 = new MockSolrSpellChecker(new LevensteinDistance());
    MockSolrSpellChecker levenstein2 = new MockSolrSpellChecker(new LevensteinDistance());
    MockSolrSpellChecker ngram = new MockSolrSpellChecker(new NGramDistance());

    cssc.addChecker(levenstein1);//from w w w .  j av  a 2s .c  o  m
    cssc.addChecker(levenstein2);
    try {
        cssc.addChecker(ngram);
        fail("ConjunctionSolrSpellChecker should have thrown an exception about non-identical StringDistances.");
    } catch (IllegalArgumentException iae) {
        // correct behavior
    }
}

From source file:org.elasticsearch.search.suggest.phrase.DirectCandidateGeneratorBuilder.java

License:Apache License

private static StringDistance resolveDistance(String distanceVal) {
    distanceVal = distanceVal.toLowerCase(Locale.US);
    if ("internal".equals(distanceVal)) {
        return DirectSpellChecker.INTERNAL_LEVENSHTEIN;
    } else if ("damerau_levenshtein".equals(distanceVal) || "damerauLevenshtein".equals(distanceVal)) {
        return new LuceneLevenshteinDistance();
    } else if ("levenstein".equals(distanceVal)) {
        return new LevensteinDistance();
        // TODO Jaro and Winkler are 2 people - so apply same naming logic
        // as damerau_levenshtein
    } else if ("jarowinkler".equals(distanceVal)) {
        return new JaroWinklerDistance();
    } else if ("ngram".equals(distanceVal)) {
        return new NGramDistance();
    } else {/*from w  w  w .  j  av a  2  s  .c o  m*/
        throw new IllegalArgumentException("Illegal distance option " + distanceVal);
    }
}

From source file:org.elasticsearch.search.suggest.SuggestUtils.java

License:Apache License

public static StringDistance resolveDistance(String distanceVal) {
    if ("internal".equals(distanceVal)) {
        return DirectSpellChecker.INTERNAL_LEVENSHTEIN;
    } else if ("damerau_levenshtein".equals(distanceVal) || "damerauLevenshtein".equals(distanceVal)) {
        return new LuceneLevenshteinDistance();
    } else if ("levenstein".equals(distanceVal)) {
        return new LevensteinDistance();
        //TODO Jaro and Winkler are 2 people - so apply same naming logic as damerau_levenshtein  
    } else if ("jarowinkler".equals(distanceVal)) {
        return new JaroWinklerDistance();
    } else if ("ngram".equals(distanceVal)) {
        return new NGramDistance();
    } else {//from w  w w .j ava2 s.  com
        throw new ElasticsearchIllegalArgumentException("Illegal distance option " + distanceVal);
    }
}