List of usage examples for org.apache.lucene.queries.function.valuesource BytesRefFieldSource BytesRefFieldSource
public BytesRefFieldSource(String field)
From source file:org.apache.solr.analytics.statistics.StatsCollectorSupplierFactory.java
License:Apache License
/** * Builds a value source for a given field, making sure that the field fits a given source type. * @param schema the schema// w ww. j a v a 2 s . c om * @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 */ private static ValueSource buildFieldSource(IndexSchema schema, String expressionString, int sourceType) { SchemaField sf; try { sf = schema.getField(expressionString); } catch (SolrException e) { throw new SolrException(ErrorCode.BAD_REQUEST, "The field " + expressionString + " does not exist.", e); } FieldType type = sf.getType(); if (type instanceof TrieIntField) { if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) { return null; } return new IntFieldSource(expressionString) { public String description() { return field; } }; } else if (type instanceof TrieLongField) { if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) { return null; } return new LongFieldSource(expressionString) { public String description() { return field; } }; } else if (type instanceof TrieFloatField) { if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) { return null; } return new FloatFieldSource(expressionString) { public String description() { return field; } }; } else if (type instanceof TrieDoubleField) { if (sourceType != NUMBER_TYPE && sourceType != FIELD_TYPE) { return null; } return new DoubleFieldSource(expressionString) { public String description() { return field; } }; } else if (type instanceof TrieDateField) { if (sourceType != DATE_TYPE && sourceType != FIELD_TYPE) { return null; } return new DateFieldSource(expressionString) { public String description() { return field; } }; } else if (type instanceof StrField) { if (sourceType != STRING_TYPE && sourceType != FIELD_TYPE) { return null; } return new BytesRefFieldSource(expressionString) { public String description() { return field; } }; } throw new SolrException(ErrorCode.BAD_REQUEST, type.toString() + " is not a supported field type in Solr Analytics."); }