Example usage for org.apache.lucene.queries.function.valuesource DoubleFieldSource DoubleFieldSource

List of usage examples for org.apache.lucene.queries.function.valuesource DoubleFieldSource DoubleFieldSource

Introduction

In this page you can find the example usage for org.apache.lucene.queries.function.valuesource DoubleFieldSource DoubleFieldSource.

Prototype

public DoubleFieldSource(String field) 

Source Link

Usage

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//from   w  w w  .  j ava  2  s.  c  o  m
 * @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.");
}

From source file:org.apache.solr.schema.DoubleField.java

License:Apache License

@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
    field.checkFieldCacheSource(qparser);
    return new DoubleFieldSource(field.name);
}

From source file:org.apache.solr.schema.DoublePointField.java

License:Apache License

@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
    field.checkFieldCacheSource();
    return new DoubleFieldSource(field.getName());
}