I have created the following Neo4j APOC trigger which adds node properties into the manual index:
CALL apoc.trigger.add('CREATE_NODES_TRIGGER', "UNWIND {createdNodes} AS n
WITH n WHERE labels(n)[1] IN ['Title','Name','Character']
CALL apoc.index.addNodeByName(labels(n)[1], n, keys(n))
RETURN true", {phase:'before'})
When I perform the following query:
CALL apoc.index.nodes('Character','name:An*') YIELD node AS c, weight
RETURN c.name, weight LIMIT 10
it correctly returns the data:
c.name weight
"Annette Porter" 1.0
"Anke Bauernfeind" 1.0
"Angel's Henchman" 1.0
"Anna Slovatzka Marshall" 1.0
"Andrew Horvath" 1.0
"Angela Somes" 1.0
"An-Soo 'Alison' Kim" 1.0
"Annette Holman" 1.0
"Anita Wilcox" 1.0
"Anna Cerdick" 1.0
but in case of lowercased query name:an*
:
CALL apoc.index.nodes('Character','name:an*') YIELD node AS c, weight
RETURN c.name, weight LIMIT 10
the result is empty.
I think I should lowercase the property values before adding them to the index. Am I right?
If so, could you please help to improve the trigger in order to lowercase the property values:
CALL apoc.trigger.add('CREATE_NODES_TRIGGER', "UNWIND {createdNodes} AS n
WITH n WHERE labels(n)[1] IN ['Title','Name','Character']
CALL apoc.index.addNodeByName(labels(n)[1], n, keys(n))
RETURN true", {phase:'before'})
Or please suggest another way how to solve this issue. Thanks!
UPDATED
I found the following property in neo4j.conf:
apoc.autoIndex.enabled=true
and added all nodes to the index:
CALL apoc.index.addAllNodes('movies',{
Title: ["primaryTitle", "originalTitle"],
Name: ["primaryName"],
Character: ["name"]}, {autoUpdate:true})
So, right now I have a question: will apoc.autoIndex.enabled=true
only track and reflect changes on the already added nodes to the index(with apoc.index.addAllNodes
) or it will also add the newly created Title
, Name
and Character
nodes to the index also?