Skip to content

Apply order_by via SQL ORDER BY and compose content_contains with node_type/ids/title filters - #2312

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2211-2212-query-nodes-order-and-filter
Aug 31, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2211-2212-query-nodes-order-and-filter

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Problem

query_nodes accepted NodeFilter.order_by but never turned it into a SQL ORDER BY, so LIMIT/OFFSET sliced an unordered result set and pagination across calls could reorder, repeat, or skip rows.

Separately, the content_contains branch returned early with a bare SELECT * FROM node WHERE LOWER(content) LIKE ?1, dropping node_type, ids, and title_contains entirely — a content search scoped to a type or collection returned nodes of every type/outside the id set, and title_contains was silently dropped once content_contains was also set.

Fix

  • SqliteStore::query_nodes now builds an ORDER BY clause (with an id ASC tiebreaker for determinism) before LIMIT/OFFSET for the direct-query path, and applies an equivalent in-memory sort for the id-chunked path where a single SQL ORDER BY can't span the merged chunk results. NodeService::query_nodes forwards order_by into NodeQuery instead of only logging that it would be handled in memory.
  • All four content_contains conditions (content/title/node_type, plus id-scoping) are now collected into one shared AND-chain. The title stem-token fallback is skipped when content_contains is present, since it has no notion of content matching.
  • OrderBy moves from nodespace-core's models::node into nodespace-types so NodeQuery (the shared wire type) can carry it.

Testing

  • bun run test:all: clean, no new failures.
  • bun run quality:fix: clean (ESLint, svelte-check, tsc, rustfmt, clippy — 0 errors/warnings across the board).
  • Rebased onto current main (which had moved significantly since this branch was created — a v0.2.3 release was cut in the meantime); re-ran the full suite post-rebase to confirm nothing regressed.
  • Pushed through the real pre-push gate (test:all + cargo build + test:e2e) — passed.

Closes #2211
Closes #2212

mstomar125 and others added 2 commits August 31, 2026 09:28
…e_type/ids/title filters

query_nodes accepted NodeFilter.order_by but never turned it into a SQL
ORDER BY, so LIMIT/OFFSET sliced an unordered result set and pagination
across calls could reorder, repeat, or skip rows. SqliteStore::query_nodes
now builds an ORDER BY clause (with an id ASC tiebreaker for determinism)
before LIMIT/OFFSET for the direct-query path, and applies an equivalent
in-memory sort for the id-chunked path where a single SQL ORDER BY can't
span the merged chunk results. NodeService::query_nodes forwards order_by
into NodeQuery instead of only logging that it would be handled in memory.

Separately, the content_contains branch returned early with a bare
"SELECT * FROM node WHERE LOWER(content) LIKE ?1", dropping node_type,
ids, and title_contains entirely. All four conditions are now collected
into one shared AND-chain (content/title/node_type, plus id-scoping) so a
content search scoped to a type or collection no longer returns nodes of
every type/outside the id set, and title_contains no longer gets silently
dropped once content_contains is also set. The title stem-token fallback
is now skipped when content_contains is present, since it has no notion
of content matching.

OrderBy moves from nodespace-core's models::node into nodespace-types so
NodeQuery (the shared wire type) can carry it.

Closes #2211
Closes #2212

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 merged commit 918ef12 into main Aug 31, 2026
@mstomar125
mstomar125 deleted the issue-2211-2212-query-nodes-order-and-filter branch August 31, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment