Full-text search
Wiki / Indexes and constraints
On this page
Full-text search (BM25)
A full-text index over a (label, string-property) pair, ranked
with BM25 (the Lucene/Tantivy default scoring). It is a reimplementation of
the valuable core of Lucene — an analyzer pipeline, postings with term
frequencies, and BM25 — not a dependency.
Declare
CREATE FULLTEXT INDEX ON :Article(body);
CREATE FULLTEXT INDEX ON :Article(body) LANGUAGE 'english'; // language hint
SHOW FULLTEXT INDEXES;
The index backfills existing string values and is maintained on every write. (The language hint is recorded for forward compatibility; v1 analyses as English.)
A list value is analysed per string element — nulls and non-string
elements are skipped. A staged value like name: ['ACME Ltd', null, 'ACME Holdings']
(see Element indexes and staged values) is therefore searchable, and a
subscript write (SET c.name[2] = '…') re-indexes the document.
Query with SEARCH
SEARCH :Article(body) FOR 'rooftop pool'; // → (node, score), best first
SEARCH :Article(body) FOR 'rooftop pool' LIMIT 10; // cap the results
SEARCH returns nodes ranked by BM25 score, highest first (ties broken by
ascending id). The query text is analysed with the same analyzer used at index
time, so analysis is symmetric.
v1 semantics & limits
- Bag-of-words with OR semantics: a document matches if it contains any query term; more/rarer matched terms score higher.
- Not yet: phrase queries, stemming, fuzzy matching, boolean operators, positions/highlighting.
Remove the declaration after querying with DROP FULLTEXT INDEX ON :Article(body).
Related articles
EXPLAIN and PROFILE · Resident and hybrid storage · Schema and maintenance procedures