Based on the previous question:
Neo4j Cypher query structure and performance optimization Neo4j Cypher node filtering by pattern comprehension
finally I have refactored my query to the following:
MATCH (parentD)-[:CONTAINS]->(childD:Decision)
WHERE id(parentD) = {decisionId}
MATCH (childD)<-[:SET_FOR]-(equalFilterValue)-[:SET_ON]->(equalFilterCharacteristic)
WHERE ALL(key IN keys({equalFilters}) WHERE id(equalFilterCharacteristic) = toInt(key) AND equalFilterValue.value = ({equalFilters}[key]))
WITH DISTINCT childD
MATCH (childD)<-[:SET_FOR]-(rangeFilterValue)-[:SET_ON]->(rangeFilterCharacteristic)
WHERE ALL(key IN keys({rangeFilters}) WHERE id(rangeFilterCharacteristic) = toInt(key) AND ({rangeFilters}[key])[0] <= rangeFilterValue.value <= ({rangeFilters}[key])[1])
WITH * MATCH (childD)-[ru:CREATED_BY]->(u:User)
RETURN ru, u, childD AS decision
SKIP 0 LIMIT 100
This query works fine if each *filter
type(map) has only one key, for example:
queries.add(new InQuery(integerCharacteristic.getId(), 30));
or
queries.add(new InQuery(stringCharacteristic.getId(), "Two"));
but fails when I add 2 or more conditions, for example:
queries.add(new InQuery(integerCharacteristic.getId(), 30));
queries.add(new InQuery(stringCharacteristic.getId(), "Two"));
The following query doesn't work as expected and my test assertions fail:
MATCH (parentD)-[:CONTAINS]->(childD:Decision)
WHERE id(parentD) = {decisionId}
MATCH (childD)<-[:SET_FOR]-(inFilterValue)-[:SET_ON]->(inFilterCharacteristic)
WHERE ALL(key IN keys({inFilters}) WHERE id(inFilterCharacteristic) = toInt(key) AND ({inFilters}[key]) IN inFilterValue.value)
WITH * MATCH (childD)-[ru:CREATED_BY]->(u:User)
RETURN ru, u, childD AS decision
SKIP 0 LIMIT 100
The parameter:
inFilters = {3153=30, 3151=Two}
Why it doesn't work when inFilters
map contains 2 or more keys and how to make it working ?