← Back to Pull requests

fix(pgdb): symbol-aware FTS query variants (no :* operator) #167

Closed
ianeustis closed this pull request without merging on Sep 28, 2026 21:50 UTC
View on GitHub
ianeustis ianeustis commented on Sep 15, 2026 22:01 UTC
Author

What & why

FullTextSearchQuery stripped every non-alphanumeric rune, so queries like Research_&_Development collapsed to the single trailing token research — and trailing-token prefix matching made the search return everything alphabetically starting with "Research" (ConductorOne IGA-4267). The index side already holds the split lexemes (research, development) and joined lexemes (researchdevelopment); only the query side was wrong.

Change (query-side only, no index/reindex)

FullTextSearchQuery now builds three variants of the input over symbolQuerySplitChars = {. _ / -}:

  • orig — input as-is (back-compat behavior),

  • split — every symbol rune becomes a space (Research_&_Development → research development),

  • joined — every symbol rune deleted, whitespace preserved (Research-Development → researchdevelopment),
  • runs each through the existing tokenize/lowercase/fold/strip pipeline, adds each variant's stemmed counterpart (stemmer.English), dedupes, and ORs them all as exact websearch_to_tsquery('simple', ?) terms.

    Semantics locked by tests

  • *No : prefix operator anywhere (guard test over multi-word, dotted, slashed, snake_case, unicode inputs) — the prefix operator caused pathological GIN scans.

  • & needs no special handling: jargon tokenizes it as a separator per-token, so orig/split/joined dedupe to the same string and only the stemmed counterpart differs. Research_&_Development renders (websearch_to_tsquery('simple', 'research development') || websearch_to_tsquery('simple', 'research develop')) — the AND variant matches the exact index entry (research + development lexemes).

  • - (and /, .)** yield a distinct joined variant: Research-Development renders all four terms (research development, research develop, researchdevelopment, researchdevelop), proving both dedup and the joined path.

  • R&D renders a single (websearch_to_tsquery('simple', 'r d')) arg.
  • Index-side files (normalizeVectorDocs, symbolsSubTokensSplitDoc, symbolsFullTokensSplitDoc, schema, key_builder, templates) are untouched — query-side fix only. Test helper renderQuerySQL and the DotVariants/NoPrefixOperator tests are ported from 556561c; TestFullTextSearchQueryUnderscoreAmpersand locks the verified renderings above.

    Verification

    go test ./pgdb/v1/ -run 'TestFullTextSearchQuery|FuzzFullTextSearchQuery' → ok (DB-backed tests need a postgres binary and are filtered out by the -run pattern).

    Downstream

    ConductorOne carries this port as a vendored-only fallback in ductone/c1#25548 (query-only; go.mod bump follows this merge).

    Diff: 177 lines (+166 / -11) across 2 files Reviewer: None requested Review duration: 18709m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.47) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 177 lines diff across 2 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    57%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.310
    Shallow Review Depth shallow_review_depth
    0.289
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Real PR Conversation Timeline
    1 comments
    "Review active on #167"
    general weight: 0.35
    Reviewers
    None requested
    Assignees
    ianeustis ianeustis
    Labels
    risk: low confidence: 58.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.0% · Lower = rushed or shallow review
    58.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%