# Full-text search

[Wiki](../README.md) / [Indexes and constraints](README.md)

**On this page**

- [Full-text search (BM25)](#full-text-search-bm25)
  - [Declare](#declare)
  - [Query with SEARCH](#query-with-search)
  - [v1 semantics & limits](#v1-semantics--limits)

## 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

```cypher
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 — `null`s and non-string
elements are skipped. A staged value like `name: ['ACME Ltd', null, 'ACME Holdings']`
(see [Element indexes and staged values](element.md#element-multi-entry-indexes)) is therefore searchable, and a
subscript write (`SET c.name[2] = '…'`) re-indexes the document.

### Query with `SEARCH`

```cypher
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.

From version 2.4.0, with `YIELD`, `SEARCH` becomes a clause like any other: its hits join the rows
around it, and `YIELD … WHERE` filters them.

```cypher
SEARCH :Article(body) FOR 'rooftop pool' LIMIT 10 YIELD node AS article, score
MATCH (author)-[:WROTE]->(article)
RETURN author.name, article.title, score;

MATCH (h:Hotel {city: 'Lisbon'})
SEARCH :Review(text) FOR 'rooftop pool' YIELD node WHERE node.hotel = h.id
RETURN h.name, node.text;
```

### 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](../cypher/planning.md) · [Resident and hybrid storage](../operations/storage.md) · [Schema and maintenance procedures](../cypher/procedures.md)
