DSL usage
Use chainable, immutable methods onRelation:
facet_by(field, max_values: nil)adds a field to the facets list. If specified multiple times, fields are de‑duplicated by first occurrence.facet_query(field, expr, label: nil)adds a client‑labeled query bucket. Labels are attached client‑side inResult#facets.- Relation stays immutable; each call returns a new instance.
Compiler mapping
- Fields →
facet_by: comma‑separated list in first‑mention order; duplicates removed. - Caps →
max_facet_values: Typesense supports a single global cap; we compile the maximum of requested per‑call caps. - Queries →
facet_query: compiled as a comma‑separated list of“field:expr”tokens. - Sorting/statistics: not emitted. If provided, you’ll get a compile‑time error with a hint.
Supported options
facet_by(field, max_values: nil): supports base fields only. Per‑field caps are normalized to a singlemax_facet_valuesby choosing the maximum request.facet_query(field, expr, label: nil): basic validation for non‑empty strings and balanced range brackets (e.g.,“[0..9]”).- Unsupported:
sort,stats. Attempting to use them raises withdocs/faceting.md#supported-optionsanchor in the error.
Result helpers
Result#facets→{ "author_id" => [ { value:, count:, highlighted:, label: }, ... ] }Result#facet_values(name)→ array of value/count hashes for a field.Result#facet_value_map(name)→ convenience{ value => count }hash.
facet_query are attached to buckets whose value exactly equals the declared expression.
DX & explain
rel.dry_run!andrel.explaininclude facet params preview:facet_by,max_facet_values, andfacet_query.- Observability redaction masks only sensitive values; facet params are left intact for clarity.
Backlinks
- See Relation Guide for general DSL patterns.
- See DX for dry‑run and explain helpers.
- See JOINs, Selection & Grouping for grouping interactions.
- See Field selection for attribute guardrails.