Search in sources :

Example 6 with SearchClusteringEngine

use of org.apache.solr.handler.clustering.SearchClusteringEngine in project SearchServices by Alfresco.

the class AlfrescoSolrClusteringComponent method inform.

@SuppressWarnings("unchecked")
@Override
public void inform(SolrCore core) {
    if (initParams != null) {
        log.info("Initializing Clustering Engines");
        // Our target list of engines, split into search-results and
        // document clustering.
        SolrResourceLoader loader = core.getResourceLoader();
        for (Map.Entry<String, Object> entry : initParams) {
            if ("engine".equals(entry.getKey())) {
                NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();
                Boolean optional = engineInitParams.getBooleanArg("optional");
                optional = (optional == null ? Boolean.FALSE : optional);
                String engineClassName = StringUtils.defaultIfBlank((String) engineInitParams.get("classname"), CarrotClusteringEngine.class.getName());
                // Instantiate the clustering engine and split to
                // appropriate map.
                final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
                final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");
                if (!engine.isAvailable()) {
                    if (optional) {
                        log.info("Optional clustering engine not available: " + name);
                    } else {
                        throw new SolrException(ErrorCode.SERVER_ERROR, "A required clustering engine failed to initialize, check the logs: " + name);
                    }
                }
                final ClusteringEngine previousEntry;
                if (engine instanceof SearchClusteringEngine) {
                    previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
                } else if (engine instanceof DocumentClusteringEngine) {
                    previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
                } else {
                    log.warn("Unknown type of a clustering engine for class: " + engineClassName);
                    continue;
                }
                if (previousEntry != null) {
                    log.warn("Duplicate clustering engine component named '" + name + "'.");
                }
            }
        }
        // Set up the default engine key for both types of engines.
        setupDefaultEngine("search results clustering", searchClusteringEngines);
        setupDefaultEngine("document clustering", documentClusteringEngines);
        log.info("Finished Initializing Clustering Engines");
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) DocumentClusteringEngine(org.apache.solr.handler.clustering.DocumentClusteringEngine) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CarrotClusteringEngine(org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) CarrotClusteringEngine(org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine) ClusteringEngine(org.apache.solr.handler.clustering.ClusteringEngine) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) DocumentClusteringEngine(org.apache.solr.handler.clustering.DocumentClusteringEngine) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException)

Aggregations

SearchClusteringEngine (org.apache.solr.handler.clustering.SearchClusteringEngine)6 ClusteringComponent (org.apache.solr.handler.clustering.ClusteringComponent)3 Test (org.junit.Test)3 SolrDocument (org.apache.solr.common.SolrDocument)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 SolrParams (org.apache.solr.common.params.SolrParams)2 DocumentClusteringEngine (org.apache.solr.handler.clustering.DocumentClusteringEngine)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 SolrException (org.apache.solr.common.SolrException)1 NamedList (org.apache.solr.common.util.NamedList)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1 ClusteringEngine (org.apache.solr.handler.clustering.ClusteringEngine)1 CarrotClusteringEngine (org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine)1 DocListAndSet (org.apache.solr.search.DocListAndSet)1