Search in sources :

Example 1 with DateRangeField

use of org.apache.solr.schema.DateRangeField in project lucene-solr by apache.

the class RangeFacetRequest method createCalculator.

/**
   * Creates the right instance of {@link org.apache.solr.handler.component.RangeFacetRequest.RangeEndpointCalculator}
   * depending on the field type of the schema field
   */
private RangeEndpointCalculator<? extends Comparable<?>> createCalculator() {
    RangeEndpointCalculator<?> calc;
    FieldType ft = schemaField.getType();
    if (ft instanceof TrieField) {
        switch(ft.getNumberType()) {
            case FLOAT:
                calc = new FloatRangeEndpointCalculator(this);
                break;
            case DOUBLE:
                calc = new DoubleRangeEndpointCalculator(this);
                break;
            case INTEGER:
                calc = new IntegerRangeEndpointCalculator(this);
                break;
            case LONG:
                calc = new LongRangeEndpointCalculator(this);
                break;
            case DATE:
                calc = new DateRangeEndpointCalculator(this, null);
                break;
            default:
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to range facet on Trie field of unexpected type:" + this.facetOn);
        }
    } else if (ft instanceof DateRangeField) {
        calc = new DateRangeEndpointCalculator(this, null);
    } else if (ft.isPointField()) {
        switch(ft.getNumberType()) {
            case FLOAT:
                calc = new FloatRangeEndpointCalculator(this);
                break;
            case DOUBLE:
                calc = new DoubleRangeEndpointCalculator(this);
                break;
            case INTEGER:
                calc = new IntegerRangeEndpointCalculator(this);
                break;
            case LONG:
                calc = new LongRangeEndpointCalculator(this);
                break;
            case DATE:
                calc = new DateRangeEndpointCalculator(this, null);
                break;
            default:
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to range facet on Point field of unexpected type:" + this.facetOn);
        }
    } else {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to range facet on field:" + schemaField);
    }
    return calc;
}
Also used : TrieField(org.apache.solr.schema.TrieField) SolrException(org.apache.solr.common.SolrException) DateRangeField(org.apache.solr.schema.DateRangeField) FieldType(org.apache.solr.schema.FieldType)

Aggregations

SolrException (org.apache.solr.common.SolrException)1 DateRangeField (org.apache.solr.schema.DateRangeField)1 FieldType (org.apache.solr.schema.FieldType)1 TrieField (org.apache.solr.schema.TrieField)1