Ben
Ben

Reputation: 23

neo4j: How do I query multiple properties for the same string?

I'm very new to neo4j and code generally. I'm trying to query multiple properties of my nodes for the same string, but don't want to have to type out my string in several times for each search.

For instance, right now my code is:

START b=node(*) 
WHERE (b.name =~ '(?i).*edward.*' OR b.alias =~ '(?i).*edward.*') 
RETURN b

Which means that I have to type out 'edward' twice for each search. Is there a way to avoid this?

Upvotes: 2

Views: 1214

Answers (2)

stdob--
stdob--

Reputation: 29167

You need the ANY function:

MATCH (b)
  WHERE ANY(k IN ['name', 'alias'] WHERE toString(b[k]) =~ '(?i).*edward.*') 
RETURN b

Upvotes: 1

dmiranda2791
dmiranda2791

Reputation: 21

Define you regex in a parameter and use it like this: :param regex: '(?i).edward.'

START b=node(*)
WHERE (b.name =~ $regex OR b.alias =~ $regex)
RETURN b

Upvotes: 0

Related Questions