Example usage for org.apache.solr.handler.clustering.carrot2 CarrotParams OUTPUT_SUB_CLUSTERS

List of usage examples for org.apache.solr.handler.clustering.carrot2 CarrotParams OUTPUT_SUB_CLUSTERS

Introduction

In this page you can find the example usage for org.apache.solr.handler.clustering.carrot2 CarrotParams OUTPUT_SUB_CLUSTERS.

Prototype

String OUTPUT_SUB_CLUSTERS

To view the source code for org.apache.solr.handler.clustering.carrot2 CarrotParams OUTPUT_SUB_CLUSTERS.

Click Source Link

Usage

From source file:com.doculibre.constellio.services.ClusteringServicesImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// ww w  .  jav  a 2 s.  c  o m
public List<SimpleOrderedMap<Object>> cluster(SimpleSearch simpleSearch, CollectionFacet facet, int start,
        int row, ConstellioUser user) {
    //      String luceneQuery = simpleSearch.getLuceneQuery();
    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    String solrServerName = simpleSearch.getCollectionName();
    RecordCollection collection = collectionServices.get(solrServerName);

    //Remarque useDismax est  false car nous allons utiliser le type de requete "/clustering"
    //         donc pas besoin d'ajouter les paramtres necessaires  dismax
    SolrQuery query = SearchServicesImpl.toSolrQuery(simpleSearch, false, true, true);
    query.setRequestHandler("/clustering");

    query.setParam(ClusteringComponent.COMPONENT_NAME, Boolean.TRUE);
    query.setParam(ClusteringParams.USE_COLLECTION, facet.isClusteringUseCollection());
    query.setParam(ClusteringParams.USE_SEARCH_RESULTS, facet.isClusteringUseSearchResults());
    query.setParam(ClusteringParams.USE_DOC_SET, facet.isClusteringUseDocSet());
    query.setParam(ClusteringParams.ENGINE_NAME, facet.getClusteringEngine());

    //The maximum number of labels to produce
    query.setParam(CarrotParams.NUM_DESCRIPTIONS, "" + maxClusters);
    //      query.setParam(CarrotParams.NUM_DESCRIPTIONS, "" + facet.getCarrotNumDescriptions());

    query.setParam(CarrotParams.OUTPUT_SUB_CLUSTERS, facet.isCarrotOutputSubclusters());
    query.setParam(ConstellioSolrQueryParams.LUCENE_QUERY, simpleSearch.getLuceneQuery());
    query.setParam(ConstellioSolrQueryParams.COLLECTION_NAME, simpleSearch.getCollectionName());
    query.setParam(ConstellioSolrQueryParams.SIMPLE_SEARCH, simpleSearch.toSimpleParams().toString());
    if (user != null) {
        query.setParam(ConstellioSolrQueryParams.USER_ID, "" + user.getId());
    }

    //If true, then the snippet field (if no snippet field, then the title field) will be highlighted and the highlighted text will be used for the snippet. 
    query.setParam(CarrotParams.PRODUCE_SUMMARY, facet.isCarrotProduceSummary());
    if (facet.getCarrotTitleField() != null) {
        IndexField indexField = facet.getCarrotTitleField();
        query.setParam(CarrotParams.TITLE_FIELD_NAME, indexField.getName());
    }
    if (facet.getCarrotUrlField() != null) {
        IndexField indexField = facet.getCarrotUrlField();
        query.setParam(CarrotParams.URL_FIELD_NAME, indexField.getName());
    }
    if (facet.getCarrotSnippetField() != null) {
        IndexField indexField = facet.getCarrotSnippetField();
        query.setParam(CarrotParams.SNIPPET_FIELD_NAME, indexField.getName());
    }

    // Requte Lucene
    //      query.setQuery(luceneQuery);

    // nb rsultats par page
    query.setRows(row);

    // page de dbut
    query.setStart(start);
    //Les resultats ne vont pas etre affichs
    /*query.setHighlight(true);
    query.setHighlightFragsize(100);
    query.setHighlightSnippets(2);*/

    if (collection.isOpenSearch()) {
        query.setParam("openSearchURL", collection.getOpenSearchURL());
    }

    SolrServer server = SolrCoreContext.getSolrServer(solrServerName);

    QueryResponse queryResponse;
    try {
        queryResponse = server.query(query);
    } catch (SolrServerException e) {
        throw new RuntimeException(e);
    }

    NamedList<Object> values = queryResponse.getResponse();
    Object clusters = values.get("clusters");
    return (List<SimpleOrderedMap<Object>>) clusters;
}