heyarne
heyarne

Reputation: 1167

Ordered children property search

I have a graph that looks like this:

Graph of two entities with a different amount of child nodes, each of which has the properties "order" and "value"

I would like to write a query that returns the correct entity for a search of the concatenated string of the value property of it's children. That is "foo bar" should return the left e:Entity, as should "baz". "ano" should return the right e:Entity.

I am quite new to writing Cypher queries and I'm unsure how I can group and concatenate the l.value at the right time. My hunch is also that this is potentially problematic from a performance perspective as there won't be any index covering these strings that are searched through, is that correct? Is there any way to organize this in a more performant manner?

Upvotes: 0

Views: 29

Answers (1)

jose_bacoy
jose_bacoy

Reputation: 12714

You can do a search on each label value and check if it matches with all words in your search keyword.

I split the keyword(s): "foo bar" into a list ["foo", "bar"]. Then check if all items on this list is found in all values of l. Then return the entity e.

MATCH (e:Entity)--(l:Label)
WITH e, collect(l.value) as allLabels 
   WHERE all(v in split('foo baz',' ') where v in allLabels)
RETURN e

sample output:
╒══════════════════╕
│"e"               │
╞══════════════════╡
│{"name":"entity1"}│
└──────────────────┘

Upvotes: 1

Related Questions