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 forfieldNameindoc.By default, the
centervalue isSystem.currentTimeMillis()/1000 (ie. current seconds since epoch). You can specify a differentcenterusing the appropriate constructor, or by usingsetCenter(Date).NOTE: By Default the
centervalue 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
decayis 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
rangesinstead of a static decay function. Ranges contain amaxDeltadistance from the table'scenterin the specifiedtimeUnit(by default seconds). When ranges are specified, the score is determined by thequadraticCoefficienta,linearCoefficientb, andconstantc, 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 TimeResolutionDEFAULT_CENTER_RESOLUTIONThe default center resolution.static doubleDEFAULT_DECAYThe 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 tobaseexcept 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 voidaddRange(long maxDelta, TimeResolution timeUnit, double a, double b, double c)Add a range to the freshness table.voidaddRange(FreshnessRange range)Freshnessclone()protected Freshnessclone(FieldExpression e)Create a new instance of this FieldExpression, with a different argument.booleanequals(java.lang.Object other)java.util.DategetCenter()Get the "center" date used to calculate freshness.TimeResolutiongetCenterResolution()Get the resolution for rounding the center date.doublegetDecay()Get the "decay" exponent used to calculate freshness.java.util.DategetDefault()Get the default time to use for documents that do not have a value set for "fieldName".java.util.ArrayList<FreshnessRange>getRanges()SchemaField.TypegetType(Schema schema)Resolve the type for this expression.inthashCode()voidsetCenter(java.util.Date center)Set the "center" date used to calculate freshness.voidsetCenterResolution(TimeResolution units)Set the resolution for rounding the center date.voidsetDecay(double decay)Set the "decay" exponent used to calculate freshness.voidsetDefault(java.util.Date value)Set the default time to use for documents that do not have a value set for "fieldName".voidsetFieldName(java.lang.String fieldName)Set the field name to calculate freshness from.voidsetRanges(FreshnessRange... value)voidsetRanges(java.util.List<FreshnessRange> value)voidtoString(java.lang.StringBuilder buffer, FieldExpression.StringMode mode)Writes the string representation of this field expression tobuffer.static FreshnessvalueOf(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 tobaseexcept with a newcenter.
-
-
Method Detail
-
getType
public SchemaField.Type getType(Schema schema)
Resolve the type for this expression.- Specified by:
getTypein 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.nullvalue 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
nullto 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:
toStringin classFieldExpression
-
hashCode
public int hashCode()
- Overrides:
hashCodein classUnaryFieldExpression
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classUnaryFieldExpression
-
clone
public Freshness clone()
- Overrides:
clonein classUnaryFieldExpression
-
clone
protected Freshness clone(FieldExpression e)
Create a new instance of this FieldExpression, with a different argument.- Overrides:
clonein classUnaryFieldExpression
-
valueOf
public static Freshness valueOf(StringParser reader)
-
-