Example usage for org.apache.solr.client.solrj SolrQuery addFacetPivotField

List of usage examples for org.apache.solr.client.solrj SolrQuery addFacetPivotField

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery addFacetPivotField.

Prototype

public SolrQuery addFacetPivotField(String... fields) 

Source Link

Document

Add field(s) for pivot computation.

Usage

From source file:uk.ac.ebi.phenotype.service.StatisticalResultService.java

License:Apache License

public Map<String, Set<String>> getAccessionProceduresMap(String resourceName) {

    SolrQuery query = new SolrQuery();
    Map<String, Set<String>> res = new HashMap<>();
    NamedList<List<PivotField>> response;

    if (resourceName == null) {
        query.setQuery("*:*");
    } else {//from   www.  j ava2 s  . c  o  m
        query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resourceName);
    }
    query.setFacet(true);
    query.addFacetPivotField(
            StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID);
    query.setFacetLimit(-1);
    query.setFacetMinCount(1);
    query.setRows(0);

    try {
        response = solr.query(query).getFacetPivot();
        for (PivotField genePivot : response.get(
                StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID)) {
            String geneName = genePivot.getValue().toString();
            Set<String> procedures = new HashSet<>();
            for (PivotField f : genePivot.getPivot()) {
                procedures.add(f.getValue().toString());
            }
            res.put(geneName, procedures);
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return res;
}