Example usage for org.apache.solr.search.function.distance GeohashHaversineFunction GeohashHaversineFunction

List of usage examples for org.apache.solr.search.function.distance GeohashHaversineFunction GeohashHaversineFunction

Introduction

In this page you can find the example usage for org.apache.solr.search.function.distance GeohashHaversineFunction GeohashHaversineFunction.

Prototype

public GeohashHaversineFunction(ValueSource geoHash1, ValueSource geoHash2, double radius) 

Source Link

Usage

From source file:GeonamesQParserPlugin.java

License:Apache License

private FunctionQuery getFunction(DistType distType, ValueSource ghVS, float power, List<ValueSource> latLon,
        double currLat, double currLon, double radius) {
    ValueSource vs = null;/*from  w w w  .  j  a  v a  2  s . c  om*/
    switch (distType) {
    case GHHSIN: {
        String ghStr = GeoHashUtils.encode(currLat, currLon);
        vs = new GeohashHaversineFunction(new LiteralValueSource(ghStr), ghVS, radius);
        break;
    }
    case HSIN: {
        vs = new HaversineFunction(new ConstValueSource((float) currLat), new ConstValueSource((float) currLon),
                latLon.get(0), latLon.get(1), radius);
        break;
    }
    case NORM: {
        List<ValueSource> current = new ArrayList<ValueSource>(2);
        current.add(new ConstValueSource((float) currLat));
        current.add(new ConstValueSource((float) currLon));
        vs = new VectorDistanceFunction(power, latLon, current);
        break;
    }
    default: {//assume 2-norm
        List<ValueSource> current = new ArrayList<ValueSource>(2);
        current.add(new ConstValueSource((float) currLat));
        current.add(new ConstValueSource((float) currLon));
        vs = new VectorDistanceFunction(2, latLon, current);
        break;
    }
    }
    return new FunctionQuery(new ReciprocalFloatFunction(vs, 1, 1, 0)); // 1/distance
}