OriginChain docs
examples · fts · 3 / 6

3. Boolean search - multi-token AND

← FTS examples
what this does

Returns documents whose description contains both wireless and headphones. Tokens are intersected. The tokens can appear in any order and anywhere in the document - for "in order, next to each other," use phrase mode.

when to use it
  • Filtering down a result set by multiple required attributes ("organic" AND "coffee").
  • Tag intersections - any doc that mentions every tag.
  • You don't care about ranking and you want the smallest possible response.
the request

Tokens are space-separated in q. Some clients show this URL-encoded as wireless+headphones - same thing.

GET /v1/tenants/:t/fts/:schema/:field?q=...&mode=boolean
curl -G "https://$OC_HOST/v1/tenants/$OC_TENANT/fts/shop.products/description" \
  -H "Authorization: Bearer $OC_TOKEN" \
  --data-urlencode "q=wireless headphones" \
  --data-urlencode "mode=boolean"
what you get back
{
  "mode": "boolean",
  "doc_ids": ["p001", "p027"]
}
how it works
  • The query is tokenised into a list - here ["wireless", "headphones"].
  • The engine fetches the posting list for each token and intersects them. Smallest list first keeps the work bounded by the rarest term.
  • The intersection is the answer. No scoring is computed.
common mistakes
  • Assuming OR behaviour. Multi-token boolean is strictly AND - there is no OR mode. For OR, run two separate queries and union the doc_ids client-side.
  • Expecting proximity. AND doesn't care where the tokens sit - "wireless mouse and wired headphones" matches "wireless headphones". Use phrase mode if you need them adjacent.
  • Adding a rare token to "help match more". AND only narrows - every extra token can only remove docs, never add.