Package org.apache.lucene.queries.function.valuesource

# Class ReciprocalFloatFunction

java.lang.Object
org.apache.lucene.queries.function.ValueSource
org.apache.lucene.queries.function.valuesource.ReciprocalFloatFunction

public class ReciprocalFloatFunction extends ValueSource
`ReciprocalFloatFunction` implements a reciprocal function f(x) = a/(mx+b), based on the float value of a field or function as exported by `ValueSource`.
When a and b are equal, and x>=0, this function has a maximum value of 1 that drops as x increases. Increasing the value of a and b together results in a movement of the entire function to a flatter part of the curve.

These properties make this an idea function for boosting more recent documents.

Example:`recip(ms(NOW,mydatefield),3.16e-11,1,1)`

A multiplier of 3.16e-11 changes the units from milliseconds to years (since there are about 3.16e10 milliseconds per year). Thus, a very recent date will yield a value close to 1/(0+1) or 1, a date a year in the past will get a multiplier of about 1/(1+1) or 1/2, and date two years old will yield 1/(2+1) or 1/3.

See Also:
  - `FunctionQuery`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final float`
`a`
`protected final float`
`b`
`protected final float`
`m`
`protected final ValueSource`
`source`

## Constructor Summary

Constructors
Constructor
Description
`ReciprocalFloatFunction(ValueSource source, float m, float a, float b)`
f(source) = a/(m*float(source)+b)

## Method Summary

Modifier and Type
Method
Description
`void`
`createWeight(Map<Object,Object> context, IndexSearcher 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()
`boolean`
`equals(Object o)`
`FunctionValues`
`getValues(Map<Object,Object> context, LeafReaderContext readerContext)`
Gets the values for this reader and the context that was previously passed to createWeight().
`int`
`hashCode()`

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

## Field Details

### source

protected final ValueSource source

### m

protected final float m

### a

protected final float a

### b

protected final float b

## Constructor Details

### ReciprocalFloatFunction

public ReciprocalFloatFunction(ValueSource source, float m, float a, float b)
f(source) = a/(m*float(source)+b)

## Method Details

### getValues

public FunctionValues getValues(Map<Object,Object> context, LeafReaderContext readerContext) throws IOException
Description copied from class: `ValueSource`
Gets the values for this reader and the context that was previously passed to createWeight(). The values must be consumed in a forward docID manner, and you must call this method again to iterate through the values again.

Specified by:
  `getValues` in class `ValueSource`
Throws:
  `IOException`

### createWeight

public void createWeight(Map<Object,Object> context, IndexSearcher 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`

### description

public String description()
Description copied from class: `ValueSource`
description of field, used in explain()

Specified by:
  `description` in class `ValueSource`

### hashCode

public int hashCode()

Specified by:
  `hashCode` in class `ValueSource`

### equals

public boolean equals(Object o)

Specified by:
  `equals` in class `ValueSource`