@@ -120,7 +120,7 @@ public static Expression constant(Timestamp value) {
120120 */
121121 @ BetaApi
122122 public static BooleanExpression constant (Boolean value ) {
123- return equal (new Constant (value ), true );
123+ return new BooleanConstant (new Constant (value ));
124124 }
125125
126126 /**
@@ -3390,6 +3390,155 @@ public static BooleanExpression isError(Expression expr) {
33903390 return new BooleanFunctionExpression ("is_error" , expr );
33913391 }
33923392
3393+ /**
3394+ * Evaluates to the distance in meters between the location in the specified field and the query
3395+ * location.
3396+ *
3397+ * <p>This Expression can only be used within a {@code Search} stage.
3398+ *
3399+ * @param fieldName Specifies the field in the document which contains the first {@link GeoPoint}
3400+ * for distance computation.
3401+ * @param location Compute distance to this {@link GeoPoint}.
3402+ * @return A new {@link Expression} representing the geoDistance operation.
3403+ */
3404+ @ BetaApi
3405+ public static Expression geoDistance (String fieldName , GeoPoint location ) {
3406+ return geoDistance (field (fieldName ), location );
3407+ }
3408+
3409+ /**
3410+ * Evaluates to the distance in meters between the location in the specified field and the query
3411+ * location.
3412+ *
3413+ * <p>This Expression can only be used within a {@code Search} stage.
3414+ *
3415+ * @param field Specifies the field in the document which contains the first {@link GeoPoint} for
3416+ * distance computation.
3417+ * @param location Compute distance to this {@link GeoPoint}.
3418+ * @return A new {@link Expression} representing the geoDistance operation.
3419+ */
3420+ @ BetaApi
3421+ public static Expression geoDistance (Field field , GeoPoint location ) {
3422+ return new FunctionExpression ("geo_distance" , java .util .Arrays .asList (field , constant (location )));
3423+ }
3424+
3425+ /**
3426+ * Perform a full-text search on all indexed search fields in the document.
3427+ *
3428+ * <p>This Expression can only be used within a {@code Search} stage.
3429+ *
3430+ * @param rquery Define the search query using the search DTS.
3431+ * @return A new {@link BooleanExpression} representing the documentMatches operation.
3432+ */
3433+ @ BetaApi
3434+ public static BooleanExpression documentMatches (String rquery ) {
3435+ return new BooleanFunctionExpression ("document_matches" , constant (rquery ));
3436+ }
3437+
3438+ /**
3439+ * Perform a full-text search on the specified field.
3440+ *
3441+ * <p>This Expression can only be used within a {@code Search} stage.
3442+ *
3443+ * @param fieldName Perform search on this field.
3444+ * @param rquery Define the search query using the rquery DTS.
3445+ */
3446+ @ InternalApi
3447+ static BooleanExpression matches (String fieldName , String rquery ) {
3448+ return matches (field (fieldName ), rquery );
3449+ }
3450+
3451+ /**
3452+ * Perform a full-text search on the specified field.
3453+ *
3454+ * <p>This Expression can only be used within a {@code Search} stage.
3455+ *
3456+ * @param field Perform search on this field.
3457+ * @param rquery Define the search query using the rquery DTS.
3458+ */
3459+ @ InternalApi
3460+ static BooleanExpression matches (Field field , String rquery ) {
3461+ return new BooleanFunctionExpression ("matches" , field , constant (rquery ));
3462+ }
3463+
3464+ /**
3465+ * Evaluates to the search score that reflects the topicality of the document to all of the text
3466+ * predicates ({@code matches} and {@code documentMatches}) in the search query.
3467+ *
3468+ * <p>This Expression can only be used within a {@code Search} stage.
3469+ *
3470+ * @return A new {@link Expression} representing the score operation.
3471+ */
3472+ @ BetaApi
3473+ public static Expression score () {
3474+ return new FunctionExpression ("score" , com .google .common .collect .ImmutableList .of ());
3475+ }
3476+
3477+ /**
3478+ * Evaluates to an HTML-formatted text snippet that highlights terms matching the search query in
3479+ * {@code <b>bold</b>}.
3480+ *
3481+ * <p>This Expression can only be used within a {@code Search} stage.
3482+ *
3483+ * @param fieldName Search the specified field for matching terms.
3484+ * @param rquery Define the search query using the search DTS.
3485+ * @return A new {@link Expression} representing the snippet operation.
3486+ */
3487+ @ BetaApi
3488+ public static Expression snippet (String fieldName , String rquery ) {
3489+ return new FunctionExpression (
3490+ "snippet" , java .util .Arrays .asList (field (fieldName ), constant (rquery )));
3491+ }
3492+
3493+ /**
3494+ * Evaluates to an HTML-formatted text snippet that highlights terms matching the search query in
3495+ * {@code <b>bold</b>}.
3496+ *
3497+ * <p>This Expression can only be used within a {@code Search} stage.
3498+ *
3499+ * @param rquery Define the search query using the search DTS.
3500+ * @return A new {@link Expression} representing the snippet operation.
3501+ */
3502+ @ BetaApi
3503+ public final Expression snippet (String rquery ) {
3504+ return new FunctionExpression (
3505+ "snippet" ,
3506+ java .util .Arrays .asList (this , constant (rquery )),
3507+ java .util .Collections .singletonMap (
3508+ "query" , com .google .cloud .firestore .PipelineUtils .encodeValue (rquery )));
3509+ }
3510+
3511+ @ InternalApi
3512+ static BooleanExpression between (String fieldName , Expression lowerBound , Expression upperBound ) {
3513+ return between (field (fieldName ), lowerBound , upperBound );
3514+ }
3515+
3516+ @ InternalApi
3517+ static BooleanExpression between (String fieldName , Object lowerBound , Object upperBound ) {
3518+ return between (fieldName , toExprOrConstant (lowerBound ), toExprOrConstant (upperBound ));
3519+ }
3520+
3521+ @ InternalApi
3522+ static BooleanExpression between (
3523+ Expression expression , Expression lowerBound , Expression upperBound ) {
3524+ return new BooleanFunctionExpression ("between" , expression , lowerBound , upperBound );
3525+ }
3526+
3527+ @ InternalApi
3528+ static BooleanExpression between (Expression expression , Object lowerBound , Object upperBound ) {
3529+ return between (expression , toExprOrConstant (lowerBound ), toExprOrConstant (upperBound ));
3530+ }
3531+
3532+ @ InternalApi
3533+ public final BooleanExpression between (Expression lowerBound , Expression upperBound ) {
3534+ return Expression .between (this , lowerBound , upperBound );
3535+ }
3536+
3537+ @ InternalApi
3538+ public final BooleanExpression between (Object lowerBound , Object upperBound ) {
3539+ return Expression .between (this , lowerBound , upperBound );
3540+ }
3541+
33933542 // Other Utility Functions
33943543 /**
33953544 * Creates an expression that returns the document ID from a path.
0 commit comments