Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-22-2020 12:18 AM
Hi there ,
I encountered an issue about fuzzy query with cypher that puzzled me for one week.
If I'd like to query a person who has the skill contains C++ (ignore the upper case or lower case) , the query below runs well in desktop browser:
match p = (a:Person {user_id:'18501700312'})-[r0..2]->()-[r1]->(b:Person)
where r1.skill =~ '.(?i)C++.*'
But it runs with error if I'd like to query a person who has the skill contains C+++ (ignore the upper case or lower case) ,
match p = (a:Person {user_id:'18501700312'})-[r0..2]->()-[r1]->(b:Person)
where r1.skill =~ '.(?i)C+++.*'
Error msg :
ERROR Neo.ClientError.Statement.SemanticError
Invalid Regex: Dangling meta character '+' near index 9 .(?i)C+++.
I thought + is a special character in cypher , I tried to use escape sign (\) , it does not work well , who can help with this ? Any suggestion would be appreciated , looking forward to your feedback.
Solved! Go to Solution.
04-22-2020 01:59 AM
Hi,
Here's an alternative.
It is easy to understand.
CREATE (:Person {name: 'John'})<-[:SKILL {skill: 'Python'}]-(),
(:Person {name: 'Bob'})<-[:SKILL {skill: 'C'}]-(),
(:Person {name: 'Jane'})<-[:SKILL {skill: 'C++'}]-(),
(:Person {name: 'Lisa'})<-[:SKILL {skill: 'c++'}]-(),
(:Person {name: 'Mike'})<-[:SKILL {skill: 'C+++'}]-(),
(:Person {name: 'Will'})<-[:SKILL {skill: 'c+++'}]-()
MATCH (a:Person)<-[r1]-()
WHERE toLower(r1.skill) CONTAINS toLower('C+++')
RETURN a.name, r1.skill
"C+++" and "c+++" are the return values.
a.name r1.skill
"Mike" "C+++"
"Will" "c+++"
04-22-2020 01:13 AM
Try below query for C+++
match p = (a:Person {user_id:'18501700312'})-[r 0..2]->()-[r1]->(b:Person)
where r1.skill =~ '.*(?i)c\+{3}'
Note: There are two backslash rather than one. editor is not displaying it.
Updated the post to incorporate case insensitive
04-22-2020 02:44 AM
this works well also for this single case , thanks all the same
04-22-2020 03:00 AM
Could you please explain what do you mean by single case ? So that I can correct myself
04-22-2020 01:59 AM
Hi,
Here's an alternative.
It is easy to understand.
CREATE (:Person {name: 'John'})<-[:SKILL {skill: 'Python'}]-(),
(:Person {name: 'Bob'})<-[:SKILL {skill: 'C'}]-(),
(:Person {name: 'Jane'})<-[:SKILL {skill: 'C++'}]-(),
(:Person {name: 'Lisa'})<-[:SKILL {skill: 'c++'}]-(),
(:Person {name: 'Mike'})<-[:SKILL {skill: 'C+++'}]-(),
(:Person {name: 'Will'})<-[:SKILL {skill: 'c+++'}]-()
MATCH (a:Person)<-[r1]-()
WHERE toLower(r1.skill) CONTAINS toLower('C+++')
RETURN a.name, r1.skill
"C+++" and "c+++" are the return values.
a.name r1.skill
"Mike" "C+++"
"Will" "c+++"
04-22-2020 02:34 AM
Really helpful , awesome , it works well , many thanks.
04-22-2020 02:36 AM
Kindly mark the solution to close it
04-22-2020 02:44 AM
Really helpful , awesome , it works well , many thanks.
All the sessions of the conference are now available online