I have a Neo4j database (2.0.3). I am currently using Cypher to run some test queries on my dataset. I have a set of records that have a property containing an array of names. I want to be able to search this array of names, while also using a basic reg-ex to do so. Is this at all possible within cypher? If not how do you reccommend going about this?
Something that would combine both of these queries:
MATCH (s:Record) WHERE "John" IN s.name RETURN s;
MATCH (s:Record) WHERE s.name =~ '(?i).*john.*)' RETURN s;
Consider the following example data:
CREATE (:Record {name: ['John', 'Bob']}),
(:Record {name: ['Alice', 'Johnny']}),
(:Record {name: ['the johnster', 'Charles']}),
(:Record {name: ['Danny', 'Josh']})
If you want to find all Records where any of the elements in the property array name
matches a regexp, use ANY
. If you want to find all Records where all elements in the property array name
match a regexp, use ALL
. I believe you want the former:
MATCH (s:Record)
WHERE ANY(name IN s.name WHERE name =~ '(?i).*john.*')
RETURN s.name
This returns:
s.name
John, Bob
Alice, Johnny
the johnster, Charles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With