org.apache.solr.search.function.distance

## Class VectorDistanceFunction

• Direct Known Subclasses:
SquaredEuclideanFunction

```public class VectorDistanceFunction
extends ValueSource```
Calculate the p-norm for a Vector. See http://en.wikipedia.org/wiki/Lp_space

Common cases:

• 0 = Sparseness calculation
• 1 = Manhattan distance
• 2 = Euclidean distance
• Integer.MAX_VALUE = infinite norm
`for the special case`
• ### Field Summary

Fields
Modifier and Type Field and Description
`protected float` `oneOverPower`
`protected float` `power`
`protected MultiValueSource` `source1`
`protected MultiValueSource` `source2`
• ### Constructor Summary

Constructors
Constructor and Description
```VectorDistanceFunction(float power, MultiValueSource source1, MultiValueSource source2)```
• ### Method Summary

Methods
Modifier and Type Method and Description
`void` ```createWeight(Map context, IndexSearcher searcher)```
`String` `description()`
`protected double` ```distance(int doc, FunctionValues dv1, FunctionValues dv2)```
Calculate the distance
`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`
• ### Field Detail

• #### source1

`protected MultiValueSource source1`
• #### source2

`protected MultiValueSource source2`
• #### power

`protected float power`
• #### oneOverPower

`protected float oneOverPower`
• ### Constructor Detail

• #### VectorDistanceFunction

```public VectorDistanceFunction(float power,
MultiValueSource source1,
MultiValueSource source2)```
• ### Method Detail

• #### name

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

```protected double distance(int doc,
FunctionValues dv1,
FunctionValues dv2)```
Calculate the distance
Parameters:
`doc` - The current doc
`dv1` - The values from the first MultiValueSource
`dv2` - The values from the second MultiValueSource
Returns:
The distance
• #### 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`