@@ -1208,7 +1208,7 @@ export abstract class Expr implements ProtoValueSerializable, UserData {
12081208 ...others : Array < Expr | unknown >
12091209 ) : FunctionExpr {
12101210 const values = [ second , ...others ] ;
1211- return new FunctionExpr ( 'logical_min ' , [
1211+ return new FunctionExpr ( 'logical_minimum ' , [
12121212 this ,
12131213 ...values . map ( valueToDefaultExpr )
12141214 ] ) ;
@@ -1314,39 +1314,6 @@ export abstract class Expr implements ProtoValueSerializable, UserData {
13141314 return new FunctionExpr ( 'euclidean_distance' , [ this , vectorToExpr ( other ) ] ) ;
13151315 }
13161316
1317- /**
1318- * @beta
1319- *
1320- * Calculates the Manhattan distance between the result of this expression and another VectorValue.
1321- *
1322- * ```typescript
1323- * // Calculate the Manhattan distance between the 'location' field and a target location
1324- * field("location").manhattanDistance(new VectorValue([37.7749, -122.4194]));
1325- * ```
1326- *
1327- * @param vector The other vector (as a VectorValue) to compare against.
1328- * @return A new {@code Expr} representing the Manhattan distance between the two vectors.
1329- */
1330- manhattanDistance ( vector : VectorValue | number [ ] ) : FunctionExpr ;
1331-
1332- /**
1333- * @beta
1334- *
1335- * Calculates the Manhattan distance between two vector expressions.
1336- *
1337- * ```typescript
1338- * // Calculate the Manhattan distance between two vector fields: 'pointA' and 'pointB'
1339- * field("pointA").manhattanDistance(field("pointB"));
1340- * ```
1341- *
1342- * @param vectorExpression The other vector (represented as an Expr) to compare against.
1343- * @return A new {@code Expr} representing the Manhattan distance between the two vectors.
1344- */
1345- manhattanDistance ( vectorExpression : Expr ) : FunctionExpr ;
1346- manhattanDistance ( other : Expr | number [ ] | VectorValue ) : FunctionExpr {
1347- return new FunctionExpr ( 'manhattan_distance' , [ this , vectorToExpr ( other ) ] ) ;
1348- }
1349-
13501317 /**
13511318 * Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC)
13521319 * and returns a timestamp.
@@ -2281,8 +2248,6 @@ export function field(nameOrPath: string | FieldPath): Field {
22812248 return new Field ( documentIdFieldPath ( ) . _internalPath ) ;
22822249 }
22832250 return new Field ( fieldPathFromArgument ( 'of' , nameOrPath ) ) ;
2284- } else if ( documentIdFieldPath ( ) . isEqual ( nameOrPath ) ) {
2285- return new Field ( documentIdFieldPath ( ) . _internalPath ) ;
22862251 } else {
22872252 return new Field ( nameOrPath . _internalPath ) ;
22882253 }
@@ -4611,6 +4576,21 @@ export function arrayContainsAll(
46114576 return fieldOfOrExpr ( array ) . arrayContainsAll ( values ) ;
46124577}
46134578
4579+ /**
4580+ * @beta
4581+ *
4582+ * Creates an expression that calculates the length of an array in a specified field.
4583+ *
4584+ * ```typescript
4585+ * // Get the number of items in field 'cart'
4586+ * arrayLength('cart');
4587+ * ```
4588+ *
4589+ * @param fieldName The name of the field containing an array to calculate the length of.
4590+ * @return A new {@code Expr} representing the length of the array.
4591+ */
4592+ export function arrayLength ( fieldName : string ) : FunctionExpr ;
4593+
46144594/**
46154595 * @beta
46164596 *
@@ -4624,8 +4604,9 @@ export function arrayContainsAll(
46244604 * @param array The array expression to calculate the length of.
46254605 * @return A new {@code Expr} representing the length of the array.
46264606 */
4627- export function arrayLength ( array : Expr ) : FunctionExpr {
4628- return array . arrayLength ( ) ;
4607+ export function arrayLength ( array : Expr ) : FunctionExpr ;
4608+ export function arrayLength ( array : Expr | string ) : FunctionExpr {
4609+ return fieldOfOrExpr ( array ) . arrayLength ( ) ;
46294610}
46304611
46314612/**
@@ -5883,7 +5864,7 @@ export function strConcat(
58835864 second : string | Expr ,
58845865 ...elements : Array < string | Expr >
58855866) : FunctionExpr {
5886- return valueToDefaultExpr ( first ) . strConcat (
5867+ return fieldOfOrExpr ( first ) . strConcat (
58875868 valueToDefaultExpr ( second ) ,
58885869 ...elements . map ( valueToDefaultExpr )
58895870 ) ;
@@ -6366,91 +6347,6 @@ export function euclideanDistance(
63666347 return expr1 . euclideanDistance ( expr2 ) ;
63676348}
63686349
6369- /**
6370- * @beta
6371- *
6372- * Calculates the Manhattan distance between a field's vector value and a double array.
6373- *
6374- * ```typescript
6375- * // Calculate the Manhattan distance between the 'location' field and a target location
6376- * manhattanDistance("location", [37.7749, -122.4194]);
6377- * ```
6378- *
6379- * @param fieldName The name of the field containing the first vector.
6380- * @param vector The other vector (as an array of doubles or VectorValue) to compare against.
6381- * @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6382- */
6383- export function manhattanDistance (
6384- fieldName : string ,
6385- vector : number [ ] | VectorValue
6386- ) : FunctionExpr ;
6387-
6388- /**
6389- * @beta
6390- *
6391- * Calculates the Manhattan distance between a field's vector value and a vector expression.
6392- *
6393- * ```typescript
6394- * // Calculate the Manhattan distance between two vector fields: 'pointA' and 'pointB'
6395- * manhattanDistance("pointA", field("pointB"));
6396- * ```
6397- *
6398- * @param fieldName The name of the field containing the first vector.
6399- * @param vectorExpression The other vector (represented as an Expr) to compare against.
6400- * @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6401- */
6402- export function manhattanDistance (
6403- fieldName : string ,
6404- vectorExpression : Expr
6405- ) : FunctionExpr ;
6406-
6407- /**
6408- * @beta
6409- *
6410- * Calculates the Manhattan distance between a vector expression and a double array.
6411- *
6412- * ```typescript
6413- * // Calculate the Manhattan distance between the 'location' field and a target location
6414- *
6415- * manhattanDistance(field("location"), [37.7749, -122.4194]);
6416- * ```
6417- *
6418- * @param vectorExpression The first vector (represented as an Expr) to compare against.
6419- * @param vector The other vector (as an array of doubles or VectorValue) to compare against.
6420- * @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6421- */
6422- export function manhattanDistance (
6423- vectorExpression : Expr ,
6424- vector : number [ ] | VectorValue
6425- ) : FunctionExpr ;
6426-
6427- /**
6428- * @beta
6429- *
6430- * Calculates the Manhattan distance between two vector expressions.
6431- *
6432- * ```typescript
6433- * // Calculate the Manhattan distance between two vector fields: 'pointA' and 'pointB'
6434- * manhattanDistance(field("pointA"), field("pointB"));
6435- * ```
6436- *
6437- * @param vectorExpression The first vector (represented as an Expr) to compare against.
6438- * @param otherVectorExpression The other vector (represented as an Expr) to compare against.
6439- * @return A new {@code Expr} representing the Manhattan distance between the two vectors.
6440- */
6441- export function manhattanDistance (
6442- vectorExpression : Expr ,
6443- otherVectorExpression : Expr
6444- ) : FunctionExpr ;
6445- export function manhattanDistance (
6446- fieldOrExpr : Expr | string ,
6447- other : Expr | number [ ] | VectorValue
6448- ) : FunctionExpr {
6449- const expr1 = fieldOfOrExpr ( fieldOrExpr ) ;
6450- const expr2 = vectorToExpr ( other ) ;
6451- return expr1 . manhattanDistance ( expr2 ) ;
6452- }
6453-
64546350/**
64556351 * @beta
64566352 *
0 commit comments