0

I need to organize into the subsequent chain (1..N calls) of apoc.index.in function, something like this:

MATCH (d:Decision)-[:HAS_VALUE_ON]->(ch:Characteristic) WHERE ch.id = 10
CALL apoc.index.in(ch,'HAS_VALUE_ON','property.2.5:7 AND value:45') YIELD node AS decision

MATCH (decision)-[:HAS_VALUE_ON]->(ch:Characteristic) WHERE ch.id = 23
CALL apoc.index.in(ch,'HAS_VALUE_ON','property.1.8:326 OR property.4:17') YIELD node AS decision

MATCH (decision)-[:HAS_VALUE_ON]->(ch:Characteristic) WHERE ch.id = 19
CALL apoc.index.in(ch,'HAS_VALUE_ON','property.15.3:"mike" OR value:43') YIELD node AS decision

RETURN decision

As you may see I need to filter the set of Decision based on different conditions described at apoc.index.in, for example like 'property.15.3:"mike" OR value:43' and so on.

Right now the query above doesn't work. Is it possible with APOC to chain it and if so, could you please show an example.

alexanoid
  • 24,051
  • 54
  • 210
  • 410

1 Answers1

1

You should be able to do this if you can send a list parameter that contains maps of values you plan to use. For example, provided a list parameter of:

inputs = [{chId:10, predicate:"property.2.5:7 AND value:45"}, {chId:23, predicate:"property.1.8:326 OR property.4:17"}, {chId:19, predicate:"property.15.3:'mike' OR value:43"}]

(you'll need to figure out the voodoo to escape the inner quotes around 'mike' properly given the language you're working with)

Then you could use the following query:

UNWIND $inputs as input
MATCH (ch:Characteristic) 
WHERE ch.id = input.chId AND ()-[:HAS_VALUE_ON]->(ch)
CALL apoc.index.in(ch,'HAS_VALUE_ON', input.predicate) YIELD node AS decision
RETURN decision

Because of the UNWIND on the collection, each element of the collection will result in its own row, and the subsequent MATCH and CALL will be executed per row, so your decision results should contain any decision that meets the associated criteria.

InverseFalcon
  • 29,576
  • 4
  • 38
  • 51
  • Thank you very much for your answer. I use Java and I'll try to implement the suggested solution. I have the additional question regarding the result set - will it contain the decisions that meet all of the associated criteria or it will contain the decisions that meet any of the associated criteria? According to my business logic, I need the result set that contains only the decisions that meet all of the associated criteria provided in $inputs. – alexanoid May 09 '18 at 07:28