0
votes

When running Neo4j embedded, the default configuration doesn't have the automatic node index set as fulltext (meaning that all Lucene queries are case sensitive). How can I configure the automatic index to be fulltext?

1

1 Answers

3
votes

For starters, you must perform this on a new database. The automatic index is lazily created, which means that it isn't created until the first access. You have until the first access to perform this configuration. If you attempt to change the property after it's already been created, it won't work. So the first step is to load the database with automatic indexing enabled (node or relationship).

val db = new GraphDatabaseFactory().newEmbedddedDatabaseBuilder("path/to/db").
  setConfig(GraphDatabaseSettings.node_keys_indexable, "label,username").
  setConfig(GraphDatabaseSettings.node_auto_indexing, "true").newGraphDatabase()

Now, before you do anything, you have to set the configuration properties. You can find out about the possible properties and values here. To do this, we just need two more lines.

val autoIndex = db.index.forNodes("node_auto_index")
db.index.setConfiguration(autoIndex, "type", "fulltext")

And that's all there is to it. You can now create vertices and relationships and the automatic index will be created and populated. You can get use the following code to query it using any Lucene query.

autoIndex.getAutoIndex.query("label:*caseinsensitive*")