List of usage examples for org.apache.lucene.search.spell SpellChecker SpellChecker
public SpellChecker(Directory spellIndex, StringDistance sd, Comparator<SuggestWord> comparator) throws IOException
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; }/* www . ja v a2s . c o m*/ } 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; }