Skip to content

feat(firestore): Implement Search pipeline stage and related expressions#14383

Merged
bhshkh merged 4 commits intogoogleapis:mainfrom
bhshkh:feat/fspq-search
Apr 9, 2026
Merged

feat(firestore): Implement Search pipeline stage and related expressions#14383
bhshkh merged 4 commits intogoogleapis:mainfrom
bhshkh:feat/fspq-search

Conversation

@bhshkh
Copy link
Copy Markdown
Contributor

@bhshkh bhshkh commented Apr 8, 2026

Summary
This PR implements the search pipeline stage and its associated expressions in the Go Firestore SDK, providing parity with the Java (googleapis/java-firestore#2346) and Node.js (googleapis/google-cloud-node#7824) SDKs for full-text and geospatial search capabilities within Firestore Pipelines.

Key Changes

  • Search Pipeline Stage:
    • Implemented the Search stage in Pipeline with a functional options pattern.
    • Introduced WithSearchQuery, WithSearchSort, WithSearchAddFields, and WithSearchRetrievalDepth options.
    • Ensured protobuf encoding places the query within the Options map (not Args) to align with backend requirements and the Java SDK implementation.
  • Search Expressions:
    • Implemented DocumentMatches(query string) and Matches(field, query string) for full-text search.
    • Implemented GeoDistance(field, location) for geospatial distance calculations.
    • Implemented Score() to retrieve the search topicality score.
    • Implemented Snippet(field, query) for highlighted search result snippets.
  • Fluent API:
    • Added GeoDistance(location), Matches(query), and Snippet(query) methods to the Expression interface to support fluent chaining (e.g., FieldOf("location").GeoDistance(loc)).
  • Testing:
    • Added comprehensive unit tests in pipeline_test.go and pipeline_function_test.go.
    • Verified backend request structure consistency via JSON dump comparisons.

Usage Example

pipeline := client.Pipeline().
    Collection("restaurants").
    Search(
        WithSearchQuery(DocumentMatches("waffles OR pancakes")),
        WithSearchSort(Descending(Score())),
        WithSearchAddFields(Snippet("menu", "waffles").As("highlight")),
    )

@bhshkh bhshkh requested review from a team as code owners April 8, 2026 00:40
@product-auto-label product-auto-label bot added the api: firestore Issues related to the Firestore API. label Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds the Search pipeline stage and associated functions like DocumentMatches, GeoDistance, and Snippet to the Firestore SDK. The changes include protobuf mapping, unit tests, and integration tests. Feedback focuses on correcting documentation examples that used incorrect method signatures and recommending the use of the idiomatic GeoPoint type instead of internal proto types for geospatial coordinates. A simplification of the protobuf conversion logic in the search stage was also suggested.

Comment thread firestore/pipeline_function.go Outdated
Comment thread firestore/pipeline_function.go
Comment thread firestore/pipeline_function.go
Comment thread firestore/pipeline_function.go Outdated
Comment thread firestore/pipeline_function.go Outdated
Comment thread firestore/pipeline_expression.go
Comment thread firestore/pipeline_stage.go Outdated
@MarkDuckworth
Copy link
Copy Markdown

MarkDuckworth commented Apr 8, 2026

Snippet will not be supported at launch. Are you seeing that it is supported in your testing?

Comment thread firestore/pipeline_expression.go Outdated
//
// Experimental: Firestore Pipelines is currently in preview and is subject to potential breaking changes in future versions,
// regardless of any other documented package stability guarantees.
Snippet(query string) Expression
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are Snippet/Matches working? I thought they were pushed to after Next

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Removed them


optionsPb := make(map[string]*pb.Value)

for k, v := range s.options {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC search has some other options available (limit, select, query_enhancement, language_code). Have you checked if they are still in scope?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these does not return any errors while testing. Saw only one limitation that select supports only score.

@MarkDuckworth, are they still in scope?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only features exposed in the (java, node, iOS, Android, and Web) SDKs for the launch are:

Search stage:

  • query
  • sort
  • addFields

Expressions:

  • documentMatches(query)
  • field(name).geoDistance(point) / geoDistance(field, point)
  • score()

My understanding is that the backend now also supports:

  • offset
  • limit
  • languageCode
  • retrievalDepth

These will be a fast follow for the Java, Node, iOS, Android, and Web SDKs, so IMO it's okay to include them in the initial release for Go and Python.

@bhshkh
Copy link
Copy Markdown
Contributor Author

bhshkh commented Apr 9, 2026

Snippet will not be supported at launch. Are you seeing that it is supported in your testing?

TEsts were missing for those. After adding, found out that they are not supported. Removed them.

@bhshkh bhshkh merged commit 8a7febc into googleapis:main Apr 9, 2026
11 checks passed
@bhshkh bhshkh deleted the feat/fspq-search branch April 9, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: firestore Issues related to the Firestore API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants