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

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

Introduction

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

Prototype

public Object getSum() 

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());//from  w  w w .ja v a 2s  .co  m
    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  www.j  a v  a  2s. 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 .jav  a 2s.  c  om

                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  va2  s . c om
    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.metron.solr.dao.SolrSearchDaoTest.java

License:Apache License

@Test
public void getGroupResultsShouldProperlyReturnGroupResults() {
    GroupRequest groupRequest = new GroupRequest();
    Group group1 = new Group();
    group1.setField("field1");
    GroupOrder groupOrder1 = new GroupOrder();
    groupOrder1.setSortOrder("ASC");
    groupOrder1.setGroupOrderType("TERM");
    group1.setOrder(groupOrder1);//from www .  j  a  va  2  s .co  m
    Group group2 = new Group();
    group2.setField("field2");
    GroupOrder groupOrder2 = new GroupOrder();
    groupOrder2.setSortOrder("DESC");
    groupOrder2.setGroupOrderType("COUNT");
    group2.setOrder(groupOrder2);
    groupRequest.setGroups(Arrays.asList(group1, group2));
    groupRequest.setScoreField("score");

    PivotField level1Pivot1 = mock(PivotField.class);
    PivotField level1Pivot2 = mock(PivotField.class);
    PivotField level2Pivot1 = mock(PivotField.class);
    PivotField level2Pivot2 = mock(PivotField.class);
    FieldStatsInfo level1Pivot1FieldStatsInfo = mock(FieldStatsInfo.class);
    FieldStatsInfo level1Pivot2FieldStatsInfo = mock(FieldStatsInfo.class);
    FieldStatsInfo level2Pivot1FieldStatsInfo = mock(FieldStatsInfo.class);
    FieldStatsInfo level2Pivot2FieldStatsInfo = mock(FieldStatsInfo.class);
    List<PivotField> level1Pivots = Arrays.asList(level1Pivot1, level1Pivot2);
    List<PivotField> level2Pivots = Arrays.asList(level2Pivot1, level2Pivot2);

    when(level1Pivot1.getValue()).thenReturn("field1value1");
    when(level1Pivot1.getCount()).thenReturn(1);
    when(level1Pivot1FieldStatsInfo.getSum()).thenReturn(1.0);
    when(level1Pivot1.getFieldStatsInfo()).thenReturn(new HashMap<String, FieldStatsInfo>() {
        {
            put("score", level1Pivot1FieldStatsInfo);
        }
    });
    when(level1Pivot2.getValue()).thenReturn("field1value2");
    when(level1Pivot2.getCount()).thenReturn(2);
    when(level1Pivot2FieldStatsInfo.getSum()).thenReturn(2.0);
    when(level1Pivot2.getFieldStatsInfo()).thenReturn(new HashMap<String, FieldStatsInfo>() {
        {
            put("score", level1Pivot2FieldStatsInfo);
        }
    });
    when(level2Pivot1.getValue()).thenReturn("field2value1");
    when(level2Pivot1.getCount()).thenReturn(3);
    when(level2Pivot1FieldStatsInfo.getSum()).thenReturn(3.0);
    when(level2Pivot1.getFieldStatsInfo()).thenReturn(new HashMap<String, FieldStatsInfo>() {
        {
            put("score", level2Pivot1FieldStatsInfo);
        }
    });
    when(level2Pivot2.getValue()).thenReturn("field2value2");
    when(level2Pivot2.getCount()).thenReturn(4);
    when(level2Pivot2FieldStatsInfo.getSum()).thenReturn(4.0);
    when(level2Pivot2.getFieldStatsInfo()).thenReturn(new HashMap<String, FieldStatsInfo>() {
        {
            put("score", level2Pivot2FieldStatsInfo);
        }
    });
    when(level1Pivot1.getPivot()).thenReturn(level2Pivots);

    List<GroupResult> level1GroupResults = solrSearchDao.getGroupResults(groupRequest, 0, level1Pivots);

    assertEquals("field1value1", level1GroupResults.get(0).getKey());
    assertEquals(1, level1GroupResults.get(0).getTotal());
    assertEquals(1.0, level1GroupResults.get(0).getScore(), 0.00001);
    assertEquals("field2", level1GroupResults.get(0).getGroupedBy());
    assertEquals("field1value2", level1GroupResults.get(1).getKey());
    assertEquals(2, level1GroupResults.get(1).getTotal());
    assertEquals(2.0, level1GroupResults.get(1).getScore(), 0.00001);
    assertEquals("field2", level1GroupResults.get(1).getGroupedBy());
    assertEquals(0, level1GroupResults.get(1).getGroupResults().size());

    List<GroupResult> level2GroupResults = level1GroupResults.get(0).getGroupResults();
    assertEquals("field2value2", level2GroupResults.get(0).getKey());
    assertEquals(4, level2GroupResults.get(0).getTotal());
    assertEquals(4.0, level2GroupResults.get(0).getScore(), 0.00001);
    assertNull(level2GroupResults.get(0).getGroupedBy());
    assertNull(level2GroupResults.get(0).getGroupResults());
    assertEquals("field2value1", level2GroupResults.get(1).getKey());
    assertEquals(3, level2GroupResults.get(1).getTotal());
    assertEquals(3.0, level2GroupResults.get(1).getScore(), 0.00001);
    assertNull(level2GroupResults.get(1).getGroupedBy());
    assertNull(level2GroupResults.get(1).getGroupResults());
}

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();/*from  w  w w  .  j a v a2  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();
}