examples · fts · 2 / 6
2. Boolean search - single token
← FTS exampleswhat this does
Returns the doc_id of every document whose description contains the token wireless. No scoring is computed and no ordering is implied - this is a set, not a ranked list.
when to use it
- "Does any product mention X" - membership checks, not relevance.
- Pre-filter step before a more expensive query (rank only the matched set).
- Tag-style search where every match is equally important.
If you need ordering by relevance, use BM25 mode instead.
the request
Assumes you've indexed at least a few documents - see Example 1.
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" \
--data-urlencode "mode=boolean"hits = db.fts.search(
"shop.products",
"description",
q="wireless",
mode="boolean",
)
for doc_id in hits.doc_ids:
print(doc_id)const hits = await db.ftsSearch("shop.products", "description", {
q: "wireless",
mode: "boolean",
});
for (const docId of hits.doc_ids) {
console.log(docId);
}hits, _ := db.FTSSearch(ctx, "shop.products", "description", originchain.FTSSearchRequest{
Q: "wireless",
Mode: "boolean",
})
for _, docID := range hits.DocIDs {
fmt.Println(docID)
} what you get back
{
"mode": "boolean",
"doc_ids": ["p001", "p014", "p027"]
} how it works
- The query is tokenised with the same analyser used at index time - lowercased and split on whitespace/punctuation.
- The single token is looked up in the inverted index. The posting list for that token is the answer.
- Because there's no scoring step, boolean mode is the cheapest query shape - constant work per matching doc, no per-doc maths.
common mistakes
- Expecting a ranked order. The
doc_idsarray is in whatever order the engine returns them. Don't rely on it being sorted by relevance, or by anything else. - Treating absence of a token as a non-match. Tokens go through the analyser - if the analyser strips stop-words,
q=thewill match nothing even if "the" appears everywhere. - Passing multiple tokens and expecting OR. Multi-token boolean is AND - see the next example.