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, as a bare JSON array of strings. No scoring is computed and no ordering is implied - this is a set, not a ranked list. Boolean is the default mode; you get it even if you omit mode.
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"# Boolean search returns a bare JSON array of doc_id strings
doc_ids = db.fts.search(
"shop.products",
"description",
q="wireless",
mode="boolean",
)
for doc_id in doc_ids:
print(doc_id)// Boolean search returns a bare string[] of doc_ids
const docIds = await db.ftsSearch("shop.products", "description", {
q: "wireless",
mode: "boolean",
});
for (const docId of docIds) {
console.log(docId);
}// Boolean search returns []string of doc_ids
docIDs, _ := db.FTSSearch(ctx, "shop.products", "description", originchain.FTSSearchRequest{
Q: "wireless",
Mode: "boolean",
})
for _, docID := range docIDs {
fmt.Println(docID)
} what you get back
["p001", "p014", "p027"]
The body is the array itself - there is no { "mode": ..., "doc_ids": [...] } wrapper. Parse it and iterate directly.
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 returned array is sorted lexicographically by
doc_id, not by relevance. Don't read any ranking into the order. - Looking for a
.doc_idsfield. The response is the bare array -["p001", "p014"]- not an object. Accessing.doc_idson it returns undefined. - Expecting case sensitivity. The query token is lowercased to match indexing -
q=Wirelessandq=wirelessbehave identically. - Passing multiple tokens and expecting OR. Multi-token boolean is AND - see the next example.