Search in sources :

Example 1 with SearchClusteringEngine

use of org.apache.solr.handler.clustering.SearchClusteringEngine in project lucene-solr by apache.

the class CarrotClusteringEngineTest method testDeclarationEngineOrder.

@Test
public void testDeclarationEngineOrder() throws Exception {
    ClusteringComponent comp = (ClusteringComponent) h.getCore().getSearchComponent("clustering-name-decl-order");
    Map<String, SearchClusteringEngine> engines = getSearchClusteringEngines(comp);
    assertEquals(Arrays.asList("unavailable", "lingo", "stc", "mock", "default"), new ArrayList<>(engines.keySet()));
    assertEquals(LingoClusteringAlgorithm.class, ((CarrotClusteringEngine) engines.get(ClusteringEngine.DEFAULT_ENGINE_NAME)).getClusteringAlgorithmClass());
}
Also used : ClusteringComponent(org.apache.solr.handler.clustering.ClusteringComponent) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) Test(org.junit.Test)

Example 2 with SearchClusteringEngine

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

the class AlfrescoSolrClusteringComponent method process.

@Override
public void process(ResponseBuilder rb) throws IOException {
    SolrParams params = rb.req.getParams();
    if (!params.getBool(COMPONENT_NAME, false)) {
        return;
    }
    final String name = getClusteringEngineName(rb);
    boolean useResults = params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false);
    if (useResults == true) {
        SearchClusteringEngine engine = searchClusteringEngines.get(name);
        if (engine != null) {
            checkAvailable(name, engine);
            DocListAndSet results = rb.getResults();
            Map<SolrDocument, Integer> docIds = Maps.newHashMapWithExpectedSize(results.docList.size());
            SolrDocumentList solrDocList = docListToSolrDocumentList(results.docList, rb.req, docIds);
            Object clusters = engine.cluster(rb.getQuery(), solrDocList, docIds, rb.req);
            rb.rsp.add("clusters", clusters);
        } else {
            log.warn("No engine named: " + name);
        }
    }
    boolean useCollection = params.getBool(ClusteringParams.USE_COLLECTION, false);
    if (useCollection == true) {
        DocumentClusteringEngine engine = documentClusteringEngines.get(name);
        if (engine != null) {
            checkAvailable(name, engine);
            boolean useDocSet = params.getBool(ClusteringParams.USE_DOC_SET, false);
            NamedList<?> nl = null;
            // that runs in an executor
            if (useDocSet == true) {
                nl = engine.cluster(rb.getResults().docSet, params);
            } else {
                nl = engine.cluster(params);
            }
            rb.rsp.add("clusters", nl);
        } else {
            log.warn("No engine named: " + name);
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) DocListAndSet(org.apache.solr.search.DocListAndSet) SolrParams(org.apache.solr.common.params.SolrParams) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) SolrDocumentList(org.apache.solr.common.SolrDocumentList) DocumentClusteringEngine(org.apache.solr.handler.clustering.DocumentClusteringEngine)

Example 3 with SearchClusteringEngine

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

the class AlfrescoSolrClusteringComponent method finishStage.

@Override
public void finishStage(ResponseBuilder rb) {
    SolrParams params = rb.req.getParams();
    if (!params.getBool(COMPONENT_NAME, false) || !params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false)) {
        return;
    }
    if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
        String name = getClusteringEngineName(rb);
        SearchClusteringEngine engine = searchClusteringEngines.get(name);
        if (engine != null) {
            checkAvailable(name, engine);
            SolrDocumentList solrDocList = (SolrDocumentList) rb.rsp.getValues().get("response");
            // TODO: Currently, docIds is set to null in distributed
            // environment.
            // This causes CarrotParams.PRODUCE_SUMMARY doesn't work.
            // To work CarrotParams.PRODUCE_SUMMARY under distributed mode,
            // we can choose either one of:
            // (a) In each shard, ClusteringComponent produces summary and
            // finishStage()
            // merges these summaries.
            // (b) Adding doHighlighting(SolrDocumentList, ...) method to
            // SolrHighlighter and
            // making SolrHighlighter uses "external text" rather than
            // stored values to produce snippets.
            Map<SolrDocument, Integer> docIds = null;
            Object clusters = engine.cluster(rb.getQuery(), solrDocList, docIds, rb.req);
            rb.rsp.add("clusters", clusters);
        } else {
            log.warn("No engine named: " + name);
        }
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 4 with SearchClusteringEngine

use of org.apache.solr.handler.clustering.SearchClusteringEngine in project lucene-solr by apache.

the class CarrotClusteringEngineTest method testDeclarationNameDuplicates.

@Test
public void testDeclarationNameDuplicates() throws Exception {
    ClusteringComponent comp = (ClusteringComponent) h.getCore().getSearchComponent("clustering-name-dups");
    Map<String, SearchClusteringEngine> engines = getSearchClusteringEngines(comp);
    assertEquals(Arrays.asList("", "default"), new ArrayList<>(engines.keySet()));
    assertEquals(MockClusteringAlgorithm.class, ((CarrotClusteringEngine) engines.get(ClusteringEngine.DEFAULT_ENGINE_NAME)).getClusteringAlgorithmClass());
}
Also used : ClusteringComponent(org.apache.solr.handler.clustering.ClusteringComponent) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) Test(org.junit.Test)

Example 5 with SearchClusteringEngine

use of org.apache.solr.handler.clustering.SearchClusteringEngine in project lucene-solr by apache.

the class CarrotClusteringEngineTest method testDefaultEngineOrder.

@Test
public void testDefaultEngineOrder() throws Exception {
    ClusteringComponent comp = (ClusteringComponent) h.getCore().getSearchComponent("clustering-name-default");
    Map<String, SearchClusteringEngine> engines = getSearchClusteringEngines(comp);
    assertEquals(Arrays.asList("stc", "default", "mock"), new ArrayList<>(engines.keySet()));
    assertEquals(LingoClusteringAlgorithm.class, ((CarrotClusteringEngine) engines.get(ClusteringEngine.DEFAULT_ENGINE_NAME)).getClusteringAlgorithmClass());
}
Also used : ClusteringComponent(org.apache.solr.handler.clustering.ClusteringComponent) SearchClusteringEngine(org.apache.solr.handler.clustering.SearchClusteringEngine) Test(org.junit.Test)

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