@@ -32,11 +32,14 @@ import com.google.firebase.firestore.pipeline.AggregateFunction.Companion.countA
3232import com.google.firebase.firestore.pipeline.Expression.Companion.constant
3333import com.google.firebase.firestore.pipeline.Expression.Companion.field
3434import com.google.firebase.firestore.pipeline.Expression.Companion.concat
35+ import com.google.firebase.firestore.pipeline.Expression.Companion.documentMatches
3536import com.google.firebase.firestore.pipeline.Expression.Companion.length
37+ import com.google.firebase.firestore.pipeline.Expression.Companion.score
3638import com.google.firebase.firestore.pipeline.Expression.Companion.type
3739import com.google.firebase.firestore.pipeline.Expression.Companion.variable
3840import com.google.firebase.firestore.pipeline.FindNearestStage
3941import com.google.firebase.firestore.pipeline.SampleStage
42+ import com.google.firebase.firestore.pipeline.SearchStage
4043import com.google.firebase.firestore.pipeline.UnnestOptions
4144import com.google.firebase.firestore.toObject
4245import java.util.Date
@@ -3656,4 +3659,42 @@ abstract class DocSnippets(val db: FirebaseFirestore) {
36563659 // [END to_scalar_expression]
36573660 }
36583661
3662+ fun searchBasicQuery () {
3663+ // [START search_basic_query]
3664+ val pipeline = db.pipeline().collection(" restaurants" )
3665+ .search(SearchStage .withQuery(documentMatches(" waffles" )))
3666+ // [END search_basic_query]
3667+ }
3668+
3669+ fun searchExactMatch () {
3670+ // [START search_exact_match]
3671+ val pipeline = db.pipeline().collection(" restaurants" )
3672+ .search(SearchStage .withQuery(documentMatches(" \" belgian waffles\" " )))
3673+ // [END search_exact_match]
3674+ }
3675+
3676+ fun searchTwoTerms () {
3677+ // [START search_two_terms]
3678+ val pipeline = db.pipeline().collection(" restaurants" )
3679+ .search(SearchStage .withQuery(documentMatches(" waffles eggs" )))
3680+ // [END search_two_terms]
3681+ }
3682+
3683+ fun searchExcludeTerm () {
3684+ // [START search_exclude_term]
3685+ val pipeline = db.pipeline().collection(" restaurants" )
3686+ .search(SearchStage .withQuery(documentMatches(" coffee -waffles" )))
3687+ // [END search_exclude_term]
3688+ }
3689+
3690+ fun searchAddScore () {
3691+ // [START search_add_score]
3692+ val pipeline = db.pipeline().collection(" restaurants" )
3693+ .search(
3694+ SearchStage .withQuery(documentMatches(" menu:waffles" ))
3695+ .withAddFields(score().alias(" score" ))
3696+ )
3697+ // [END search_add_score]
3698+ }
3699+
36593700}
0 commit comments