Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 114 additions & 11 deletions pages/querying/text-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ To list all text indices in Memgraph, use the `SHOW INDEX INFO`

## Query text indices

<Callout type="warning">

Within a single transaction, repeated text searches may return different results if other transactions have committed their changes to the same index.
For consistent results, avoid performing multiple identical searches within the same transaction when concurrent modifications are expected.

</Callout>

Querying text indices is done through query procedures.

<Callout type="info">
Expand Down Expand Up @@ -109,6 +116,31 @@ YIELD node
RETURN node;
```

{<h4 className="custom-header">Example</h4>}

```cypher
CREATE TEXT INDEX complianceDocuments ON :Document;
CREATE (:Document {title: 'Rules2024', version: 1});
CREATE (:Document {title: 'Rules2024', version: 2});
CREATE (:Document {title: 'Other', version: 2});

// Search for documents with title containing 'Rules2024'
CALL text_search.search('complianceDocuments', 'data.title:Rules2024')
YIELD node
RETURN node.title AS title, node.version AS version
ORDER BY version ASC;
```

Result:
```
+-------------+-------------+
| title | version |
+-------------+-------------+
| "Rules2024" | 1 |
| "Rules2024" | 2 |
+-------------+-------------+
```

### Search over all indexed properties

The `text_search.search_all` procedure looks for text-indexed nodes where at
Expand Down Expand Up @@ -137,6 +169,30 @@ YIELD node
RETURN node;
```

{<h4 className="custom-header">Example</h4>}

```cypher
CREATE TEXT INDEX complianceDocuments ON :Document;
CREATE (:Document {title: 'Rules2024', fulltext: 'text words', version: 1});
CREATE (:Document {title: 'Other', fulltext: 'Rules2024 here', version: 3});

// Search for 'Rules2024' across all properties
CALL text_search.search_all('complianceDocuments', 'Rules2024')
YIELD node
RETURN node
ORDER BY node.version ASC;
```

Result:
```
+----------------------------------------------------------------------+
| node |
+----------------------------------------------------------------------+
| (:Document {fulltext: "text words", title: "Rules2024", version: 1}) |
| (:Document {fulltext: "Rules2024 here", title: "Other", version: 3}) |
+----------------------------------------------------------------------+
```

### Regex search

The `text_search.regex_search` procedure looks for text-indexed nodes where at
Expand Down Expand Up @@ -164,6 +220,30 @@ YIELD node
RETURN node;
```

{<h4 className="custom-header">Example</h4>}

```cypher
CREATE TEXT INDEX complianceDocuments ON :Document;
CREATE (:Document {fulltext: 'words and things'});
CREATE (:Document {fulltext: 'more words'});

// Search using regex pattern 'wor.*s'
CALL text_search.regex_search('complianceDocuments', 'wor.*s')
YIELD node
RETURN node
ORDER BY node.fulltext ASC;
```

Result:
```
+--------------------------------------------+
| node |
+--------------------------------------------+
| (:Document {fulltext: "more words"}) |
| (:Document {fulltext: "words and things"}) |
+--------------------------------------------+
```

### Aggregations

Aggregations allow you to perform calculations on text search results. By using
Expand Down Expand Up @@ -196,12 +276,38 @@ The following query counts all nodes in the `complianceDocuments` index:
CALL text_search.aggregate(
"complianceDocuments",
"data.title:Rules2024",
'{"count": {"value_count": {"field": "metadata.gid"}}}'
'{"count": {"value_count": {"field": "data.version"}}}'
)
YIELD aggregation
RETURN aggregation;
```

{<h4 className="custom-header">Example</h4>}

```cypher
CREATE TEXT INDEX complianceDocuments ON :Document;
CREATE (:Document {title: 'Rules2024', version: 1});
CREATE (:Document {title: 'Rules2024', version: 2});

// Count documents matching the search query
CALL text_search.aggregate(
'complianceDocuments',
'data.title:Rules2024',
'{"count":{"value_count":{"field":"data.version"}}}'
)
YIELD aggregation
RETURN aggregation;
```

Result:
```
+-------------------------------+
| aggregation |
+-------------------------------+
| "{\"count\":{\"value\":2.0}}" |
+-------------------------------+
```

## Drop text indices

Text indices are dropped with the `DROP TEXT INDEX` command. You need to give
Expand All @@ -213,18 +319,15 @@ This statement drops the text index named `complianceDocuments`:
DROP TEXT INDEX complianceDocuments;
```

If one attempts to delete an index with the same name twice, the statement will
fail.

## Compatibility

Even though text search is an experimental feature, it supports most usage modalities
that are available in Memgraph from version 3.5. Refer to the table below for an overview:

| Feature | Support |
|-------------------------|--------------------------------------------- |
| Multitenancy | ✅ Yes |
| Durability | ✅ Yes |
| Storage modes | ❌ No (doesn't work in IN_MEMORY_ANALYTICAL) |
| Replication | ✅ Yes (from version 3.5) |
| Concurrent transactions | ✅ Yes (from version 3.5) |
| Feature | Support |
|-------------------------|---------------------------------------------------------|
| Multitenancy | ✅ Yes |
| Durability | ✅ Yes |
| Replication | ✅ Yes (from version 3.5) |
| Concurrent transactions | ⚠️ Yes, but search results may vary within transactions |
| Storage modes | ❌ No (doesn't work in IN_MEMORY_ANALYTICAL) |