org.apache.solr.search.function.distance
Class HaversineFunction

java.lang.Object
  extended by org.apache.lucene.queries.function.ValueSource
      extended by org.apache.solr.search.function.distance.HaversineFunction

public class HaversineFunction
extends ValueSource

Calculate the Haversine formula (distance) between any two points on a sphere Takes in four value sources: (latA, lonA); (latB, lonB).

Assumes the value sources are in radians unless

See http://en.wikipedia.org/wiki/Great-circle_distance and http://en.wikipedia.org/wiki/Haversine_formula for the actual formula and also http://www.movable-type.co.uk/scripts/latlong.html


Constructor Summary
HaversineFunction(MultiValueSource p1, MultiValueSource p2, double radius)
           
HaversineFunction(MultiValueSource p1, MultiValueSource p2, double radius, boolean convertToRads)
           
 
Method Summary
 void createWeight(Map context, IndexSearcher searcher)
           
 String description()
           
protected  double distance(int doc, FunctionValues p1DV, FunctionValues p2DV)
           
 boolean equals(Object o)
           
 FunctionValues getValues(Map context, AtomicReaderContext readerContext)
           
 int hashCode()
           
protected  String name()
           
 
Methods inherited from class org.apache.lucene.queries.function.ValueSource
getSortField, newContext, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HaversineFunction

public HaversineFunction(MultiValueSource p1,
                         MultiValueSource p2,
                         double radius)

HaversineFunction

public HaversineFunction(MultiValueSource p1,
                         MultiValueSource p2,
                         double radius,
                         boolean convertToRads)
Method Detail

name

protected String name()

distance

protected double distance(int doc,
                          FunctionValues p1DV,
                          FunctionValues p2DV)
Parameters:
doc - The doc to score
Returns:
The haversine distance formula

getValues

public FunctionValues getValues(Map context,
                                AtomicReaderContext readerContext)
                         throws IOException
Specified by:
getValues in class ValueSource
Throws:
IOException

createWeight

public void createWeight(Map context,
                         IndexSearcher searcher)
                  throws IOException
Overrides:
createWeight in class ValueSource
Throws:
IOException

equals

public boolean equals(Object o)
Specified by:
equals in class ValueSource

hashCode

public int hashCode()
Specified by:
hashCode in class ValueSource

description

public String description()
Specified by:
description in class ValueSource


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.