Reputation: 761
I have a search items graph model in neo4j.
So I have the following data types nodes:
Item
,
Key
,
and category
Item
has several connected key
s Category
has several connected key
sI want to do a statistic check on the graph. I want to know if I take one key
out of each category
- how many connected Item
s there are for every set of keys.
So, if I had key_A
(12) from category_A
and key_B
(34) from Category_B
, I could do:
START key1 = node(12), key2 = node(34)
MATCH key1 <--(item), key2<--(item)
RETURN count(item)
Pretty simple... But I need to run the same for every set of keys. (one key from each category)
How can I run the same question for each permutation of the keys?
Upvotes: 0
Views: 343
Reputation: 41676
Can you try this?
start cat=node:node_auto_index("name:(Category1 Category2 Category3")
MATCH (item)-->(key)<--(cat)
where (item.type="item")
with key.name as key_name, collect(distinct item.name) as items
order by key.name
with collect(key_name) as keys, reduce(a=[],i in collect(items) : a + i) as items2
return keys, items2, length(items2)
Probably posting an example dataset to http://console.neo4j.org
or describing it as a graph-gist (http://gist.neo4j.org) would be great.
Upvotes: 0
Reputation: 761
Found the answer!
start cat1=node:node_auto_index(name="Category1"),cat2=node:node_auto_index(name="Category2")
MATCH (item) --> (key1)<--(cat1),
(item)--> (key2)<--(cat2)
where (item.type="item")
with key1, key2 , collect(distinct item.name) as items
return key1.name,key2.name, items, length(items)
Upvotes: 2