Please note that in Neo4j 2.3 new text search operators were added: STARTS WITH, CONTAINS and ENDS WITH. Of these only STARTS WITH will utilize an schema index, you can use ENDS WITH in conjunction with reverse() to store a separate property for reverse lookup.

As of Neo4j 2.2.x, the new schema index is optimal for indexing exact property values, but does not support “fuzzy” or full-text search. However, legacy indexing does allow for optimization for these types of queries, relying on auto-indexes. Here’s how to do it:

First we need to enable the legacy indexing by editing the conf/neo4j.properties file and edit the following lines as shown:

# Enable auto-indexing for nodes, default is false.
node_auto_indexing=true
Then in the same file add the node property keys to be auto-indexed.

# The node property keys to be auto-indexed, if enabled.
node_keys_indexable=name,title,tagline

By default, the auto-index will take the type as “exact”. To change to type “fulltext” we can do it using neo4j-shell.

In bin/neo4j-shell, type in to get the current auto-index configuration:

index --get-config node_auto_index

neo4j-sh (?)$ index --get-config node_auto_index
{
   "provider": "lucene",
   "type": "exact"
}

To change the configuration to “fulltext” execute the following command in neo4j-shell

neo4j-sh (?)$ index --set-config node_auto_index type fulltext
INDEX CONFIGURATION CHANGED, INDEX DATA MAY BE INVALID

Repopulate those columns on which it is indexed as given in the below example from the Movie database:

MATCH (n:Movie) SET n.title = n.title;

Then check the auto-index config to confirm if the type is changed to “fulltext”

neo4j-sh (?)$ index --get-config node_auto_index
{
    "provider": "lucene",
    "type": "fulltext"
}

Run the query to use fulltext:

neo4j-sh (?)$ start n=node:node_auto_index("title:*atri*") return n;
+-------------------------------------------------------------------------------------------------------------+
| n                                                                                                           |
+-------------------------------------------------------------------------------------------------------------+
| Node[0]{title:"The Matrix",released:1999,tagline:"Welcome to the Real World"}                               |
| Node[9]{title:"The Matrix Reloaded",released:2003,tagline:"Free your mind"}                                 |
| Node[10]{title:"The Matrix Revolutions",released:2003,tagline:"Everything that has a beginning has an end"} |
+-------------------------------------------------------------------------------------------------------------+
3 rows
18 ms

Details


Author:
Dave Gordon
Applicable versions:
2.0,2.1,2.2
Keywords:
fulltextneo4j-2.0neo4j-2.1neo4j-2.2search