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.

Cypher query

Hi,
I have a cypher query to check in the DB for the search results, using where condition to check the parameters entered. I have a lot of properties for which query should check in the DB. I have added a few in the query below. I am using javascript driver for this
My Query is as follows:
`

match (n)--() where n.name =~ '(?i).' + queryStr + '.' n.email =~ '(?i).' + queryStr + '.' or n.type =~ '(?i).' + queryStr + '.' or n.phoneNumber =~ '(?i).' + queryStr + '.' or labels(n)[0] =~ '(?i).' + queryStr + '.' return n

`

I need to add almost 10 more properties to the cypher query is there a better way to go about this and is there a way to check for all properties instead of hardcoding it?

Thank you,
Viral

3 REPLIES 3

Hi,

You can use param like this ($name).

try {
  const result = await session.run(
    'MATCH (n)-[]-() WHERE n.name =~ $name OR n.email =~ $email... RETURN n',
    { name: personName, email: personEmail... }
  )

https://neo4j.com/developer/javascript/#javascript-driver

Hi koji,
Thanks for the answer but according to my query this will still be hardcoding, If I change my database and it has new property keys I will have to change the match query based on those particular keys.
I am looking for a way to write a query where it can check for any property in the db.
Suppose from the search bar name is entered it will check for name if email it will check for email and so on.
Is this possible via queries?

Hello @vsanghavi

Did you have a look at indexes for full text search?

Regards,
Cobra