Class Freshness
- java.lang.Object
-
- com.attivio.sdk.search.fields.FieldExpression
-
- com.attivio.sdk.search.fields.UnaryFieldExpression
-
- com.attivio.sdk.search.fields.Freshness
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class Freshness extends UnaryFieldExpression
Field Expression to calculate a Freshness score.The freshness score function will boost documents that are close to a center date.
The standard freshness calculation for a document is as follows:
freshness = 1 / pow( abs(center
- freshnessValue(fieldName
, doc)) + 1, "decay
)
freshnessValue(fieldName
, doc) = the indexed freshness value forfieldName
indoc
.By default, the
center
value isSystem.currentTimeMillis()
/1000 (ie. current seconds since epoch). You can specify a differentcenter
using the appropriate constructor, or by usingsetCenter(Date)
.NOTE: By Default the
center
value will be rounded up to the next hour during evaluation. This greatly improves cache hits when including freshness scores in searches. You can control the units used for rounding (minutes, seconds, etc) by setting thecenter time units
.The
decay
is used to accelerate or decelerate the change in score as documents approach thecenter
. The freshness score will be a number between 0.0 and 1.0 for positive decay values. Larger values for the decay will result in a faster dropoff in boost as the document's "date" diverges from the "center".The freshness score can consist of
ranges
instead of a static decay function. Ranges contain amaxDelta
distance from the table'scenter
in the specifiedtimeUnit
(by default seconds). When ranges are specified, the score is determined by thequadraticCoefficient
a,linearCoefficient
b, andconstant
c, which are used as the constants of the quadratic equationy = ax^2 + bx + c
, where x is the time delta from the center in the given unit and y is the final score. Setting a and b to zero will result in the constant score c for a range. .Ranges are not additive; the score is determined only by the most specific (smallest delta from the center) matching range. If the function returns a value less than zero, the freshness score is zero. The final score is normalized to a score of 0 to 1 by dividing the function result by the max allowed function value for all ranges.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.attivio.sdk.search.fields.FieldExpression
FieldExpression.StringMode
-
-
Field Summary
Fields Modifier and Type Field Description static TimeResolution
DEFAULT_CENTER_RESOLUTION
The default center resolution.static double
DEFAULT_DECAY
The default value fordecay
-
Fields inherited from class com.attivio.sdk.search.fields.UnaryFieldExpression
expression
-
Fields inherited from class com.attivio.sdk.search.fields.FieldExpression
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Constructor Description Freshness(FieldExpression field)
Freshness(Freshness base, java.util.Date center)
Crate a new freshness identical tobase
except with a newcenter
.Freshness(java.lang.String fieldName)
Freshness(java.lang.String fieldName, double decay)
Freshness(java.lang.String fieldName, double decay, java.util.Date center)
Freshness(java.lang.String fieldName, double decay, java.util.Date center, java.util.Date defaultValue)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRange(long maxDelta, TimeResolution timeUnit, double a, double b, double c)
Add a range to the freshness table.void
addRange(FreshnessRange range)
Freshness
clone()
protected Freshness
clone(FieldExpression e)
Create a new instance of this FieldExpression, with a different argument.boolean
equals(java.lang.Object other)
java.util.Date
getCenter()
Get the "center" date used to calculate freshness.TimeResolution
getCenterResolution()
Get the resolution for rounding the center date.double
getDecay()
Get the "decay" exponent used to calculate freshness.java.util.Date
getDefault()
Get the default time to use for documents that do not have a value set for "fieldName".java.util.ArrayList<FreshnessRange>
getRanges()
SchemaField.Type
getType(Schema schema)
Resolve the type for this expression.int
hashCode()
void
setCenter(java.util.Date center)
Set the "center" date used to calculate freshness.void
setCenterResolution(TimeResolution units)
Set the resolution for rounding the center date.void
setDecay(double decay)
Set the "decay" exponent used to calculate freshness.void
setDefault(java.util.Date value)
Set the default time to use for documents that do not have a value set for "fieldName".void
setFieldName(java.lang.String fieldName)
Set the field name to calculate freshness from.void
setRanges(FreshnessRange... value)
void
setRanges(java.util.List<FreshnessRange> value)
void
toString(java.lang.StringBuilder buffer, FieldExpression.StringMode mode)
Writes the string representation of this field expression tobuffer
.static Freshness
valueOf(StringParser reader)
-
Methods inherited from class com.attivio.sdk.search.fields.UnaryFieldExpression
forEachField, getExpression, getFieldName, hasChildren, isConstant, rewrite, setExpression
-
Methods inherited from class com.attivio.sdk.search.fields.FieldExpression
apply, copyOf, forEachPhrase, forEachQuery, getDefaultName, isConstant, parse, quote, rewrite, rewriteChildren, toString, toString, valueOf
-
-
-
-
Field Detail
-
DEFAULT_DECAY
public static final double DEFAULT_DECAY
The default value fordecay
- See Also:
- Constant Field Values
-
DEFAULT_CENTER_RESOLUTION
public static final TimeResolution DEFAULT_CENTER_RESOLUTION
The default center resolution.
-
-
Constructor Detail
-
Freshness
public Freshness(FieldExpression field)
-
Freshness
public Freshness(java.lang.String fieldName)
-
Freshness
public Freshness(java.lang.String fieldName, double decay)
-
Freshness
public Freshness(java.lang.String fieldName, double decay, java.util.Date center)
-
Freshness
public Freshness(java.lang.String fieldName, double decay, java.util.Date center, java.util.Date defaultValue)
-
Freshness
public Freshness(Freshness base, java.util.Date center)
Crate a new freshness identical tobase
except with a newcenter
.
-
-
Method Detail
-
getType
public SchemaField.Type getType(Schema schema)
Resolve the type for this expression.- Specified by:
getType
in classFieldExpression
-
setFieldName
public void setFieldName(java.lang.String fieldName)
Set the field name to calculate freshness from.The field specified here must be a Date field.
-
getDefault
public java.util.Date getDefault()
Get the default time to use for documents that do not have a value set for "fieldName".If null, this will be epoch start time.
-
setDefault
public void setDefault(java.util.Date value)
Set the default time to use for documents that do not have a value set for "fieldName".If null, this will be epoch start time.
-
getCenter
public java.util.Date getCenter()
Get the "center" date used to calculate freshness.null
value means calcualte freshness from "NOW" (System.currentTimeMillis()
)
-
setCenter
public void setCenter(java.util.Date center)
Set the "center" date used to calculate freshness.Set to
null
to use "NOW" (System.currentTimeMillis()
) as the center.
-
getCenterResolution
public TimeResolution getCenterResolution()
Get the resolution for rounding the center date.
-
setCenterResolution
public void setCenterResolution(TimeResolution units)
Set the resolution for rounding the center date.
-
getDecay
public double getDecay()
Get the "decay" exponent used to calculate freshness.
-
setDecay
public void setDecay(double decay)
Set the "decay" exponent used to calculate freshness.
-
getRanges
public java.util.ArrayList<FreshnessRange> getRanges()
-
setRanges
public void setRanges(java.util.List<FreshnessRange> value)
-
setRanges
public void setRanges(FreshnessRange... value)
-
addRange
public void addRange(FreshnessRange range)
-
addRange
public void addRange(long maxDelta, TimeResolution timeUnit, double a, double b, double c)
Add a range to the freshness table.a, b, and c are the coefficients of the quadratic function
y = ax^2 + bx + c
, where x is the delta from the center point in the given units and y is the score.
-
toString
public void toString(java.lang.StringBuilder buffer, FieldExpression.StringMode mode)
Writes the string representation of this field expression tobuffer
.- Specified by:
toString
in classFieldExpression
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classUnaryFieldExpression
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classUnaryFieldExpression
-
clone
public Freshness clone()
- Overrides:
clone
in classUnaryFieldExpression
-
clone
protected Freshness clone(FieldExpression e)
Create a new instance of this FieldExpression, with a different argument.- Overrides:
clone
in classUnaryFieldExpression
-
valueOf
public static Freshness valueOf(StringParser reader)
-
-