examples · fts · 3 / 6
3. Boolean search - multi-token AND
← FTS exampleswhat 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"hits = db.fts.search(
"shop.products",
"description",
q="wireless headphones",
mode="boolean",
)
for doc_id in hits.doc_ids:
print(doc_id)const hits = await db.ftsSearch("shop.products", "description", {
q: "wireless headphones",
mode: "boolean",
});
for (const docId of hits.doc_ids) {
console.log(docId);
}hits, _ := db.FTSSearch(ctx, "shop.products", "description", originchain.FTSSearchRequest{
Q: "wireless headphones",
Mode: "boolean",
})
for _, docID := range hits.DocIDs {
fmt.Println(docID)
} 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_idsclient-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.