SearchStage

@Beta
public final class SearchStage extends Stage


The Search stage executes full-text search or geo search operations.

The Search stage must be the first stage in a Pipeline.

db.pipeline().collection("restaurants").search(
SearchStage(
query = documentMatches("waffles OR pancakes"),
sort = arrayOf(score().descending())
)
)

Summary

Nested types

public static class SearchStage.Companion

Public methods

boolean
equals(Object other)
int
final @NonNull SearchStage
withAddFields(
    @NonNull Selectable field,
    @NonNull Selectable additionalFields
)

Specify the fields to add to each document.

final @NonNull SearchStage

Specify the BCP-47 language code of text in the search query, such as "en" or "sr".

final @NonNull SearchStage
withLimit(long limit)

Specify the maximum number of documents to return.

final @NonNull SearchStage
withOffset(long offset)

Specify the number of documents to skip.

static final @NonNull SearchStage

Create SearchStage with an expression search query.

static final @NonNull SearchStage

Create SearchStage with a string search query.

final @NonNull SearchStage
withRetrievalDepth(long retrievalDepth)

Specify the maximum number of documents to retrieve from the search index.

final @NonNull SearchStage
withSort(@NonNull Ordering order, @NonNull Ordering additionalOrderings)

Specify how the returned documents are sorted.

Inherited methods

From com.google.firebase.firestore.pipeline.Stage
final @NonNull SearchStage
final @NonNull SearchStage
withOption(@NonNull String key, boolean value)

Specify named Boolean parameter

final @NonNull SearchStage
withOption(@NonNull String key, double value)

Specify named Double parameter

final @NonNull SearchStage

Specify named Field parameter

final @NonNull SearchStage
withOption(@NonNull String key, long value)

Specify named Long parameter

final @NonNull SearchStage

Specify named String parameter

Public methods

equals

public boolean equals(Object other)

hashCode

public int hashCode()

withAddFields

public final @NonNull SearchStage withAddFields(
    @NonNull Selectable field,
    @NonNull Selectable additionalFields
)

Specify the fields to add to each document.

withLanguageCode

public final @NonNull SearchStage withLanguageCode(@NonNull String languageCode)

Specify the BCP-47 language code of text in the search query, such as "en" or "sr".

withLimit

public final @NonNull SearchStage withLimit(long limit)

Specify the maximum number of documents to return. The limit is applied after documents are scored and sorted.

withOffset

public final @NonNull SearchStage withOffset(long offset)

Specify the number of documents to skip.

withQuery

public static final @NonNull SearchStage withQuery(@NonNull BooleanExpression query)

Create SearchStage with an expression search query.

query specifies the search query that will be used to query and score documents by the search stage.

The query can be expressed as an Expression, which will be used to score and filter the results. Not all expressions supported by Pipelines are supported in the Search query.

db.pipeline().collection("restaurants").search(
SearchStage.withQuery(
or(
documentContainsText("breakfast"),
field("menu").containsText("waffle AND coffee")
)
)
)

withQuery

public static final @NonNull SearchStage withQuery(@NonNull String rquery)

Create SearchStage with a string search query. The string will be used as rquery for searching the document.

query specifies the search query that will be used to query and score documents by the search stage.

db.pipeline().collection("restaurants").search(
SearchStage.withQuery("breakfast -diner")
)

// The above query is equivalent to:
db.pipeline().collection("restaurants").search(
SearchStage.withQuery(documentMatches("breakfast -diner"))
)

withRetrievalDepth

public final @NonNull SearchStage withRetrievalDepth(long retrievalDepth)

Specify the maximum number of documents to retrieve from the search index. Documents will be retrieved in the pre-sort order specified by the search index. The retrievalDepth is a limit applied before documents are scored and sorted, which can reduce costs of expensive scoring and sorting operations.

withSort

public final @NonNull SearchStage withSort(@NonNull Ordering order, @NonNull Ordering additionalOrderings)

Specify how the returned documents are sorted. One or more ordering are required.