Example usage for org.apache.solr.client.solrj.response FieldStatsInfo getFacets

List of usage examples for org.apache.solr.client.solrj.response FieldStatsInfo getFacets

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response FieldStatsInfo getFacets.

Prototype

public Map<String, List<FieldStatsInfo>> getFacets() 

Source Link

Usage

From source file:com.frank.search.solr.core.ResultHelper.java

License:Apache License

static Map<String, FieldStatsResult> convertFieldStatsInfoToFieldStatsResultMap(
        Map<String, FieldStatsInfo> fieldStatsInfo) {

    if (fieldStatsInfo == null) {
        return Collections.emptyMap();
    }//from  w w  w  .  j av a  2s  . c o  m

    Map<String, FieldStatsResult> result = new LinkedHashMap<String, FieldStatsResult>();
    for (Entry<String, FieldStatsInfo> entry : fieldStatsInfo.entrySet()) {

        FieldStatsInfo value = entry.getValue();

        if (value == null) {
            result.put(entry.getKey(), new SimpleFieldStatsResult());
            continue;
        }

        SimpleFieldStatsResult statsResult = populateStatsResultWithFieldStatsInfo(new SimpleFieldStatsResult(),
                value);

        statsResult.setCountDistinct(value.getCountDistinct());
        statsResult.setDistinctValues(value.getDistinctValues());

        Map<String, List<FieldStatsInfo>> facets = value.getFacets();

        if (facets != null) {
            statsResult.setStatsResults(convertFieldStatsInfoToStatsResultMap(facets));
        }

        result.put(entry.getKey(), statsResult);
    }

    return result;
}

From source file:org.apache.drill.exec.store.solr.SolrRecordReader.java

License:Apache License

private int processStatsFieldResponse(Map<String, FieldStatsInfo> fieldStatsInfoMap, boolean isGroup,
        String uniqueKey) {/*from  w  ww  .  j  ava  2 s.com*/
    int counter = 0;
    int statsCounter = 0;
    Object fieldValue = null;
    if (isGroup) {
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String statsKey = solrAggrParam.getFieldName();
            String functionName = solrAggrParam.getFunctionName();
            FieldStatsInfo fieldStats = fieldStatsInfoMap.get(getSolrField(statsKey, uniqueKey));
            Map<String, List<FieldStatsInfo>> statsFacet = fieldStats.getFacets();

            for (String groupKey : statsFacet.keySet()) {
                counter = 0;
                List<FieldStatsInfo> facetStats = statsFacet.get(groupKey);
                ValueVector vv = vectors.get(groupKey);
                if (vv != null) {
                    for (FieldStatsInfo fieldStatsInfo : facetStats) {
                        fieldValue = fieldStatsInfo.getName();
                        processRecord(vv, fieldValue, counter);
                        processStatsRecord(fieldStatsInfo, functionName, statsCounter, counter, isGroup);
                        counter++; // actual record counter
                    }
                }
            }

            statsCounter++;
        }
    } else {
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            FieldStatsInfo fieldStats = fieldStatsInfoMap
                    .get(getSolrField(solrAggrParam.getFieldName(), uniqueKey));
            String functionName = solrAggrParam.getFunctionName();

            if (fieldStats != null) {
                processStatsRecord(fieldStats, functionName, statsCounter, counter, isGroup);
                statsCounter++;

                if (statsCounter == solrScanSpec.getProjectFieldNames().size()) {
                    break;
                }
            }
        }

        counter++; // actual record counter
    }
    return counter;
}

From source file:org.mousephenotype.cda.solr.service.ObservationService.java

License:Apache License

/**
 * Get stats for the baseline graphs on the phenotype pages for each parameter/center
 * if phenotypingCenter is null just return all stats for the center otherwise filter on that center
 *///w w w .  j  ava 2s  .  c om
public List<FieldStatsInfo> getStatisticsForParameterFromCenter(String parameterStableId,
        String phenotypingCenter) throws SolrServerException, IOException {
    //http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/experiment/select?q=*:*&stats=true&stats.field=data_point&stats.facet=parameter_stable_id&rows=0&indent=true&fq=phenotyping_center:HMGU&fq=parameter_stable_id:IMPC_CBC_010_001
    //http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/experiment/select?q=*:*&stats=true&stats.field=data_point&stats.facet=phenotyping_center&rows=0&indent=true&fq=parameter_stable_id:IMPC_CBC_010_001
    logger.debug("calling getStats for baseline");
    SolrQuery query = new SolrQuery().setQuery("*:*");
    query.setGetFieldStatistics(true);
    query.setGetFieldStatistics(ObservationDTO.DATA_POINT);
    query.setParam("stats.facet", ObservationDTO.PHENOTYPING_CENTER);
    query.setFacetLimit(-1);
    query.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":control");
    if (parameterStableId != null) {
        query.addFilterQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + parameterStableId);
    }

    if (phenotypingCenter != null) {
        query.addFilterQuery(ObservationDTO.PHENOTYPING_CENTER + ":\"" + phenotypingCenter + "\"");
    }

    query.setRows(0);

    logger.debug("SOLR URL getPipelines " + SolrUtils.getBaseURL(experimentCore) + "/select?" + query);

    QueryResponse response = experimentCore.query(query);
    FieldStatsInfo statsInfo = response.getFieldStatsInfo().get(ObservationDTO.DATA_POINT);
    Map<String, List<FieldStatsInfo>> facetToStatsMap = statsInfo.getFacets();

    List<FieldStatsInfo> centerStatsList = null;
    //just get the first result as we only expect 1
    for (String facet : facetToStatsMap.keySet()) {
        centerStatsList = facetToStatsMap.get(facet);
    }

    return centerStatsList;

}