Skip to content

fix(search): pick the tsvector query config from the request language - #2047

Merged
devin-ai-integration[bot] merged 4 commits into
mainfrom
feat/search-tsvector-request-language
Nov 21, 2026
Merged

devin-ai-integration[bot] merged 4 commits into
mainfrom
feat/search-tsvector-request-language

Conversation

@pyramation

@pyramation pyramation commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Full-text search always parsed queries with English stemming, even for a French request, so chevaux never matched a French-indexed cheval row.

graphile-search's tsvector adapter, and the unified search and FullText.matches paths that use it, now choose the query config in this order:

explicit column/adapter/preset config
  ?? first supported request langCode (from #2045's Graphile context), mapped by primary subtag → regconfig
  ?? 'english'

The mapping is a fixed allowlist, and the config is passed as a bound parameter, so no request input is ever string-built into SQL. graphile-settings' constructive preset no longer forces english, which would otherwise always win.

Tests cover the plugin (French matches stems, English default unchanged, unknown code falls back, explicit config wins) and cached-handler HTTP Accept-Language. With the DB fix (constructive-db PR), integration realtime-i18n-search IS197 passes (run 44904093702).


Johnny opened this PR for Dan
Implemented in session Build real-time end-to-end tests in integration repo
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • New Features
    • Full-text search filters, unified search, and FullText.matches now use language preferences from HTTP and WebSocket requests for language-aware stemming.
    • Search supports per-column and configured text-search languages. Explicit column, adapter, and preset settings take precedence over request preferences; English is used when preferences are missing or unsupported.
  • Documentation
    • Added guidance on supported language preferences and text-search configuration precedence.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Qualify the english tsconfig fallback with pg_catalog (ts-config.ts:25) — The requestTsConfig fallback returns bare 'english' while every mapped language returns a pg_catalog.-qualified name (graphile/graphile-search/src/ts-config.ts:25).

This PR makes full-text search respect the caller's requested language. A new ts-config.ts normalizes ordered langCodes (from the graphile-i18n middleware context) into PostgreSQL text-search configuration names and stamps them onto select plans via a REQUEST_TS_CONFIG meta key set by a new where-arg applyPlan wrapper in plugin.ts. The tsvector adapter and matches operator factory then resolve a precedence chain — column @tsConfig tag, adapter/preset config, request language, then english — and bind the configuration parameterized as sql.value(config)::regconfig instead of a literal. Presets (graphile-search and constructive-preset) thread default tsConfig values through, and new unit tests plus a WebSocket integration test (with a seeded search_language_documents table) cover resolution and end-to-end behavior.

Files Change
graphile/graphile-search/src/ts-config.ts New language-code → regconfig resolution helpers with whitelist and english fallback
graphile/graphile-search/src/plugin.ts, src/preset.ts Wrap where-arg planning to stamp request tsConfig meta; thread preset defaults
graphile/graphile-search/src/adapters/tsvector.ts, src/codecs/operator-factories.ts Resolve config precedence per column and bind ::regconfig parameterized
graphile/graphile-search/src/__tests__/* New request-language unit tests and SQL fixture
graphql/server-test/__fixtures__/seed/websocket.sql, __tests__/websocket.integration.test.ts Seed search-enabled table and add WebSocket integration coverage
graphile/graphile-settings/src/presets/constructive-preset.ts Wire the new tsConfig option into the constructive preset
graphile/graphile-search/README.md Document the request-language behavior (not reviewed in depth)

Reviewed commit: 40e90db

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Search filters now select PostgreSQL text-search configurations from request language codes. Column and adapter settings take precedence over request preferences, with English as the fallback.

Changes: Request-language search

Layer / File(s) Summary
Map and propagate request language
graphile/graphile-search/src/ts-config.ts, graphile/graphile-search/src/plugin.ts
Helpers map supported langCodes to PostgreSQL configurations and store request configuration metadata for tsvector filters, including unifiedSearch.
Resolve effective text-search configuration
graphile/graphile-search/src/adapters/tsvector.ts, graphile/graphile-search/src/codecs/operator-factories.ts, graphile/graphile-search/src/preset.ts, graphile/graphile-settings/src/presets/constructive-preset.ts, graphile/graphile-search/README.md
Tsvector filters resolve configuration from column settings, adapter settings, request metadata, then English. The matches operator uses field settings, factory settings, request metadata, then English. The README documents request-language selection and configuration precedence.
Verify request-language search behavior
graphile/graphile-search/src/__tests__/request-language.sql, graphile/graphile-search/src/__tests__/request-language.test.ts, graphile/graphile-settings/sql/request-language.sql, graphile/graphile-settings/__tests__/request-language.test.ts, graphql/server-test/...
Tests cover French stemming, explicit configuration, language mapping, fallback inputs, and empty queries. HTTP integration tests check tsvFulltext and unifiedSearch results for language headers.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant GraphileContext
  participant SearchPlugin
  participant TsvectorAdapter
  participant PostgreSQL
  GraphileContext->>SearchPlugin: Provide ctx.langCodes
  SearchPlugin->>SearchPlugin: Store REQUEST_TS_CONFIG on the select query
  SearchPlugin->>TsvectorAdapter: Pass columnWithRequestTsConfig
  TsvectorAdapter->>PostgreSQL: Use the resolved text-search configuration
Loading

Possibly related PRs

  • constructive-io/constructive#2045: Adds HTTP and WebSocket Accept-Language parsing into ordered context langCodes, which this change reads when selecting a text-search configuration.

Suggested reviewers: zetazzz

Merge Risk: Minimal · up to d578c

Search filters now pick the PostgreSQL text-search configuration from the request language. Explicit column, adapter, and preset settings still take precedence, and English remains the fallback. The earlier problem of the Constructive preset forcing English is fixed, and no concrete defects remain open, so the change looks ready to merge.

Security architecture risk: Minimal · up to d578c

Search stemming becomes language-aware, while supported configurations remain fixed and explicit settings retain priority. No introduced or worsened risk to privileges, persistent state or failure containment was identified in the inspected change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed influence reaches existing search filters wherever request preferences are available and no explicit configuration wins, including anonymous request contexts. In the traced path, the preference changes text-search parsing, not the selected database, role, tenant identity or SQL operation.

Trust Boundaries and Controls

  • observed — The request-to-database boundary is constrained by array/string validation, a fixed Map/Set allowlist and SQL value binding. Explicit deployment and column configuration remain above request preferences in the authority chain.

Resilience and Maintainability Implications

  • inferred — The inspected request-specific path copies column metadata and sets query-builder metadata rather than rewriting shared presets or persistent database configuration. It therefore introduces no evident durable transition requiring compensation after interruption. Isolation across executions still depends on framework context and query-builder semantics, whose internals were not independently verified.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(search): pick the tsvector query config from the request language" matches the main change. The PR makes tsvector and full-text filters choose their text-search configuration from the r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(search): pick the tsvector query config from the request language" matches the main change. The PR makes tsvector and full-text filters choose their text-search configuration from the request's language preferences (langCodes), falling back to English, instead of always using a fixed configuration. The title is specific, uses a conventional commit prefix, and names the primary behavior change. It omits the precedence rules and the preset change, which is acceptable for a title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 40e90db and d578cd3.

Files selected for processing: 5

  • graphile/graphile-search/src/__tests__/request-language.test.ts
  • graphile/graphile-search/src/preset.ts
  • graphile/graphile-settings/__tests__/request-language.test.ts
  • graphile/graphile-settings/sql/request-language.sql
  • graphile/graphile-settings/src/presets/constructive-preset.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

coderabbitai[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • English-only matches in Constructive search — Removed the forced-English matches factory and added French-request regressions on ConstructivePreset.
  • Undefined adapter option discards preset language — An undefined adapter tsConfig no longer overrides the explicit preset config; added tests for the adapter, unified and matches paths.

View findings in Devin Review · Follow Devin's work

Devin Review

@devin-ai-integration
devin-ai-integration Bot merged commit 5a13201 into main Nov 21, 2026
22 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the feat/search-tsvector-request-language branch November 21, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant