Skip to main content
Related: Relation, Query DSL, DX

Intro

Copy these minimal patterns and adapt fields to your models. Prefer dry_run! and explain to debug locally without network I/O.

Index of patterns

Back to top ⤴

Recipes

Exact match

Small set lookup by ID.
Why it works / gotchas:

Prefix/infix match

Begins‑with or contains‑like filters via templates/raw.
Why / gotchas:
  • PREFIX is parsed to AST; infix shown as raw Typesense fragment
  • Consider query text in q for full‑text; this is a filter
  • Links: Query DSL, Compiler

Any of list (IN)

Match any of several brands.
Why / gotchas:

Price range + sort

Use two comparators for numeric ranges.
Why / gotchas:

Pagination

Classic page/per; prefer this over limit/offset unless you need offset math.
Why / gotchas:

Facet filters

Combine multiple filters with AND semantics across calls.
Why / gotchas:

Pinned/hidden curation

Pin two IDs and hide one; keep network‑safe while inspecting.
Why / gotchas:
  • Curation keys are body‑only; redacted in logs
  • Hide wins when an ID is both pinned and hidden
  • Links: Curation, Observability

Grouping top‑N

First hit per group, up to N hits inside each.
Why / gotchas:
  • group_limit caps hits per group; pagination applies to number of groups
  • Links: Grouping

Joins — basic

Filter on a joined collection field.
Why / gotchas:
  • Call .joins(:assoc) before referencing $assoc.field
  • Links: Joins, Compiler

Geo search + distance sort

Filter by radius and sort nearest-first; access distance on results.
Why / gotchas:
  • Field must be declared as :geopoint in the model
  • geo_distance_meters is available on hits when order_geo is used
  • Links: Geo Search

Viewport boost with _eval()

Boost documents inside a map viewport polygon, with distance tiebreaker.
Why / gotchas:
  • order_eval wraps the expression in _eval() — do not add _eval() yourself
  • Weighted form: order_eval([{ expr: "...", weight: 3 }, { expr: "...", weight: 1 }])
  • Links: Geo Search → order_eval

Multi‑search two relations

Send two labeled relations in one round‑trip.
Why / gotchas:
  • Per‑search params compiled independently; order preserved by labels
  • Links: Multi‑search

Debug each recipe

Use explain or dry_run! to preview without I/O:
Redaction policy hides literals and secrets; bodies remain copyable. Back to top ⤴

Edge‑case callouts

  • Quoting: strings double‑quoted; booleans and null literal; arrays flattened one level
  • Boolean coercion: only for boolean‑typed fields; strings “true”/“false” accepted
  • Empty arrays: invalid for membership; provide at least one value
  • Reserved characters: prefer templates with placeholders to avoid manual escaping
  • Ambiguous names: unknown fields raise with suggestions when attributes are declared
  • Sort vs group order: sort applies before grouping; group order preserved

Related links: Query DSL, Compiler, DX, Observability, Joins, Grouping, Presets, Curation

Faceting DSL

Add facets and facet queries:
See Faceting for details.