org.apache.solr.search.function.distance

## Class 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

Constructors
Constructor and Description
```HaversineFunction(MultiValueSource p1, MultiValueSource p2, double radius)```
```HaversineFunction(MultiValueSource p1, MultiValueSource p2, double radius, boolean convertToRads)```
• ### Method Summary

All Methods
Modifier and Type Method and Description
`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, LeafReaderContext readerContext)```
`int` `hashCode()`
`protected String` `name()`
• ### Methods inherited from class org.apache.lucene.queries.function.ValueSource

`asDoubleValuesSource, asLongValuesSource, fromDoubleValuesSource, 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,
• #### HaversineFunction

```public HaversineFunction(MultiValueSource p1,
MultiValueSource p2,
• ### Method Detail

• #### name

`protected String name()`
• #### distance

```protected double distance(int doc,
FunctionValues p1DV,
FunctionValues p2DV)
throws IOException```
Parameters:
`doc` - The doc to score
Returns:
The haversine distance formula
Throws:
`IOException`
• #### getValues

```public FunctionValues getValues(Map context,
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`