Skip to main content
Version: 0.3.36

Full-Text Search Functions

Functions that query the Tantivy full-text index. Both take a query string in Tantivy syntax and an ISO 639-1 language code.

Table function. Returns the index hits, ranked, as rows.

Syntax

FULLTEXT_SEARCH(query, language, workspaces => scope [, limit => n])

Arguments

ArgumentTypeDescription
queryTEXTSearch string. Positional, required.
languageTEXTISO 639-1 code such as 'en'. Positional, required. Selects the stemmer. 'english' is rejected.
workspacesTEXTNamed, required. One name, 'a, b, c', a glob 'content-*', or 'ALL READABLE'.
limitINTNamed, optional. Hits taken from the index. Default 100.

Positional arguments must come before named ones. A third positional argument is an error.

Result columns

ColumnTypeDescription
node_id, workspace_idTEXTIdentity of the hit
name, path, node_typeTEXTFrom the node
propertiesJSONBThe node's properties
scoreDOUBLE1 / (60 + fulltext_rank); higher is better
fulltext_rankINT1 for the best hit
vector_rank, vector_distance, chunk_index, embedding_kind, chunk_text, chunk_text_sourceNULL for a full-text-only search; populated by HYBRID_SEARCH and KNN
revisionINTThe node's version
created_at, updated_atTIMESTAMPTZ

Examples

-- top ten
SELECT path, score
FROM FULLTEXT_SEARCH('databases', 'en', workspaces => 'blog')
ORDER BY score DESC
LIMIT 10;

-- filtered
SELECT path, score
FROM FULLTEXT_SEARCH('databases', 'en', workspaces => 'blog', limit => 50)
WHERE node_type = 'raisin:Page'
AND properties->>'status'::String = 'published'
ORDER BY score DESC;

-- several workspaces
SELECT workspace_id, path, score
FROM FULLTEXT_SEARCH('onboarding', 'en', workspaces => 'docs, blog')
ORDER BY score DESC
LIMIT 20;

-- everything the caller may read
SELECT workspace_id, path
FROM FULLTEXT_SEARCH('gdpr', 'en', workspaces => 'ALL READABLE')
LIMIT 20;

-- phrase, exclusion, prefix, field
SELECT path FROM FULLTEXT_SEARCH('"content management"', 'en', workspaces => 'blog');
SELECT path FROM FULLTEXT_SEARCH('+database -tutorial', 'en', workspaces => 'blog');
SELECT path FROM FULLTEXT_SEARCH('datab*', 'en', workspaces => 'blog');
SELECT path FROM FULLTEXT_SEARCH('name:about', 'en', workspaces => 'blog');

Errors

MessageCause
FULLTEXT_SEARCH requires an explicit workspace scopeworkspaces missing
language must be an ISO 639-1 codea word such as 'english'
Field does not exist: 'title'a field: prefix other than name or content
unknown argument '…'a named argument other than workspaces, limit, language

FULLTEXT_MATCH

Boolean predicate for the WHERE clause of a query over a workspace table. The planner turns it into a FullTextScan and applies the remaining predicates to its hits.

Syntax

FULLTEXT_MATCH(query, language)BOOLEAN

Arguments

ArgumentTypeDescription
queryTEXTSearch string
languageTEXTISO 639-1 code. An unknown code matches nothing.

Examples

SELECT path FROM 'blog'
WHERE FULLTEXT_MATCH('databases', 'en');

SELECT path FROM 'blog'
WHERE FULLTEXT_MATCH('databases', 'en')
AND CHILD_OF('/posts')
AND properties->>'status'::String = 'published';
EXPLAIN SELECT path FROM 'blog'
WHERE FULLTEXT_MATCH('databases', 'en') AND properties->>'status'::String = 'published';
-- Project
-- Filter: 1 predicates
-- FullTextScan: lang=en, query=databases

FULLTEXT_MATCH returns rows in index order but exposes no score column. Use FULLTEXT_SEARCH when you need to sort by relevance.


  • HYBRID_SEARCH(query, k, workspaces => …) and KNN(query, k, workspaces => …) share this implementation and add a vector leg. They require an embedding configuration. See Vector Search.
  • PostgreSQL's to_tsvector / to_tsquery / @@ / ts_rank are not available as query operators; use the two functions above.