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.

Search through whole database

shanna
Node Clone

I was wondering how I can search for a search term through the whole database. Like through all properties and node and relationship names.

Suppose I have a database consisting of 2000 elements. And I am looking for the word 'Cat', independent on what type of element it is.

Is there a way I can find this?

3 REPLIES 3

thats going to be quite challenging.

But do you not have some domain knowledge such that for example one would not expect to see the word 'Cat' associated with a property that is a date or a float or a integer?

And then also, what if your data is such that a property represents an array as opposed to a single field.

if i understand correctly you want a single query which will traverse every node, every relationship, every property and if said element contains the word 'Cat' then return said element?

B-D-T
Node Link

Would something like this work?

WITH toLower("cat") AS strSearch
MATCH (n)-[r]-(m)
WITH DISTINCT 
  [x IN keys(n) WHERE toLower(n[x]) CONTAINS strSearch | n] AS propNodeMatch,
  [x IN keys(r) WHERE toLower(r[x]) CONTAINS strSearch | r] AS propRelMatch,
  [x IN labels(n) WHERE toLower(x) CONTAINS strSearch | n] AS labelNodeMatch,
  CASE toLower(type(r)) CONTAINS strSearch WHEN true THEN r END AS typeRelMatch
RETURN DISTINCT
  propNodeMatch + labelNodeMatch AS MatchingNodes,
  propRelMatch+typeRelMatch AS MatchingRels

It would need some tweaking, and performance isn't optimized, but I think it gets close to what you're looking to do.

shanna
Node Clone

Dear @B-D-T , sorry for replying so late, something came up that I have to deal with first. I still didn't have the time to try out your solution, but I will in the near future and get back to you! Thank you for thinking along.