Search in sources :

Example 6 with FloatFieldSource

use of org.apache.lucene.queries.function.valuesource.FloatFieldSource 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

FloatFieldSource (org.apache.lucene.queries.function.valuesource.FloatFieldSource)6 DoubleConstValueSource (org.apache.lucene.queries.function.valuesource.DoubleConstValueSource)3 DoubleFieldSource (org.apache.lucene.queries.function.valuesource.DoubleFieldSource)3 IntFieldSource (org.apache.lucene.queries.function.valuesource.IntFieldSource)3 LongFieldSource (org.apache.lucene.queries.function.valuesource.LongFieldSource)3 ConstValueSource (org.apache.lucene.queries.function.valuesource.ConstValueSource)2 DocFreqValueSource (org.apache.lucene.queries.function.valuesource.DocFreqValueSource)2 IDFValueSource (org.apache.lucene.queries.function.valuesource.IDFValueSource)2 JoinDocFreqValueSource (org.apache.lucene.queries.function.valuesource.JoinDocFreqValueSource)2 LiteralValueSource (org.apache.lucene.queries.function.valuesource.LiteralValueSource)2 MaxDocValueSource (org.apache.lucene.queries.function.valuesource.MaxDocValueSource)2 MultiValuedFloatFieldSource (org.apache.lucene.queries.function.valuesource.MultiValuedFloatFieldSource)2 NormValueSource (org.apache.lucene.queries.function.valuesource.NormValueSource)2 NumDocsValueSource (org.apache.lucene.queries.function.valuesource.NumDocsValueSource)2 QueryValueSource (org.apache.lucene.queries.function.valuesource.QueryValueSource)2 SumTotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.SumTotalTermFreqValueSource)2 TFValueSource (org.apache.lucene.queries.function.valuesource.TFValueSource)2 TermFreqValueSource (org.apache.lucene.queries.function.valuesource.TermFreqValueSource)2 TotalTermFreqValueSource (org.apache.lucene.queries.function.valuesource.TotalTermFreqValueSource)2 DateFieldSource (org.apache.solr.analytics.util.valuesource.DateFieldSource)2