Example usage for org.apache.solr.client.solrj.response RangeFacet getGap

List of usage examples for org.apache.solr.client.solrj.response RangeFacet getGap

Introduction

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

Prototype

public G getGap() 

Source Link

Usage

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

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes" })
private void populateFacet(DataTable aTable, RangeFacet aRangeFacet) {
    DataField schemaField;//  ww  w  .  j  a  v a 2s . c  o  m
    Logger appLogger = mAppMgr.getLogger(this, "populateFacet");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    DataBag resultBag = mBag;
    String fieldName = aRangeFacet.getName();
    schemaField = resultBag.getFieldByName(fieldName);
    Field.Type fieldType = facetRangeToFieldType(aRangeFacet, schemaField);
    if (Field.isDateOrTime(fieldType)) {
        RangeFacet<Date, Date> facetRangeDate = (RangeFacet<Date, Date>) aRangeFacet;

        aTable.newRow();
        aTable.setValueByName("field_name", fieldName);
        if ((schemaField != null) && (StringUtils.isNotEmpty(schemaField.getTitle())))
            aTable.setValueByName("field_title", schemaField.getTitle());
        else
            aTable.setValueByName("field_title", Field.nameToTitle(fieldName));
        aTable.setValueByName("field_type", Field.typeToString(fieldType));
        Object objectValue = facetRangeDate.getStart();
        if (objectValue != null)
            aTable.setValueByName("field_start", facetRangeDate.getStart());
        objectValue = facetRangeDate.getEnd();
        if (objectValue != null)
            aTable.setValueByName("field_finish", facetRangeDate.getEnd());
        objectValue = facetRangeDate.getGap();
        if (objectValue != null)
            aTable.setValueByName("field_gap", objectValue.toString());
        objectValue = facetRangeDate.getAfter();
        if (objectValue != null)
            aTable.setValueByName("count_after", objectValue.toString());
        objectValue = facetRangeDate.getBefore();
        if (objectValue != null)
            aTable.setValueByName("count_before", objectValue.toString());
        objectValue = facetRangeDate.getBetween();
        if (objectValue != null)
            aTable.setValueByName("count_between", objectValue.toString());
        ArrayList<String> fieldValueList = new ArrayList<>();
        for (RangeFacet.Count rfCount : facetRangeDate.getCounts())
            fieldValueList.add(String.format("%s (%d)", rfCount.getValue(), rfCount.getCount()));
        aTable.setValuesByName("facet_name_count", fieldValueList);
        aTable.addRow();
    } else {
        RangeFacet.Numeric facetRangeNumber = (RangeFacet.Numeric) aRangeFacet;

        aTable.newRow();
        aTable.setValueByName("field_name", fieldName);
        if ((schemaField != null) && (StringUtils.isNotEmpty(schemaField.getTitle())))
            aTable.setValueByName("field_title", schemaField.getTitle());
        else
            aTable.setValueByName("field_title", Field.nameToTitle(fieldName));
        aTable.setValueByName("field_type", Field.typeToString(fieldType));
        Object objectValue = facetRangeNumber.getStart();
        if (objectValue != null)
            aTable.setValueByName("field_start", objectValue.toString());
        objectValue = facetRangeNumber.getEnd();
        if (objectValue != null)
            aTable.setValueByName("field_finish", objectValue.toString());
        objectValue = facetRangeNumber.getGap();
        if (objectValue != null)
            aTable.setValueByName("field_gap", objectValue.toString());
        objectValue = facetRangeNumber.getAfter();
        if (objectValue != null)
            aTable.setValueByName("count_after", objectValue.toString());
        objectValue = facetRangeNumber.getBefore();
        if (objectValue != null)
            aTable.setValueByName("count_before", objectValue.toString());
        objectValue = facetRangeNumber.getBetween();
        if (objectValue != null)
            aTable.setValueByName("count_between", objectValue.toString());
        ArrayList<String> fieldValueList = new ArrayList<>();
        for (RangeFacet.Count rfCount : facetRangeNumber.getCounts())
            fieldValueList.add(String.format("%s (%d)", rfCount.getValue(), rfCount.getCount()));
        aTable.setValuesByName("facet_name_count", fieldValueList);
        aTable.addRow();
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}