Example usage for org.apache.lucene.search.spell SuggestWordQueue DEFAULT_COMPARATOR

List of usage examples for org.apache.lucene.search.spell SuggestWordQueue DEFAULT_COMPARATOR

Introduction

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

Prototype

Comparator DEFAULT_COMPARATOR

To view the source code for org.apache.lucene.search.spell SuggestWordQueue DEFAULT_COMPARATOR.

Click Source Link

Document

Default comparator: score then frequency.

Usage

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

License:Apache License

@Override
public String init(NamedList config, SolrCore core) {
    super.init(config, core);
    indexDir = (String) config.get(INDEX_DIR);
    String accuracy = (String) config.get(ACCURACY);
    //If indexDir is relative then create index inside core.getDataDir()
    if (indexDir != null) {
        if (!new File(indexDir).isAbsolute()) {
            indexDir = core.getDataDir() + File.separator + indexDir;
        }/*from  www  . j a  va  2 s  .c om*/
    }
    sourceLocation = (String) config.get(LOCATION);
    String compClass = (String) config.get(COMPARATOR_CLASS);
    Comparator<SuggestWord> comp = null;
    if (compClass != null) {
        if (compClass.equalsIgnoreCase(SCORE_COMP)) {
            comp = SuggestWordQueue.DEFAULT_COMPARATOR;
        } else if (compClass.equalsIgnoreCase(FREQ_COMP)) {
            comp = new SuggestWordFrequencyComparator();
        } else {//must be a FQCN
            comp = (Comparator<SuggestWord>) core.getResourceLoader().newInstance(compClass, Comparator.class);
        }
    } else {
        comp = SuggestWordQueue.DEFAULT_COMPARATOR;
    }
    String strDistanceName = (String) config.get(STRING_DISTANCE);
    if (strDistanceName != null) {
        sd = core.getResourceLoader().newInstance(strDistanceName, StringDistance.class);
        //TODO: Figure out how to configure options.  Where's Spring when you need it?  Or at least BeanUtils...
    } else {
        sd = new LevensteinDistance();
    }
    try {
        initIndex();
        spellChecker = new SpellChecker(index, sd, comp);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    if (accuracy != null) {
        try {
            this.accuracy = Float.parseFloat(accuracy);
            spellChecker.setAccuracy(this.accuracy);
        } catch (NumberFormatException e) {
            throw new RuntimeException("Unparseable accuracy given for dictionary: " + name, e);
        }
    }
    return name;
}

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

License:Apache License

@Override
public String init(NamedList config, SolrCore core) {
    LOG.info("init: " + config);
    String name = super.init(config, core);

    Comparator<SuggestWord> comp = SuggestWordQueue.DEFAULT_COMPARATOR;
    String compClass = (String) config.get(COMPARATOR_CLASS);
    if (compClass != null) {
        if (compClass.equalsIgnoreCase(SCORE_COMP))
            comp = SuggestWordQueue.DEFAULT_COMPARATOR;
        else if (compClass.equalsIgnoreCase(FREQ_COMP))
            comp = new SuggestWordFrequencyComparator();
        else //must be a FQCN
            comp = (Comparator<SuggestWord>) core.getResourceLoader().newInstance(compClass, Comparator.class);
    }/*from   w  w  w. j  av  a2 s. com*/

    StringDistance sd = DirectSpellChecker.INTERNAL_LEVENSHTEIN;
    String distClass = (String) config.get(STRING_DISTANCE);
    if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE))
        sd = core.getResourceLoader().newInstance(distClass, StringDistance.class);

    float minAccuracy = DEFAULT_ACCURACY;
    Float accuracy = (Float) config.get(ACCURACY);
    if (accuracy != null)
        minAccuracy = accuracy;

    int maxEdits = DEFAULT_MAXEDITS;
    Integer edits = (Integer) config.get(MAXEDITS);
    if (edits != null)
        maxEdits = edits;

    int minPrefix = DEFAULT_MINPREFIX;
    Integer prefix = (Integer) config.get(MINPREFIX);
    if (prefix != null)
        minPrefix = prefix;

    int maxInspections = DEFAULT_MAXINSPECTIONS;
    Integer inspections = (Integer) config.get(MAXINSPECTIONS);
    if (inspections != null)
        maxInspections = inspections;

    float minThreshold = DEFAULT_THRESHOLD_TOKEN_FREQUENCY;
    Float threshold = (Float) config.get(THRESHOLD_TOKEN_FREQUENCY);
    if (threshold != null)
        minThreshold = threshold;

    int minQueryLength = DEFAULT_MINQUERYLENGTH;
    Integer queryLength = (Integer) config.get(MINQUERYLENGTH);
    if (queryLength != null)
        minQueryLength = queryLength;

    float maxQueryFrequency = DEFAULT_MAXQUERYFREQUENCY;
    Float queryFreq = (Float) config.get(MAXQUERYFREQUENCY);
    if (queryFreq != null)
        maxQueryFrequency = queryFreq;

    checker.setComparator(comp);
    checker.setDistance(sd);
    checker.setMaxEdits(maxEdits);
    checker.setMinPrefix(minPrefix);
    checker.setAccuracy(minAccuracy);
    checker.setThresholdFrequency(minThreshold);
    checker.setMaxInspections(maxInspections);
    checker.setMinQueryLength(minQueryLength);
    checker.setMaxQueryFrequency(maxQueryFrequency);
    checker.setLowerCaseTerms(false);

    return name;
}

From source file:org.dice.solrenhancements.spellchecker.DiceDirectSolrSpellChecker.java

License:Apache License

@Override
public String init(NamedList config, SolrCore core) {
    LOG.info("init: " + config);
    String name = super.init(config, core);

    Comparator<SuggestWord> comp = SuggestWordQueue.DEFAULT_COMPARATOR;
    String compClass = (String) config.get(COMPARATOR_CLASS);
    if (compClass != null) {
        if (compClass.equalsIgnoreCase(SCORE_COMP))
            comp = SuggestWordQueue.DEFAULT_COMPARATOR;
        else if (compClass.equalsIgnoreCase(FREQ_COMP))
            comp = new SuggestWordFrequencyComparator();
        else //must be a FQCN
            comp = (Comparator<SuggestWord>) core.getResourceLoader().newInstance(compClass, Comparator.class);
    }/*  w ww  .  ja v a2  s  .c  om*/

    characterEncoding = DEFAULT_SOURCE_FILE_CHAR_ENCODING;
    String charEncoding = (String) config.get(SOURCE_FILE_CHAR_ENCODING);
    if (charEncoding != null && charEncoding.length() != 0) {
        characterEncoding = charEncoding;
    }

    StringDistance sd = DirectSpellChecker.INTERNAL_LEVENSHTEIN;
    String distClass = (String) config.get(STRING_DISTANCE);
    if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE))
        sd = core.getResourceLoader().newInstance(distClass, StringDistance.class);

    float minAccuracy = DEFAULT_ACCURACY;
    Float accuracy = (Float) config.get(ACCURACY);
    if (accuracy != null)
        minAccuracy = accuracy;

    int maxEdits = DEFAULT_MAXEDITS;
    Integer edits = (Integer) config.get(MAXEDITS);
    if (edits != null)
        maxEdits = edits;

    int minPrefix = DEFAULT_MINPREFIX;
    Integer prefix = (Integer) config.get(MINPREFIX);
    if (prefix != null)
        minPrefix = prefix;

    int maxInspections = DEFAULT_MAXINSPECTIONS;
    Integer inspections = (Integer) config.get(MAXINSPECTIONS);
    if (inspections != null)
        maxInspections = inspections;

    float minThreshold = DEFAULT_THRESHOLD_TOKEN_FREQUENCY;
    Float threshold = (Float) config.get(THRESHOLD_TOKEN_FREQUENCY);
    if (threshold != null)
        minThreshold = threshold;

    int minQueryLength = DEFAULT_MINQUERYLENGTH;
    Integer queryLength = (Integer) config.get(MINQUERYLENGTH);
    if (queryLength != null)
        minQueryLength = queryLength;

    float maxQueryFrequency = DEFAULT_MAXQUERYFREQUENCY;
    Float queryFreq = (Float) config.get(MAXQUERYFREQUENCY);
    if (queryFreq != null)
        maxQueryFrequency = queryFreq;

    Object oTyposFileName = config.get(TYPOS_FILENAME_CFG);
    if (oTyposFileName != null) {
        this.typosFile = oTyposFileName.toString();
    }

    checker.setComparator(comp);
    checker.setDistance(sd);
    checker.setMaxEdits(maxEdits);
    checker.setMinPrefix(minPrefix);
    checker.setAccuracy(minAccuracy);
    checker.setThresholdFrequency(minThreshold);
    checker.setMaxInspections(maxInspections);
    checker.setMinQueryLength(minQueryLength);
    checker.setMaxQueryFrequency(maxQueryFrequency);
    checker.setLowerCaseTerms(false);

    return name;
}