Skip to content

Unified search: projection-parametrized search() SQL consolidation#5157

Merged
habdelra merged 6 commits into
mainfrom
cs-11431-unified-search-projection-parametrized-search-sql
Jun 9, 2026
Merged

Unified search: projection-parametrized search() SQL consolidation#5157
habdelra merged 6 commits into
mainfrom
cs-11431-unified-search-projection-parametrized-search-sql

Conversation

@habdelra

@habdelra habdelra commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Phase 1 / Stream A step 1 of Unify prerendered-card-search and card-search: collapse the two SQL projections in index-query-engine.ts into one parametrized query. Pure refactor — output is unchanged (the existing wrapper tests are the parity goldens).

Stacked on #5152#5150. Review the top commit here; base retargets to main as the stack lands.

The change

search(realmURL, query, opts, projection) builds the shared query core once (_search still owns WHERE / GROUP BY url / ORDER / LIMIT) and varies only the SELECT list by projection:

  • dataOnlypristine_doc + error_doc (today's searchCards projection).
  • render(format, renderType) → the format-specific HTML column via buildHtmlColumnExpression (reused verbatim) + used_render_type + deps/display_names/icon_html/error_doc, plus pristine_doc carried conditionallyCASE WHEN <htmlExpr> IS NULL THEN ANY_VALUE(pristine_doc) END — so the live serialization rides along only on no-HTML fallback rows; HTML-backed rows carry none (they'll ship identity-only in CS-11433).

searchCards and searchPrerendered are now thin wrappers over search(); their returned shape is unchanged. No response-shape or endpoint change — emission lands in CS-11433.

Tests

  • Parity goldens: the full existing Unit | query suite (all searchCards / searchPrerendered cases) passes unchanged — 74/74 locally.
  • Projection equivalence: search() returns the same row set + page.total across the dataOnly and render projections for the same query.
  • Conditional pristine_doc: present only on rows whose HTML expression is NULL (verified: HTML-backed row → no pristine_doc; no-HTML row → live pristine_doc).

The pg path is exercised by the realm-server search/prerendered/indexing shards in CI (the SQL reuses the existing pg/sqlite dbExpression variants).

🤖 Generated with Claude Code

…ngine

Consolidate the searchCards and searchPrerendered SQL projections into one
search(realmURL, query, opts, projection): the shared query core
(WHERE / GROUP BY url / ORDER / LIMIT) is built once in _search, and only the
SELECT list varies by projection —

  - dataOnly: pristine_doc + error_doc (today's searchCards projection);
  - render(format, renderType): the format-specific HTML column via
    buildHtmlColumnExpression (reused verbatim) + used_render_type + deps +
    display_names + icon_html + error_doc, plus pristine_doc carried
    conditionally (CASE WHEN <htmlExpr> IS NULL) so the live serialization
    rides along only on no-HTML fallback rows; HTML-backed rows ship none.

searchCards and searchPrerendered become thin wrappers over search(); their
output is unchanged, so the existing wrapper tests are the parity goldens.
New tests cover projection equivalence (same row set + page.total across
projections) and the conditional pristine_doc. No response-shape or endpoint
change — emission/shape work lands in CS-11433.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Preview deployments

Host Test Results

    1 files      1 suites   1h 48m 50s ⏱️
2 974 tests 2 959 ✅ 15 💤 0 ❌
2 993 runs  2 978 ✅ 15 💤 0 ❌

Results for commit b54bdaf.

Realm Server Test Results

    1 files      1 suites   10m 30s ⏱️
1 575 tests 1 575 ✅ 0 💤 0 ❌
1 666 runs  1 666 ✅ 0 💤 0 ❌

Results for commit b54bdaf.

habdelra added 2 commits June 8, 2026 16:50
…ault-filteron' into cs-11431-unified-search-projection-parametrized-search-sql
Code comments describe the enduring contract, not the rollout sequence.
Comment thread packages/host/tests/unit/index-query-engine-test.ts Outdated
Comments (test files included) state the enduring contract, not the ticket.

Copilot AI 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.

Pull request overview

This PR consolidates the SQL projection logic used by instance search into a single IndexQueryEngine.search() entrypoint that varies only the SELECT list via a SearchProjection, while keeping the existing searchCards and searchPrerendered wrappers intact.

Changes:

  • Introduces SearchProjection and a new IndexQueryEngine.search() method to centralize the shared query core and parameterize the projection.
  • Refactors searchCards and searchPrerendered to delegate to search() while preserving their return shapes.
  • Adds unit tests that directly exercise projection equivalence and the conditional pristine_doc behavior for render results.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
packages/runtime-common/index-query-engine.ts Adds SearchProjection and consolidates instance search into a projection-parametrized search() used by the existing wrappers.
packages/host/tests/unit/index-query-engine-test.ts Adds direct tests for search() projection parity and conditional pristine_doc behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/runtime-common/index-query-engine.ts Outdated
Comment thread packages/runtime-common/index-query-engine.ts Outdated
Comment thread packages/runtime-common/index-query-engine.ts Outdated
Comment thread packages/host/tests/unit/index-query-engine-test.ts Outdated
Comment thread packages/host/tests/unit/index-query-engine-test.ts Outdated
@habdelra
habdelra changed the base branch from cs-11430-unified-search-render-type-resolution-rule-default-filteron to main June 8, 2026 21:30
habdelra and others added 2 commits June 8, 2026 17:34
State the contract in timeless terms — drop temporal/delivery framing
("today's", "later separate step", "existing/new") and the identity-only
delivery phrasing from comments and an assertion message.
…_doc

The render projection carries the live serialization only on rows with no HTML
for the format. Build that by wrapping the grouped query: the inner query
computes `html` once (aliased) and a raw `pristine_doc_fallback`; the outer
query applies `CASE WHEN html IS NULL THEN pristine_doc_fallback` — so the
COALESCE/JSONB HTML expression is evaluated a single time per row instead of
twice. Sort values are exposed as inner columns and the outer ORDER BY applies
them (plus the `url` tiebreaker), so ordering and paging are unchanged.

Adds a sort-order test alongside the projection-equivalence and
conditional-pristine_doc tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@habdelra
habdelra merged commit e5fa873 into main Jun 9, 2026
73 checks passed
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.

3 participants