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
Static MethodsModifier and TypeMethodDescriptionstatic AddSearchScoreExpressionaddExpression(Iterable<? extends SearchScoreExpression> expressions) Returns aSearchScoreExpressionthat evaluates into the sum of the values of the specifiedexpressions.constantExpression(float value) Returns aSearchScoreExpressionthat evaluates into the specifiedvalue.static GaussSearchScoreExpressiongaussExpression(double origin, PathSearchScoreExpression path, double scale) Returns aSearchScoreExpressionthat represents a Gaussian function whose output is within the interval [0, 1].static Log1pSearchScoreExpressionlog1pExpression(SearchScoreExpression expression) Returns aSearchScoreExpressionthat evaluates into log10(expressionValue+ 1), whereexpressionValueis the value of theexpression.static LogSearchScoreExpressionlogExpression(SearchScoreExpression expression) Returns aSearchScoreExpressionthat evaluates into log10(expressionValue), whereexpressionValueis the value of theexpression.multiplyExpression(Iterable<? extends SearchScoreExpression> expressions) Returns aSearchScoreExpressionthat evaluates into the product of the values of the specifiedexpressions.static SearchScoreExpressionCreates aSearchScoreExpressionfrom aBsonin situations when there is no builder method that better satisfies your needs.static PathSearchScoreExpressionReturns aSearchScoreExpressionthat evaluates into the value of the specified field.Returns aSearchScoreExpressionthat evaluates into the relevance score of a document.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
relevanceExpression
Returns aSearchScoreExpressionthat evaluates into the relevance score of a document.- Returns:
- The requested
SearchScoreExpression.
-
pathExpression
Returns aSearchScoreExpressionthat 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 aSearchScoreExpressionthat 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 aSearchScoreExpressionthat represents a Gaussian function whose output is within the interval [0, 1]. Roughly speaking, the further the value of thepathexpression is from theorigin, the smaller the output of the function.The
scaleanddecayare 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), wherepathValueis the value of thepathexpression.- Parameters:
origin- The point of origin, seeGaussSearchScoreExpression.offset(double). The value of the Gaussian function is 1 if the value of thepathexpression isorigin.path- The expression whose value is used to calculate the input of the Gaussian function.scale- The distance from the pointsorigin±offsetat which the output of the Gaussian function must decay by the factor ofdecay.- Returns:
- The requested
SearchScoreExpression.
-
logExpression
Returns aSearchScoreExpressionthat evaluates into log10(expressionValue), whereexpressionValueis the value of theexpression.- Parameters:
expression- The expression whose value is the input of the log10 function.- Returns:
- The requested
SearchScoreExpression.
-
log1pExpression
Returns aSearchScoreExpressionthat evaluates into log10(expressionValue+ 1), whereexpressionValueis 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 aSearchScoreExpressionthat 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 aSearchScoreExpressionthat 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 aSearchScoreExpressionfrom aBsonin 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 equivalentSearchScoreExpressions, 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- ABsonrepresenting the requiredSearchScoreExpression.- Returns:
- The requested
SearchScoreExpression.
-