У меня следующий запрос:
MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision)
WHERE dg.id = {decisionGroupId}
MATCH (childD)-[relationshipValueRel1:HAS_VALUE_ON]-(filterCharacteristic1:Characteristic)
MATCH (dg)<-[:DEFINED_BY]-(:CharacteristicGroup)-[characteristicRel1:CONTAINS]->(filterCharacteristic1)
WHERE characteristicRel1.hidden <> true AND filterCharacteristic1.id = 1
WITH relationshipValueRel1, childD, dg
WHERE
({relationshipValueRel11}[0] <= relationshipValueRel1.value <= {relationshipValueRel11}[1] )
WITH childD, dg
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]-(filterCharacteristic2:Characteristic)
MATCH (dg)<-[:DEFINED_BY]-(:CharacteristicGroup)-[characteristicRel2:CONTAINS]->(filterCharacteristic2)
WHERE characteristicRel2.hidden <> true AND filterCharacteristic2.id = 2
WITH relationshipValueRel2, childD, dg
WHERE
(ANY (id IN {relationshipValueRel22} WHERE id IN relationshipValueRel2.value ))
AND (ANY (id IN [1] WHERE id IN relationshipValueRel2.optionIds ))
AND ( relationshipValueRel2.`property.1.4` = {property4} AND relationshipValueRel2.`property.1.4` = {property5} )
WITH childD , dg
ORDER BY childD.createDate ASC
SKIP 0 LIMIT 100
WITH * MATCH (childD)-[ru:CREATED_BY]->(u:User)
OPTIONAL MATCH (childD)-[rup:UPDATED_BY]->(up:User)
RETURN ru, u, rup, up, childD AS decision,
[ (dg)<-[:DEFINED_BY]-(entityGroup)-[:CONTAINS]->(entity)<-[:COMMENTED_ON]-(comg:CommentGroup)-[:COMMENTED_FOR]->(childD)
| {entityId: toInt(entity.id), types: labels(entity), totalComments: toInt(comg.totalComments)} ] AS commentGroups,
[ (c1)<-[vg1:HAS_VOTE_ON]-(childD)
| {criterionId: toInt(c1.id), weight: vg1.avgVotesWeight, totalVotes: toInt(vg1.totalVotes)} ] AS weightedCriteria,
[ (dg)<-[:DEFINED_BY]-(chg:CharacteristicGroup)-[rchgch1:CONTAINS]->(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD) WHERE rchgch1.hidden <> true
| {characteristicId: toInt(ch1.id), v1:v1, optionIds: v1.optionIds, valueIds: v1.valueIds, value: v1.value, available: v1.available, totalHistoryValues: v1.totalHistoryValues, totalFlags: v1.totalFlags, description: v1.description, valueType: ch1.valueType, visualMode: ch1.visualMode} ] AS valuedCharacteristics
Я бы хотел улучшить производительность следующих операций фильтрации:
({relationshipValueRel11}[0] <= relationshipValueRel1.value <= {relationshipValueRel11}[1] )
и
(ANY (id IN {relationshipValueRel22} WHERE id IN relationshipValueRel2.value ))
AND (ANY (id IN [1] WHERE id IN relationshipValueRel2.optionIds ))
AND ( relationshipValueRel2.`property.1.4` = {property4} AND relationshipValueRel2.`property.1.4` = {property5} )
Для этого я создал следующий триггер APOC, чтобы переместить все свойства отношения HAS_VALUE_ON
в индекс:
CALL apoc.trigger.add('RELATIONSHIP_INDEX_ADD_HAS_VALUE_ON', 'UNWIND {createdRelationships} AS r MATCH (d:Decision)-[r:HAS_VALUE_ON]->(ch:Characteristic) CALL apoc.index.addRelationship(r, keys(r)) RETURN count(*)', {phase:'after'});
Сейчас я бы хотел переписать исходный запрос, чтобы заменить операцию фильтрации на
CALL apoc.index.relationships('HAS_VALUE_ON', ...
Кроме того, я не понимаю, как добавить следующие условия filterCharacteristic1.id = 1
и filterCharacteristic1.id = 2
к этому вызову APOC. Я попытался следующий запрос для этой цели:
CALL apoc.index.relationships('HAS_VALUE_ON', 'property.1.4:"1"') YIELD start as childD, end as ch MATCH (childD)-[:HAS_VALUE_ON]-(ch) WHERE ch.id IN [1,2]
но происходит сбой со следующим исключением:
Neo.ClientError.Statement.SyntaxError: Query cannot conclude with MATCH (must be RETURN or an update clause) (line 1, column 100 (offset: 99))
"CALL apoc.index.relationships('HAS_VALUE_ON', 'property.1.4:"1"') YIELD start as childD, end as ch MATCH (childD)-[:HAS_VALUE_ON]-(ch) WHERE ch.id IN [1,2]"
Не могли бы вы показать, как это можно сделать?