Package com.mongodb.client.model.search
Interface SearchScoreExpression
- All Superinterfaces:
Bson
- All Known Subinterfaces:
AddSearchScoreExpression
,ConstantSearchScoreExpression
,GaussSearchScoreExpression
,Log1pSearchScoreExpression
,LogSearchScoreExpression
,MultiplySearchScoreExpression
,PathSearchScoreExpression
,RelevanceSearchScoreExpression
- Since:
- 4.7
- See Also:
- MongoDB Atlas documentation
- Expressions for the function score modifier
-
Field Summary
Fields inherited from interface org.bson.conversions.Bson
DEFAULT_CODEC_REGISTRY
-
Method Summary
Modifier and TypeMethodDescriptionstatic AddSearchScoreExpression
addExpression
(Iterable<? extends SearchScoreExpression> expressions) Returns aSearchScoreExpression
that evaluates into the sum of the values of the specifiedexpressions
.constantExpression
(float value) Returns aSearchScoreExpression
that evaluates into the specifiedvalue
.static GaussSearchScoreExpression
gaussExpression
(double origin, PathSearchScoreExpression path, double scale) Returns aSearchScoreExpression
that represents a Gaussian function whose output is within the interval [0, 1].static Log1pSearchScoreExpression
log1pExpression
(SearchScoreExpression expression) Returns aSearchScoreExpression
that evaluates into log10(expressionValue
+ 1), whereexpressionValue
is the value of theexpression
.static LogSearchScoreExpression
logExpression
(SearchScoreExpression expression) Returns aSearchScoreExpression
that evaluates into log10(expressionValue
), whereexpressionValue
is the value of theexpression
.multiplyExpression
(Iterable<? extends SearchScoreExpression> expressions) Returns aSearchScoreExpression
that evaluates into the product of the values of the specifiedexpressions
.static SearchScoreExpression
Creates aSearchScoreExpression
from aBson
in situations when there is no builder method that better satisfies your needs.static PathSearchScoreExpression
Returns aSearchScoreExpression
that evaluates into the value of the specified field.Returns aSearchScoreExpression
that evaluates into the relevance score of a document.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
relevanceExpression
Returns aSearchScoreExpression
that evaluates into the relevance score of a document.- Returns:
- The requested
SearchScoreExpression
.
-
pathExpression
Returns aSearchScoreExpression
that evaluates into the value of the specified field.- Parameters:
path
- The numeric field whose value to use as the result of the expression.- Returns:
- The requested
SearchScoreExpression
. - See Also:
-
constantExpression
Returns aSearchScoreExpression
that evaluates into the specifiedvalue
.- Parameters:
value
- The value to use as the result of the expression. UnlikeSearchScore.constant(float)
, does not have constraints.- Returns:
- The requested
SearchScoreExpression
. - See Also:
-
gaussExpression
static GaussSearchScoreExpression gaussExpression(double origin, PathSearchScoreExpression path, double scale) Returns aSearchScoreExpression
that represents a Gaussian function whose output is within the interval [0, 1]. Roughly speaking, the further the value of thepath
expression is from theorigin
, the smaller the output of the function.The
scale
anddecay
are parameters of the Gaussian function, they define the rate at which the function decays. The input of the Gaussian function is the output of another function: max(0, abs(pathValue
-origin
) -offset
), wherepathValue
is the value of thepath
expression.- Parameters:
origin
- The point of origin, seeGaussSearchScoreExpression.offset(double)
. The value of the Gaussian function is 1 if the value of thepath
expression isorigin
.path
- The expression whose value is used to calculate the input of the Gaussian function.scale
- The distance from the pointsorigin
±offset
at which the output of the Gaussian function must decay by the factor ofdecay
.- Returns:
- The requested
SearchScoreExpression
.
-
logExpression
Returns aSearchScoreExpression
that evaluates into log10(expressionValue
), whereexpressionValue
is the value of theexpression
.- Parameters:
expression
- The expression whose value is the input of the log10 function.- Returns:
- The requested
SearchScoreExpression
.
-
log1pExpression
Returns aSearchScoreExpression
that evaluates into log10(expressionValue
+ 1), whereexpressionValue
is the value of theexpression
.- Parameters:
expression
- The expression whose value is used to calculate the input of the log10 function.- Returns:
- The requested
SearchScoreExpression
.
-
addExpression
static AddSearchScoreExpression addExpression(Iterable<? extends SearchScoreExpression> expressions) Returns aSearchScoreExpression
that evaluates into the sum of the values of the specifiedexpressions
.- Parameters:
expressions
- The expressions whose values to add. Must contain at least two expressions.- Returns:
- The requested
SearchScoreExpression
.
-
multiplyExpression
static MultiplySearchScoreExpression multiplyExpression(Iterable<? extends SearchScoreExpression> expressions) Returns aSearchScoreExpression
that evaluates into the product of the values of the specifiedexpressions
.- Parameters:
expressions
- The expressions whose values to multiply. Must contain at least two expressions.- Returns:
- The requested
SearchScoreExpression
.
-
of
Creates aSearchScoreExpression
from aBson
in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.Example
The following code creates two functionally equivalentSearchScoreExpression
s, though they may not be equal.SearchScoreExpression expression1 = SearchScoreExpression.pathExpression( SearchPath.fieldPath("fieldName")) .undefined(-1.5f); SearchScoreExpression expression2 = new Document("path", new Document("value", SearchPath.fieldPath("fieldName").toValue()) .append("undefined", -1.5));
- Parameters:
expression
- ABson
representing the requiredSearchScoreExpression
.- Returns:
- The requested
SearchScoreExpression
.
-