Skip to content

feat(bigquery): add bigquery_search_with_analyzer_options sample to s… - #14722

Merged
iennae merged 1 commit into
mainfrom
feat/bq-search-with-analyzer-options
Nov 3, 2026
Merged

iennae merged 1 commit into
mainfrom
feat/bq-search-with-analyzer-options

Conversation

@iennae

@iennae iennae commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

…earch text with custom JSON analyzer options

Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/search) needs a standalone, tested Python code sample demonstrating how to search text with custom JSON analyzer options (region tag bigquery_search_with_analyzer_options).

Solution:

  • Add search_with_analyzer_options(project_id: str) -> None in bigquery/search/bigquery_search_with_analyzer_options.py (Run a BigQuery SEARCH query configured with custom JSON analyzer_options such as token_filters and stop_words.)
  • Add unit tests (bigquery/search/bigquery_search_with_analyzer_options_test.py) covering both the success path and API error handling (GoogleAPICallError)

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@iennae
iennae requested review from a team and chalmerlowe as code owners November 1, 2026 20:25
@snippet-bot

snippet-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples. labels Nov 1, 2026

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

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.

Code Review

This pull request introduces a new BigQuery code sample demonstrating how to search a table using custom JSON analyzer_options in the SEARCH function, along with its corresponding unit tests and configuration files. The feedback recommends updating the ignored_versions list in noxfile_config.py to ensure only the oldest and newest supported Python versions (3.10 and 3.13) are tested, in accordance with the project's testing guidelines.

Comment thread bigquery/search/noxfile_config.py Resolved

@XrossFox XrossFox left a comment

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.

I left a few questions and suggestions.

u.street_address,
@search_query,
analyzer => 'LOG_ANALYZER',
analyzer_options => '{{"token_filters": [{{"stop_words": ["Apt"]}}]}}'

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.

I believe declaring stop_words outside the sql string and passing it as a value would point the usage better:

search_query = "Nelson Apt"
stop_words = "Apt"
sql = f"""
. 
.
analyzer_options => '{{"token_filters": [{{"stop_words": ["{stop_words}"]}}]}}'

Comment thread bigquery/search/requirements.txt Resolved
@iennae
iennae force-pushed the feat/bq-search-with-analyzer-options branch 2 times, most recently from 276ef7f to e0b9cf8 Compare November 2, 2026 22:35

@XrossFox XrossFox left a comment

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.

LGTM

@iennae
iennae force-pushed the feat/bq-search-with-analyzer-options branch from e0b9cf8 to d3c9099 Compare November 2, 2026 23:33
…earch text with custom JSON analyzer options

Problem:
The BigQuery documentation (https://cloud.google.com/bigquery/docs/search)
needs a standalone, tested Python code sample demonstrating how to
search text with custom JSON analyzer options (region tag `bigquery_search_with_analyzer_options`).

Solution:
- Add `search_with_analyzer_options(project_id: str) -> None` in `bigquery/search/bigquery_search_with_analyzer_options.py`
  (Run a BigQuery SEARCH query configured with custom JSON analyzer_options such as token_filters and stop_words.)
- Add unit tests (`bigquery/search/bigquery_search_with_analyzer_options_test.py`) covering both the success
  path and API error handling (`GoogleAPICallError`)
@iennae
iennae force-pushed the feat/bq-search-with-analyzer-options branch from d3c9099 to 50a8bec Compare November 3, 2026 02:44
@iennae
iennae merged commit 2adea44 into main Nov 3, 2026
13 of 18 checks passed
@iennae
iennae deleted the feat/bq-search-with-analyzer-options branch November 3, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants