@@ -74,16 +74,23 @@ import com.google.firestore.v1.Value
7474 * A `Pipeline` is composed of a sequence of stages. Each stage processes the output from the
7575 * previous one, and the final stage's output is the result of the pipeline's execution.
7676 *
77- * <p><b>Example usage:</b> <pre>{@code Pipeline pipeline = firestore.pipeline()
78- * .collection("books") .where(Field("rating").isGreaterThan(4.5))
79- * .sort(Field("rating").descending()) .limit(2); }</pre>
77+ * **Example usage:**
8078 *
81- * <p><b>Note on Execution:</b> The stages are conceptual. The Firestore backend may optimize
82- * execution (e.g., reordering or merging stages) as long as the final result remains the same.
79+ * ```kotlin
80+ * val pipeline = firestore.pipeline()
81+ * .collection("books")
82+ * .where(field("rating").greaterThan(4.5))
83+ * .sort(field("rating").descending())
84+ * .limit(2)
85+ * ```
8386 *
84- * <p><b>Important Limitations:</b> <ul> <li>Pipelines operate on a <b>request/response basis
85- * only</b>. <li>They do <b>not</b> utilize or update the local SDK cache. <li>They do <b>not</b>
86- * support realtime snapshot listeners. </ul>
87+ * **Note on Execution:** The stages are conceptual. The Firestore backend may optimize execution
88+ * (e.g., reordering or merging stages) as long as the final result remains the same.
89+ *
90+ * **Important Limitations:**
91+ * - Pipelines operate on a **request/response basis only**.
92+ * - They do **not** utilize or update the local SDK cache.
93+ * - They do **not** support realtime snapshot listeners.
8794 */
8895class Pipeline
8996internal constructor (
@@ -259,12 +266,12 @@ internal constructor(
259266 * [Expr.alias]
260267 *
261268 * Example:
262- * ```
269+ * ```kotlin
263270 * firestore.pipeline().collection("books")
264271 * .addFields(
265272 * field("rating").as("bookRating"), // Rename 'rating' to 'bookRating'
266273 * add(5, field("quantity")).as("totalCost") // Calculate 'totalCost'
267- * );
274+ * )
268275 * ```
269276 *
270277 * @param field The first field to add to the documents, specified as a [Selectable].
@@ -278,11 +285,11 @@ internal constructor(
278285 * Remove fields from outputs of previous stages.
279286 *
280287 * Example:
281- * ```
288+ * ```kotlin
282289 * firestore.pipeline().collection("books")
283290 * .removeFields(
284291 * field("rating"), field("cost")
285- * );
292+ * )
286293 * ```
287294 *
288295 * @param field The first [Field] to remove.
@@ -296,11 +303,11 @@ internal constructor(
296303 * Remove fields from outputs of previous stages.
297304 *
298305 * Example:
299- * ```
306+ * ```kotlin
300307 * firestore.pipeline().collection("books")
301308 * .removeFields(
302309 * "rating", "cost"
303- * );
310+ * )
304311 * ```
305312 *
306313 * @param field The first [String] name of field to remove.
@@ -328,12 +335,12 @@ internal constructor(
328335 * instead if only additions are desired.
329336 *
330337 * Example:
331- * ```
338+ * ```kotlin
332339 * firestore.pipeline().collection("books")
333340 * .select(
334341 * field("name"),
335342 * field("address").toUppercase().as("upperAddress"),
336- * );
343+ * )
337344 * ```
338345 *
339346 * @param selection The first field to include in the output documents, specified as a
@@ -359,13 +366,13 @@ internal constructor(
359366 * instead if only additions are desired.
360367 *
361368 * Example:
362- * ```
369+ * ```kotlin
363370 * firestore.collection("books")
364- * .select("name", "address");
371+ * .select("name", "address")
365372 *
366373 * // The above is a shorthand of this:
367374 * firestore.pipeline().collection("books")
368- * .select(field("name"), field("address"));
375+ * .select(field("name"), field("address"))
369376 * ```
370377 *
371378 * @param fieldName The first field to include in the output documents, specified as a string
@@ -387,13 +394,13 @@ internal constructor(
387394 * unspecified.
388395 *
389396 * Example:
390- * ```
397+ * ```kotlin
391398 * // Sort books by rating in descending order, and then by title in ascending order for books with the same rating
392399 * firestore.pipeline().collection("books")
393400 * .sort(
394401 * Ordering.of("rating").descending(),
395402 * Ordering.of("title") // Ascending order is the default
396- * );
403+ * )
397404 * ```
398405 *
399406 * @param order The first [Ordering] instance specifying the sorting criteria.
@@ -418,14 +425,14 @@ internal constructor(
418425 * - advanced functions: [Expr.regexMatch], [Expr.arrayContains], etc.
419426 *
420427 * Example:
421- * ```
428+ * ```kotlin
422429 * firestore.pipeline().collection("books")
423430 * .where(
424431 * and(
425432 * gt("rating", 4.0), // Filter for ratings greater than 4.0
426433 * field("genre").equal("Science Fiction") // Equivalent to equal("genre", "Science Fiction")
427434 * )
428- * );
435+ * )
429436 * ```
430437 *
431438 * @param condition The [BooleanExpression] to apply.
@@ -441,12 +448,12 @@ internal constructor(
441448 * page.
442449 *
443450 * Example:
444- * ```
451+ * ```kotlin
445452 * // Retrieve the second page of 20 results
446453 * firestore.pipeline().collection("books")
447454 * .sort(field("published").descending())
448455 * .offset(20) // Skip the first 20 results
449- * .limit(20); // Take the next 20 results
456+ * .limit(20) // Take the next 20 results
450457 * ```
451458 *
452459 * @param offset The number of documents to skip.
@@ -465,11 +472,11 @@ internal constructor(
465472 * especially when dealing with large collections.
466473 *
467474 * Example:
468- * ```
475+ * ```kotlin
469476 * // Limit the results to the top 10 highest-rated books
470477 * firestore.pipeline().collection("books")
471478 * .sort(field("rating").descending())
472- * .limit(10);
479+ * .limit(10)
473480 * ```
474481 *
475482 * @param limit The maximum number of documents to return.
@@ -491,11 +498,11 @@ internal constructor(
491498 * [Expr.alias]
492499 *
493500 * Example:
494- * ```
501+ * ```kotlin
495502 * // Get a list of unique author names in uppercase and genre combinations.
496503 * firestore.pipeline().collection("books")
497504 * .distinct(toUppercase(field("author")).as("authorName"), field("genre"))
498- * .select("authorName");
505+ * .select("authorName")
499506 * ```
500507 *
501508 * @param group The [Selectable] expression to consider when determining distinct value
@@ -523,10 +530,10 @@ internal constructor(
523530 * [Expr.alias]
524531 *
525532 * Example:
526- * ```
533+ * ```kotlin
527534 * // Get a list of unique genres.
528535 * firestore.pipeline().collection("books")
529- * .distinct("genre");
536+ * .distinct("genre")
530537 * ```
531538 *
532539 * @param groupField The [String] representing field name.
@@ -549,13 +556,13 @@ internal constructor(
549556 * calling [AggregateFunction.alias] on [AggregateFunction] instances.
550557 *
551558 * Example:
552- * ```
559+ * ```kotlin
553560 * // Calculate the average rating and the total number of books
554561 * firestore.pipeline().collection("books")
555562 * .aggregate(
556563 * field("rating").average().as("averageRating"),
557564 * countAll().as("totalBooks")
558- * );
565+ * )
559566 * ```
560567 *
561568 * @param accumulator The first [AliasedAggregate] expression, wrapping an [AggregateFunction]
@@ -586,13 +593,13 @@ internal constructor(
586593 * (e.g., sum, average, count) based on the documents within its group.
587594 *
588595 * Example:
589- * ```
596+ * ```kotlin
590597 * // Calculate the average rating for each genre.
591598 * firestore.pipeline().collection("books")
592599 * .aggregate(
593600 * Aggregate
594601 * .withAccumulators(average("rating").as("avg_rating"))
595- * .withGroups("genre"));
602+ * .withGroups("genre"))
596603 * ```
597604 *
598605 * @param aggregateStage An [AggregateStage] object that specifies the grouping fields (if any)
@@ -666,13 +673,13 @@ internal constructor(
666673 * set.
667674 *
668675 * Example:
669- * ```
676+ * ```kotlin
670677 * // Find books with similar "topicVectors" to the given targetVector
671678 * firestore.pipeline().collection("books")
672679 * .findNearest("topicVectors", targetVector, FindNearest.DistanceMeasure.COSINE,
673- * new FindNearestOptions()
680+ * FindNearestOptions()
674681 * .withLimit(10)
675- * .withDistanceField("distance"));
682+ * .withDistanceField("distance"))
676683 * ```
677684 *
678685 * @param vectorField A field name that contains vector to search on.
@@ -697,7 +704,7 @@ internal constructor(
697704 * the document that contains the corresponding value.
698705 *
699706 * Example:
700- * ```
707+ * ```kotlin
701708 * // Input.
702709 * // {
703710 * // "name": "John Doe Jr.",
@@ -707,7 +714,7 @@ internal constructor(
707714 * // }
708715 *
709716 * // Emit parents as document.
710- * firestore.pipeline().collection("people").replaceWith("parents");
717+ * firestore.pipeline().collection("people").replaceWith("parents")
711718 *
712719 * // Output
713720 * // {
@@ -728,7 +735,7 @@ internal constructor(
728735 * the document that contains the corresponding value.
729736 *
730737 * Example:
731- * ```
738+ * ```kotlin
732739 * // Input.
733740 * // {
734741 * // "name": "John Doe Jr.",
@@ -738,7 +745,7 @@ internal constructor(
738745 * // }
739746 *
740747 * // Emit parents as document.
741- * firestore.pipeline().collection("people").replaceWith(field("parents"));
748+ * firestore.pipeline().collection("people").replaceWith(field("parents"))
742749 *
743750 * // Output
744751 * // {
@@ -762,10 +769,10 @@ internal constructor(
762769 * sample of exactly size entries where any sample is equally likely.
763770 *
764771 * Example:
765- * ```
772+ * ```kotlin
766773 * // Sample 10 books, if available.
767774 * firestore.pipeline().collection("books")
768- * .sample(10);
775+ * .sample(10)
769776 * ```
770777 *
771778 * @param documents The number of documents to emit.
@@ -777,14 +784,14 @@ internal constructor(
777784 * Performs a pseudo-random sampling of the input documents.
778785 *
779786 * Examples:
780- * ```
787+ * ```kotlin
781788 * // Sample 10 books, if available.
782789 * firestore.pipeline().collection("books")
783- * .sample(Sample.withDocLimit(10));
790+ * .sample(Sample.withDocLimit(10))
784791 *
785792 * // Sample 50% of books.
786793 * firestore.pipeline().collection("books")
787- * .sample(Sample.withPercentage(0.5));
794+ * .sample(Sample.withPercentage(0.5))
788795 * ```
789796 *
790797 * @param sample An [SampleStage] object that specifies how sampling is performed.
@@ -800,10 +807,10 @@ internal constructor(
800807 * from this stage is undefined.
801808 *
802809 * Example:
803- * ```
810+ * ```kotlin
804811 * // Emit documents from books collection and magazines collection.
805812 * firestore.pipeline().collection("books")
806- * .union(firestore.pipeline().collection("magazines"));
813+ * .union(firestore.pipeline().collection("magazines"))
807814 * ```
808815 *
809816 * @param other The other [Pipeline] that is part of union.
@@ -822,13 +829,13 @@ internal constructor(
822829 * parameter on the augmented document.
823830 *
824831 * Example:
825- * ```
832+ * ```kotlin
826833 * // Input:
827834 * // { "title": "The Hitchhiker's Guide to the Galaxy", "tags": [ "comedy", "space", "adventure" ], ... }
828835 *
829836 * // Emit a book document for each tag of the book.
830837 * firestore.pipeline().collection("books")
831- * .unnest("tags", "tag");
838+ * .unnest("tags", "tag")
832839 *
833840 * // Output:
834841 * // { "title": "The Hitchhiker's Guide to the Galaxy", "tag": "comedy", ... }
@@ -872,13 +879,13 @@ internal constructor(
872879 * replaced with the individual element.
873880 *
874881 * Example:
875- * ```
882+ * ```kotlin
876883 * // Input:
877884 * // { "title": "The Hitchhiker's Guide to the Galaxy", "tags": [ "comedy", "space", "adventure" ], ... }
878885 *
879886 * // Emit a book document for each tag of the book.
880887 * firestore.pipeline().collection("books")
881- * .unnest("tags", "tag", new UnnestOptions().withIndexField("tagIndex"));
888+ * .unnest("tags", "tag", UnnestOptions().withIndexField("tagIndex"))
882889 *
883890 * // Output:
884891 * // { "title": "The Hitchhiker's Guide to the Galaxy", "tagIndex": 0, "tag": "comedy", ... }
@@ -1088,7 +1095,7 @@ internal constructor(
10881095 *
10891096 * @example
10901097 * ```kotlin
1091- * db.pipeline().collection(' restaurants' ).search(
1098+ * db.pipeline().collection(" restaurants" ).search(
10921099 * SearchStage(
10931100 * query = documentMatches("waffles OR pancakes"),
10941101 * sort = arrayOf(score().descending())
@@ -1264,7 +1271,7 @@ class PipelineSource internal constructor(private val firestore: FirebaseFiresto
12641271 * .addFields(
12651272 * PipelineSource.subcollection("reviews")
12661273 * .aggregate(AggregateFunction.average("rating").as("avg_rating"))
1267- * .toScalarExpression().as("average_rating"));
1274+ * .toScalarExpression().as("average_rating"))
12681275 * ```
12691276 *
12701277 * @param path The path of the subcollection.
@@ -1285,7 +1292,7 @@ class PipelineSource internal constructor(private val firestore: FirebaseFiresto
12851292 * .addFields(
12861293 * PipelineSource.subcollection(SubcollectionSource.of("reviews"))
12871294 * .aggregate(AggregateFunction.average("rating").as("avg_rating"))
1288- * .toScalarExpression().as("average_rating"));
1295+ * .toScalarExpression().as("average_rating"))
12891296 * ```
12901297 *
12911298 * @param source The subcollection that will be the source of this pipeline.
0 commit comments