Matching all nodes related to a set of other nodes

Matching all nodes related to a set of other nodes

I'm just getting started with neo4j and would like some help trying to solve a problem.

I have a set of Questions that require information (Slots) to answer them.

The rules of the graph (i.e. the Slots required for each Question) are shown below:

graph LR
C[QUESTION 1] -- requires --> E[SLOT A]
C-- requires --> F[SLOT B]
G[QUESTION 2] -- requires --> E
G -- requires --> H[SLOT C]

In a scenario in which I have a set of slots e.g. [Slot A, Slot B] I want to be able to check all Questions that the Slots are related to e.g. [Question 1 , Question 2].

I then want to be able to check for which of the Questions all required Slots are available, e.g. [Question 1]

Is this possible, and if so how should I go about it?

You don't have enough of a graph model to know for sure, but it would be something like this:

MATCH (q:Question)-[:REQUIRES]->(shared:Slot { required: true })
WITH shared, collect(q) as questions
WHERE length(questions) >= 2
RETURN shared, questions;

What that does is collect up all of the questions that are shared in common by a given slot. It filters them down to only those slots that are in more than 1 question, and returns the shared slot, along with a list of questions it's in.