Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-15-2021 09:51 AM
Hello:
I'm trying to perform a full-text search using a regex, but I cannot get to the right syntax or get the expected results.
Let's say I have a database with persons, a full text index on the name and I want to query users by name using a regex to find the persons whose name begins with michael j. I expect to get michael jones, michael johnson, michael jonas...
I am trying to write a query like this:
CALL db.index.fulltext.queryNodes('person_name_fulltext', '/michael j.*/')
YIELD node as person, score
RETURN person, score
But I don't get any results.
Any ideas on what am I doing wrong?
Thank you!
Solved! Go to Solution.
07-16-2021 02:04 AM
Hello @nachogonzalez and welcome to the Neo4j community
I created a database with 4 nodes:
CREATE (:Person {name: "MICHAEL j"});
CREATE (:Person {name: "michael JONES"});
CREATE (:Person {name: "michael johnson"});
CREATE (:Person {name: "MICHAEL JONAS"});
Then create the search index on name
property of Person
nodes:
CREATE FULLTEXT INDEX person_name_index IF NOT EXISTS FOR (n:Person) ON EACH [n.name]
This query will return the 4 nodes. (?i)
makes sure to match string with lower and upper characters and *
to finish with anything:
CALL db.index.fulltext.queryNodes('person_name_index', '(?i)michael j*')
YIELD node AS person, score
RETURN person, score
You can also use a classic Cypher query:
MATCH (p:Person)
WHERE p.name =~ '(?i)michael j.*'
RETURN p.name
Regards,
Cobra
07-16-2021 02:04 AM
Hello @nachogonzalez and welcome to the Neo4j community
I created a database with 4 nodes:
CREATE (:Person {name: "MICHAEL j"});
CREATE (:Person {name: "michael JONES"});
CREATE (:Person {name: "michael johnson"});
CREATE (:Person {name: "MICHAEL JONAS"});
Then create the search index on name
property of Person
nodes:
CREATE FULLTEXT INDEX person_name_index IF NOT EXISTS FOR (n:Person) ON EACH [n.name]
This query will return the 4 nodes. (?i)
makes sure to match string with lower and upper characters and *
to finish with anything:
CALL db.index.fulltext.queryNodes('person_name_index', '(?i)michael j*')
YIELD node AS person, score
RETURN person, score
You can also use a classic Cypher query:
MATCH (p:Person)
WHERE p.name =~ '(?i)michael j.*'
RETURN p.name
Regards,
Cobra
All the sessions of the conference are now available online