if (initParams.getName(i).equals("spellchecker")) {
NamedList spellchecker = (NamedList) initParams.getVal(i);
String className = (String) spellchecker.get("classname");
if (className == null)
className = IndexBasedSpellChecker.class.getName();
SolrResourceLoader loader = core.getResourceLoader();
SolrSpellChecker checker = (SolrSpellChecker) loader.newInstance(className);
if (checker != null) {
String dictionary = checker.init(spellchecker, core);
if (dictionary != null) {
boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME);
if (isDefault == true && hasDefault == false){
hasDefault = true;
} else if (isDefault == true && hasDefault == true){
throw new RuntimeException("More than one dictionary is missing name.");
}
spellCheckers.put(dictionary, checker);
} else {
if (hasDefault == false){
spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker);
hasDefault = true;
} else {
throw new RuntimeException("More than one dictionary is missing name.");
}
}
// Register event listeners for this SpellChecker
core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, true));
if (Boolean.parseBoolean((String)spellchecker.get("buildOnCommit"))) {
LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName());
core.registerNewSearcherListener(new SpellCheckerListener(core, checker, false));
}
} else {
throw new RuntimeException("Can't load spell checker: " + className);
}
}
}
String xpath = "queryConverter";
SolrConfig solrConfig = core.getSolrConfig();
NodeList nodes = (NodeList) solrConfig.evaluate(xpath, XPathConstants.NODESET);
Map<String, QueryConverter> queryConverters = new HashMap<String, QueryConverter>();
NamedListPluginLoader<QueryConverter> loader =
new NamedListPluginLoader<QueryConverter>("[solrconfig.xml] " + xpath, queryConverters);
loader.load(solrConfig.getResourceLoader(), nodes);
//ensure that there is at least one query converter defined
if (queryConverters.size() == 0) {
LOG.warning("No queryConverter defined, using default converter");
queryConverters.put("queryConverter", new SpellingQueryConverter());