Search in sources :

Example 1 with QueryConverter

use of org.apache.solr.spelling.QueryConverter in project lucene-solr by apache.

the class SpellCheckComponent method inform.

@Override
public void inform(SolrCore core) {
    if (initParams != null) {
        LOG.info("Initializing spell checkers");
        boolean hasDefault = false;
        for (int i = 0; i < initParams.size(); i++) {
            if (initParams.getName(i).equals("spellchecker")) {
                Object cfg = initParams.getVal(i);
                if (cfg instanceof NamedList) {
                    addSpellChecker(core, hasDefault, (NamedList) cfg);
                } else if (cfg instanceof Map) {
                    addSpellChecker(core, hasDefault, new NamedList((Map) cfg));
                } else if (cfg instanceof List) {
                    for (Object o : (List) cfg) {
                        if (o instanceof Map) {
                            addSpellChecker(core, hasDefault, new NamedList((Map) o));
                        }
                    }
                }
            }
        }
        Map<String, QueryConverter> queryConverters = new HashMap<>();
        core.initPlugins(queryConverters, QueryConverter.class);
        //ensure that there is at least one query converter defined
        if (queryConverters.size() == 0) {
            LOG.trace("No queryConverter defined, using default converter");
            queryConverters.put("queryConverter", new SpellingQueryConverter());
        }
        //there should only be one
        if (queryConverters.size() == 1) {
            queryConverter = queryConverters.values().iterator().next();
            IndexSchema schema = core.getLatestSchema();
            String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType");
            FieldType fieldType = schema.getFieldTypes().get(fieldTypeName);
            Analyzer analyzer = fieldType == null ? new WhitespaceAnalyzer() : fieldType.getQueryAnalyzer();
            //TODO: There's got to be a better way!  Where's Spring when you need it?
            queryConverter.setAnalyzer(analyzer);
        }
    }
}
Also used : WhitespaceAnalyzer(org.apache.lucene.analysis.core.WhitespaceAnalyzer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedList(org.apache.solr.common.util.NamedList) SpellingQueryConverter(org.apache.solr.spelling.SpellingQueryConverter) WhitespaceAnalyzer(org.apache.lucene.analysis.core.WhitespaceAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) FieldType(org.apache.solr.schema.FieldType) QueryConverter(org.apache.solr.spelling.QueryConverter) SpellingQueryConverter(org.apache.solr.spelling.SpellingQueryConverter) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) IndexSchema(org.apache.solr.schema.IndexSchema) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 WhitespaceAnalyzer (org.apache.lucene.analysis.core.WhitespaceAnalyzer)1 NamedList (org.apache.solr.common.util.NamedList)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1 FieldType (org.apache.solr.schema.FieldType)1 IndexSchema (org.apache.solr.schema.IndexSchema)1 QueryConverter (org.apache.solr.spelling.QueryConverter)1 SpellingQueryConverter (org.apache.solr.spelling.SpellingQueryConverter)1