use of org.apache.lucene.queries.function.valuesource.LongFieldSource 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);
}
Aggregations