- Early limit: proactively cap work at the backend when supported.
- Post‑fetch validation: assert a hard upper bound on total hits and raise when exceeded.
DSL usage
Verbatim:- Apply only an early limit to avoid over‑fetching when you only need a small page.
- Add a post‑fetch validator to guard against unexpectedly broad queries in production.
Compiler mapping
- Early limit: The Typesense API has no canonical total‑hits cap parameter. As a conservative fallback, the compiler lowers
per_pagewhen it exceeds the early limit. This avoids over‑fetching on the first page but does not emulate a hard cap across pages. - Validation note: A non‑transmitted internal note is attached for DX so
dry_run!andexplaincan show that a validator will run.
Materializers
The validator runs once per materialization and only after the first response is available, using the backend’s total hits field (found). It applies to:
to_a,each,first,last,take,pluck,idscount,exists?(via a minimal metadata fetch)
Troubleshooting
- Repeated errors: Narrow your filters or increase
validate_hits!(max:). - Multi‑search failures: Treat offending searches independently; raise or log details with labels where available.
perlower than expected: This is the conservativeper_pageadjustment fromlimit_hits(n); increase your early limit if appropriate.
DX surfaces
dry_run!shows the compiled body with anyper_pageadjustment and notes about a pending validator.explainsummarizes early limit, per adjustment, and the validator threshold.