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

java.lang.Object
  extended by org.apache.solr.search.function.ValueSource
      extended by org.apache.solr.search.function.distance.HaversineFunction
All Implemented Interfaces:
Serializable

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

See Also:
Serialized Form

Constructor Summary
HaversineFunction(MultiValueSource p1, MultiValueSource p2, double radius)
           
HaversineFunction(MultiValueSource p1, MultiValueSource p2, double radius, boolean convertToRads)
           
 
Method Summary
 void createWeight(Map context, Searcher searcher)
          Implementations should propagate createWeight to sub-ValueSources which can optionally store weight info in the context.
 String description()
          description of field, used in explain()
protected  double distance(int doc, DocValues p1DV, DocValues p2DV)
           
 boolean equals(Object o)
           
 DocValues getValues(Map context, IndexReader reader)
          Gets the values for this reader and the context that was previously passed to createWeight()
 int hashCode()
           
protected  String name()
           
 
Methods inherited from class org.apache.solr.search.function.ValueSource
getSortField, getValues, 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,
                          DocValues p1DV,
                          DocValues p2DV)
Parameters:
doc - The doc to score
p1DV -
p2DV -
Returns:
The haversine distance formula

getValues

public DocValues getValues(Map context,
                           IndexReader reader)
                    throws IOException
Description copied from class: ValueSource
Gets the values for this reader and the context that was previously passed to createWeight()

Overrides:
getValues in class ValueSource
Throws:
IOException

createWeight

public void createWeight(Map context,
                         Searcher searcher)
                  throws IOException
Description copied from class: ValueSource
Implementations should propagate createWeight to sub-ValueSources which can optionally store weight info in the context. The context object will be passed to getValues() where this info can be retrieved.

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()
Description copied from class: ValueSource
description of field, used in explain()

Specified by:
description in class ValueSource