Search in sources :

Example 1 with DualDoubleFunction

use of org.apache.solr.analytics.util.valuesource.DualDoubleFunction in project lucene-solr by apache.

the class StatsCollectorSupplierFactory method buildFilterSource.

/**
   * Builds a default is missing source that wraps a given source. A missing value is required for all 
   * non-field value sources.
   * @param schema the schema
   * @param expressionString The name of the field to build a Field Source from.
   * @param sourceType FIELD_TYPE for any type of field, NUMBER_TYPE for numeric fields, 
   * DATE_TYPE for date fields and STRING_TYPE for string fields.
   * @return a value source
   */
@SuppressWarnings("deprecation")
private static ValueSource buildFilterSource(IndexSchema schema, String expressionString, int sourceType) {
    String[] arguments = ExpressionFactory.getArguments(expressionString);
    if (arguments.length != 2) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid arguments were given for \"" + AnalyticsParams.FILTER + "\".");
    }
    ValueSource delegateSource = buildSourceTree(schema, arguments[0], sourceType);
    if (delegateSource == null) {
        return null;
    }
    Object defaultObject;
    ValueSource src = delegateSource;
    if (delegateSource instanceof FilterFieldSource) {
        src = ((FilterFieldSource) delegateSource).getRootSource();
    }
    if (src instanceof IntFieldSource) {
        try {
            defaultObject = new Integer(arguments[1]);
        } catch (NumberFormatException e) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "The filter value " + arguments[1] + " cannot be converted into an integer.", e);
        }
    } else if (src instanceof DateFieldSource || src instanceof MultiDateFunction) {
        defaultObject = DateMathParser.parseMath(null, arguments[1]);
    } else if (src instanceof LongFieldSource) {
        try {
            defaultObject = new Long(arguments[1]);
        } catch (NumberFormatException e) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "The filter value " + arguments[1] + " cannot be converted into a long.", e);
        }
    } else if (src instanceof FloatFieldSource) {
        try {
            defaultObject = new Float(arguments[1]);
        } catch (NumberFormatException e) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "The filter value " + arguments[1] + " cannot be converted into a float.", e);
        }
    } else if (src instanceof DoubleFieldSource || src instanceof SingleDoubleFunction || src instanceof DualDoubleFunction || src instanceof MultiDoubleFunction) {
        try {
            defaultObject = new Double(arguments[1]);
        } catch (NumberFormatException e) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "The filter value " + arguments[1] + " cannot be converted into a double.", e);
        }
    } else {
        defaultObject = arguments[1];
    }
    return new FilterFieldSource(delegateSource, defaultObject);
}
Also used : LongFieldSource(org.apache.lucene.queries.function.valuesource.LongFieldSource) MultiDateFunction(org.apache.solr.analytics.util.valuesource.MultiDateFunction) SingleDoubleFunction(org.apache.solr.analytics.util.valuesource.SingleDoubleFunction) MultiDoubleFunction(org.apache.solr.analytics.util.valuesource.MultiDoubleFunction) DoubleFieldSource(org.apache.lucene.queries.function.valuesource.DoubleFieldSource) DualDoubleFunction(org.apache.solr.analytics.util.valuesource.DualDoubleFunction) FilterFieldSource(org.apache.solr.analytics.util.valuesource.FilterFieldSource) IntFieldSource(org.apache.lucene.queries.function.valuesource.IntFieldSource) FloatFieldSource(org.apache.lucene.queries.function.valuesource.FloatFieldSource) DateFieldSource(org.apache.solr.analytics.util.valuesource.DateFieldSource) ValueSource(org.apache.lucene.queries.function.ValueSource) SolrException(org.apache.solr.common.SolrException)

Aggregations

ValueSource (org.apache.lucene.queries.function.ValueSource)1 DoubleFieldSource (org.apache.lucene.queries.function.valuesource.DoubleFieldSource)1 FloatFieldSource (org.apache.lucene.queries.function.valuesource.FloatFieldSource)1 IntFieldSource (org.apache.lucene.queries.function.valuesource.IntFieldSource)1 LongFieldSource (org.apache.lucene.queries.function.valuesource.LongFieldSource)1 DateFieldSource (org.apache.solr.analytics.util.valuesource.DateFieldSource)1 DualDoubleFunction (org.apache.solr.analytics.util.valuesource.DualDoubleFunction)1 FilterFieldSource (org.apache.solr.analytics.util.valuesource.FilterFieldSource)1 MultiDateFunction (org.apache.solr.analytics.util.valuesource.MultiDateFunction)1 MultiDoubleFunction (org.apache.solr.analytics.util.valuesource.MultiDoubleFunction)1 SingleDoubleFunction (org.apache.solr.analytics.util.valuesource.SingleDoubleFunction)1 SolrException (org.apache.solr.common.SolrException)1