Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-26-2022 04:27 PM
I want to query my graph which should return the nodes which end with the word "Shock". I have two options for that, one node has the word "Shock" another has the word "Septic Shock". I want to run a single query that uses the word shock and return nodes for both of them.
match (:Symptom_Name{Name:"Shock"})-[:Causes]->(a) return a
This query just gives the answer for Shock and not septic shock.
Can someone please guide me on the same?
Thanks.
01-26-2022 05:04 PM
You could try the CONTAINS predicate.
match (n:Symptom_Name)-[:Causes]->(a)
where n.Name contains 'Shock'
return a
01-26-2022 05:15 PM
Hello,
Thanks for the response, I tried that but it seems case sensitive, the Septic shock has small s so the query is not helping me to get that node.
Can we check for the case of the word?
Thanks
01-26-2022 05:45 PM
ok, make the value lower case and test that:
match (n:Symptom_Name)-[:Causes]->(a)
where toLower(n.Name) contains 'shock'
return a
01-26-2022 05:56 PM
By the way, if you only want to match to strings ending in 'shock', then you need to use 'ends with' instead of 'contains.' There is also 'starts with'
the reference card is very handy:
https://neo4j.com/docs/cypher-refcard/current/
These string predicates are described under the 'Predicate' section on the right-hand-side.
01-26-2022 06:18 PM
Thank you so much for your help 🙂
01-28-2022 01:08 AM
Hello @nikitagajra1998
You could improve your query performance with a regex:
MATCH (n:Symptom_Name)-[:Causes]->(a)
WHERE n.Name =~ "(?i).*" + 'Shock'
RETURN a
This query is faster and not case sensitive.
Regards,
Cobra
01-30-2022 02:24 PM
Hello Cobra,
It helped a lot.
Thanks & Regards,
Nikita Gajra
02-09-2022 06:38 AM
Another option to consider would be to create a full-text index on the node or node property/label. Should be insensitive to case, unless you make it sensitive. This index effectively drops a search engine behind your neo4j DB.
Once indexed you can use the db.index.fulltext.queryNodes function with 'shock' as query string. This query should give you both nodes. If not try 'shock~', fuzzy search.
I believe you can adjust the query string to only match text that ends in 'Shock'. If you add more nodes that contain "Shock".
To dig in: Full-text search index - Neo4j Cypher Manual
All the sessions of the conference are now available online