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

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

Introduction

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

Prototype

public Long getCount() 

Source Link

Usage

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

License:Apache License

private static <T extends SimpleStatsResult> T populateStatsResultWithFieldStatsInfo(T statsResult,
        FieldStatsInfo value) {

    statsResult.setMax(value.getMax());// w  w  w .  j  av  a 2 s . c  om
    statsResult.setMin(value.getMin());
    statsResult.setCount(value.getCount());
    statsResult.setMissing(value.getMissing());
    statsResult.setStddev(value.getStddev());
    statsResult.setSumOfSquares((Double) new DirectFieldAccessor(value).getPropertyValue("sumOfSquares"));

    Object mean = value.getMean();
    if (mean instanceof Double) {
        statsResult.setMean((Double) mean);
    }

    Object sum = value.getSum();
    if (sum instanceof Double) {
        statsResult.setSum((Double) sum);
    }

    return statsResult;
}

From source file:com.nridge.ds.solr.SolrResponseBuilder.java

License:Open Source License

private void populateStatistic(QueryResponse aQueryResponse) {
    Object statObject;/*from   w w  w .j  av a2 s. c o m*/
    DataField schemaField;
    FieldStatsInfo fieldStatsInfo;
    String fieldName, fieldTitle, fieldValue;
    Logger appLogger = mAppMgr.getLogger(this, "populateStatistic");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Map<String, FieldStatsInfo> mapFieldStatsInfo = aQueryResponse.getFieldStatsInfo();
    if (mapFieldStatsInfo != null) {
        mDocument.addRelationship(Solr.RESPONSE_STATISTIC, createStatisticsBag());
        Relationship statisticRelationship = mDocument.getFirstRelationship(Solr.RESPONSE_STATISTIC);
        if (statisticRelationship != null) {
            DataBag statisticsBag = new DataBag(statisticRelationship.getBag());
            statisticsBag.setAssignedFlagAll(false);
            DataTable statisticTable = new DataTable(statisticsBag);
            DataBag resultBag = mBag;

            for (Map.Entry<String, FieldStatsInfo> entry : mapFieldStatsInfo.entrySet()) {
                statisticTable.newRow();
                fieldName = entry.getKey();
                fieldStatsInfo = entry.getValue();
                statisticTable.setValueByName("field_name", fieldName);
                schemaField = resultBag.getFieldByName(fieldName);
                if (schemaField == null)
                    fieldTitle = Field.nameToTitle(fieldName);
                else
                    fieldTitle = schemaField.getTitle();
                statisticTable.setValueByName("field_title", fieldTitle);
                statObject = fieldStatsInfo.getMin();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("min", fieldValue);
                statObject = fieldStatsInfo.getMax();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("max", fieldValue);
                statObject = fieldStatsInfo.getCount();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("count", fieldValue);
                statObject = fieldStatsInfo.getMissing();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("missing", fieldValue);
                statObject = fieldStatsInfo.getSum();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("sum", fieldValue);
                statObject = fieldStatsInfo.getMean();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("mean", fieldValue);
                statObject = fieldStatsInfo.getStddev();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("standard_deviation", fieldValue);
                statisticTable.addRow();
            }

            Document facetDocument = new Document(Solr.RESPONSE_STATISTIC, statisticTable);
            statisticRelationship.add(facetDocument);
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

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

License:Apache License

@Override
public int next() {
    logger.debug("SolrAggrReader :: next");

    int counter = 0;

    if (!vectors.isEmpty()) {
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String functionName = solrAggrParam.getFunctionName();
            String key = functionName + "_" + counter;
            ValueVector vv = vectors.get(functionName + "_" + counter);
            String solrField = solrAggrParam.getFieldName();
            FieldStatsInfo fieldStats = fieldStatsInfoMap.get(solrField);

            if (vv.getClass().equals(NullableBigIntVector.class)) {
                NullableBigIntVector v = (NullableBigIntVector) vv;

                Object value = null;

                if (functionName.equalsIgnoreCase("sum")) {
                    value = fieldStats.getSum();
                } else if (functionName.equalsIgnoreCase("count")) {
                    value = fieldStats.getCount();
                } else if (functionName.equalsIgnoreCase("min")) {
                    value = fieldStats.getMin();
                } else if (functionName.equalsIgnoreCase("max")) {
                    value = fieldStats.getMax();
                } else {
                    logger.debug("yet to implement function type [ " + functionName + " ]");
                }/*from w  ww.  j a  va 2s  . co  m*/

                Long l = 0L;

                if (value != null) {
                    BigDecimal bd = new BigDecimal(value.toString());
                    l = bd.longValue();
                }

                logger.debug("functionName [ " + functionName + " ] value is " + l + " index " + counter);
                v.getMutator().setSafe(counter, l);
            }

            counter++;
        }

        for (String functionName : vectors.keySet()) {
            ValueVector vv = vectors.get(functionName);
            vv.getMutator().setValueCount((counter > 0) ? counter : 0);
        }

        vectors.clear();
    }

    return counter;
}

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

License:Apache License

private void processStatsRecord(FieldStatsInfo fieldStatsInfo, String functionName, int statsRecordCounter,
        int recordCounter, boolean isGroup) {
    Object fieldValue = null;//from   w  w  w  .j a v a  2s  .co  m
    ValueVector vv1 = vectors.get(String.valueOf(statsRecordCounter));

    if (vv1 != null) {
        if (functionName.equalsIgnoreCase("sum")) {
            fieldValue = fieldStatsInfo.getSum();
        } else if (functionName.equalsIgnoreCase("count")) {
            fieldValue = fieldStatsInfo.getCount();
        } else if (functionName.equalsIgnoreCase("min")) {
            fieldValue = fieldStatsInfo.getMin();
        } else if (functionName.equalsIgnoreCase("max")) {
            fieldValue = fieldStatsInfo.getMax();
        } else if (functionName.equalsIgnoreCase("avg")) {
            fieldValue = fieldStatsInfo.getMean();
        } else {
            SolrRecordReader.logger.debug("Yet to implement function type [ " + functionName + " ]");
        }
    }
    processRecord(vv1, fieldValue, recordCounter);
}

From source file:org.apache.nifi.processors.solr.QuerySolr.java

License:Apache License

private static void addStatsFromSolrResponseToJsonWriter(final QueryResponse response, final JsonWriter writer)
        throws IOException {
    writer.beginObject();// w  w w . j  a va  2  s.c o  m
    writer.name("stats_fields");
    writer.beginObject();
    for (Map.Entry<String, FieldStatsInfo> entry : response.getFieldStatsInfo().entrySet()) {
        FieldStatsInfo fsi = entry.getValue();
        writer.name(entry.getKey());
        writer.beginObject();
        writer.name("min").value(fsi.getMin().toString());
        writer.name("max").value(fsi.getMax().toString());
        writer.name("count").value(fsi.getCount());
        writer.name("missing").value(fsi.getMissing());
        writer.name("sum").value(fsi.getSum().toString());
        writer.name("mean").value(fsi.getMean().toString());
        writer.name("sumOfSquares").value(fsi.getSumOfSquares());
        writer.name("stddev").value(fsi.getStddev());
        writer.endObject();
    }
    writer.endObject();
    writer.endObject();
}