cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Exact match for string with CONTAINS

takhims
Node Link

Hi all, i have been stuck on an issue related to cypher matching.

So we have multiple nodes which contains a property 'x_matchKey' and we use this x_matchKey property to fetch the result with a CONTAINS.

the query goes like that that:
MATCH (a:person)->[r:occupies]->(b:position) WHERE b.x_matchKey contains 'cto' return a. This query is intended to fetch the person whose position is cto. Its was working fine from past few years.

Now there's another node which contains 'director' in the x_matchKey property.

So when i run this query now, it returns both persons as 'director' also contains 'cto'.

Also, i can't use '=' operator as x_matchKey contains various terms for a person (Like 'cto, Chief Techniology Officer, EVP, Technical officer'). Basically there are more than two comma separated values for each x_matchKey.

Is there any way that i can search if a property contains only a specific word rather than a substring?

I hope i have explained it well, if not please feel free to reply on this thread.

Thanks in advance for all the future suggestions.

3 REPLIES 3

Maybe you should store the descriptions as a list instead of a comma concatenated string. You could then determine if the list contains the exact phrase you want.

if that is not an option, you could split the string into a list and determine if the list contains the exact string you want to match.

you could also use a grep search to restrict you results so that it is a whole word from a comma concatenated list.

https://neo4j.com/docs/cypher-manual/current/functions/string/#functions-split

ameyasoft
Graph Maven

Try this:
MATCH (a:person)->[r:occupies]->(b:position) WHERE b.x_matchKey contains 'cto,' return a

Hi,

It looks very easy, why not

MATCH (a:person)->[r:occupies]->(b:position) WHERE b.x_matchKey = 'cto'

Why do not change the architecture to store cto in property "name" and maybe use other id system to have unique condition..... name = 'cto' id = '001' so

MATCH (a:person)->[r:occupies]->(b:position {matchKey: 'cto'}) RETURN a.name
or
MATCH (a:person)->[r:occupies]->(b:position {name: 'cto'}) RETURN a.name
or
MATCH (a:person)->[r:occupies]->(b:position {id: '001'}) RETURN a.name

Regards

Vaclav