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
See Also:
for the special case
• ### Field Detail

• #### power

protected float power
• #### oneOverPower

protected float oneOverPower

• ### Method Detail

• #### name

protected String name()
• #### distance

protected double distance(int doc,
FunctionValues dv1,
FunctionValues dv2)
throws IOException
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
Throws:
IOException
• #### vectorDistance

public static double vectorDistance(double[] vec1,
double[] vec2,
double power)
Calculate the p-norm (i.e. length) between two vectors.

See Lp space

Parameters:
vec1 - The first vector
vec2 - The second vector
power - The power (2 for cartesian distance, 1 for manhattan, etc.)
Returns:
The length.
See Also:
vectorDistance(double[], double[], double, double)
• #### vectorDistance

public static double vectorDistance(double[] vec1,
double[] vec2,
double power,
double oneOverPower)
Calculate the p-norm (i.e. length) between two vectors.
Parameters:
vec1 - The first vector
vec2 - The second vector
power - The power (2 for cartesian distance, 1 for manhattan, etc.)
oneOverPower - If you've pre-calculated oneOverPower and cached it, use this method to save one division operation over vectorDistance(double[], double[], double).
Returns:
The length.
• #### distSquaredCartesian

public static double distSquaredCartesian(double[] vec1,
double[] vec2)
The square of the cartesian Distance. Not really a distance, but useful if all that matters is comparing the result to another one.
Parameters:
vec1 - The first point
vec2 - The second point
Returns:
The squared cartesian distance
• #### hashCode

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

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