neo4j - Neo4j Cypher 使用 APOC apoc.index.relationships 更改过滤操作
问题描述
我有以下查询:
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]"
你能展示一下它是怎么做的吗?
解决方案
推荐阅读
- html - 致命:遥控器意外挂断。无法将内容推送到我的 git 存储库
- continuous-integration - Azure Pipelines:使用 Azure App Service Deploy 排除文件夹
- mysql - MySQL:使用 id 将 table2 中的条目与 table1 中的条目匹配,然后将匹配项作为新列插入 table2
- r - 如何将 str_split 应用于具有一个字符列的小标题?
- vega - vega-lite 中的计算
- google-ads-api - 在哪里可以找到正确的 HTTP 端点以在 Oauth2 Playground 中测试 Google Ads API 调用?
- css - 如何使用 CSS 将旋转的元素动态匹配到父元素?
- ios - 在 mac 催化剂上更改 UITextField 的提示颜色
- sql - 如何在 AS3 中测试 SQL 连接是否打开?
- php - PHP Imagick PDF 到 JPEG 字符间距问题