How to give preference to conditions in neo4j

I want to indicate the order of preferences for the conditions, for example, if there are three conditions that need to be compared, and I want the total number of results to be 20, then first it meets the first condition, and if it gives 20 results, then the other conditions are not compared, and if the first conditions give less than 20 results, then it corresponds to the second condition, and if the total number of results of the first and second states is more than 20, then it gives the first 20 results and does not meet the third condition, and the same will happen for I am the third condition. If all matches do not give 20 results, then it combines the result of the three conditions and adds some random result to make it 20.

+4
source share
1 answer

I think I understand what you want. How about something like that?

OPTIONAL MATCH (node:Label)
WHERE node.a = 1
WITH collect(node) AS set1
OPTIONAL MATCH (node:Label)
WHERE node.a = 2
WITH set1 + collect(node) AS set2
OPTIONAL MATCH (node:Label)
WHERE node.a = 3
WITH set2 + collect(node) AS set3
UNWIND set3 AS node
RETURN node
LIMIT 20
+2
source

Source: https://habr.com/ru/post/1615047/


All Articles