Neo4j的实施意见 [英] Neo4j implementing comments

查看:259
本文介绍了Neo4j的实施意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的春节,启动/ Neo4j的应用程序,我有Neo4j的节点的一棵大树,现在我想实现多层次的意见对各节点的。

In my Spring Boot/Neo4j application I have a big tree of Neo4j nodes and now I would like to implement hierarchical comments for each of these node.

现在,我想在那里这些评论必须放置在......在Neo4j的数据库或其他外部RDBMS / NoSQL的存储空间。

Right now I'm thinking of where these comments must be placed in... In Neo4j database or in some other external RDBMS/NoSQL storage.

为什么我想它 - 因为现在我面临着(与许多关系到其他节点的节点组合)去除沉重的Neo4j节点的问题我有限的知识Cypher支架..和我不解决这个问题现在的问题..所以引入新的注释节点可以完全杀死我的系统。

Why I'm thinking about it - because of my limited Cypher knowledge right now I'm faced with the problem of removing heavy Neo4j nodes(composite nodes with many relationships to other nodes).. and I can't fix this issue now.. so introducing new Comment nodes can totally kill my system.

所以,你怎么想,我应该尝试解决问题,删除或实施一些外部数据存储评论?

So what do you think, should I try to fix the delete issue or implement Comments in some external data storage ?

更新时间:

这是我的慢删除查询:

MATCH (d:Decision) 
WHERE id(d) IN {decisionsIds} 
OPTIONAL MATCH (d)-[r]-(t) 
DELETE d, r 
WITH t, r WHERE NOT (id(t) IN {decisionsIds}) 
OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-()-[r3:CONTAINS]-(t2) WHERE r2 <> r 
WITH t, r2, t2, r3 
WHERE none(x in labels(t) 
WHERE x in ['User', 'Decision']) 
DELETE t, r2, t2, r3

现在这个查询的工作很长一段时间,所以我不敢为了不彻底杀灭性能增加新的实体决策节点。

Right now this query works long time so I afraid to add new entities to Decision node in order to not kill the performance completely.

时的任何方式来优化这个查询?

Is any way to optimize this query ?

推荐答案

如果没有一个数据库,这是一个小的优化企图,不知道这是否会有所帮助。

Without a db this is an attempt for a small optimization, not sure if it helps.

这将是也是很好的了解更多的领域模型和元素之间的基数(如 D T

It would be also good to know more about the domain model and the cardinalities between the element (e.g. between d and t)

MATCH (d:Decision) WHERE id(d) IN {decisionsIds} 
OPTIONAL MATCH (d)-[r]-(t) 
DELETE d, r 
WITH t, collect(r) as rels 
  WHERE NOT (id(t) IN {decisionsIds}) AND NOT t:User OR t:Decision
OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-(t1)
  WHERE NOT (r2 in rels)
OPTIONAL MATCH (t1)-[r3:CONTAINS]-(t2) 
DELETE t, r2, t2, r3;

更新

你的数据库的测试,工作pretty,很好。关于你的说法,我不知道哪些是违反

Update

Tested with your DB, worked pretty, well. Regarding your assertions, I'm not sure which ones are violated.

export decisionsIds=[332,336,335,334,333,340,339,338,337,344,343,342,341] 

MATCH (d:Decision) WHERE id(d) IN {decisionsIds} 
OPTIONAL MATCH (d)-[r]-(t) 
DELETE d, r 
WITH t, collect(r) as rels 
  WHERE NOT (t:User OR t:Decision) AND NOT (id(t) IN {decisionsIds})
OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR|:CONTAINS]-(t1)
  WHERE NOT (r2 in rels)
DELETE t, r2
WITH t1
OPTIONAL MATCH (t1)-[:CONTAINS]-(t2) 
// will be detach delete in 2.3
FOREACH ( p IN (t2)--() | DELETE head(rels(p)))
DELETE t2;

+-------------------+
| No data returned. |
+-------------------+
Nodes deleted: 362
Relationships deleted: 723
340 ms

您可以找到你这样的问题的节点:

You can find your offending node like this:

neo4j-sh (?)$ match (n)-[r]-() where id(n) = 86715 return labels(n),n,r;
+----------------------------------------------------------------------------------------------------------------------------------+
| labels(n)                  | n                                                                            | r                    |
+----------------------------------------------------------------------------------------------------------------------------------+
| ["VoteGroup","_VoteGroup"] | Node[86715]{createDate:"1443124989049",avgVotesWeight:5.0,totalVotesCount:1} | :CONTAINS[173172]{}  |
| ["VoteGroup","_VoteGroup"] | Node[86715]{createDate:"1443124989049",avgVotesWeight:5.0,totalVotesCount:1} | :VOTED_ON[173169]{}  |
| ["VoteGroup","_VoteGroup"] | Node[86715]{createDate:"1443124989049",avgVotesWeight:5.0,totalVotesCount:1} | :VOTED_FOR[173170]{} |
+----------------------------------------------------------------------------------------------------------------------------------+

如果你想看到的是感动了所有的数据/将通过这个查询被删除使用:

If you want to see all data that is touched / would be deleted by this query use this:

MATCH (d:Decision) WHERE id(d) IN {decisionsIds} 
OPTIONAL MATCH (d)-[r]-(t) 
WITH t, collect(r) as rels 
  WHERE NOT (t:User OR t:Decision) AND NOT (id(t) IN {decisionsIds})
OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR|:CONTAINS]-(t1)
  WHERE NOT (r2 in rels)
OPTIONAL MATCH (t1)-[:CONTAINS]-(t2)
RETURN *;

然后你可以找到你的问题的节点的结果,并确保已删除周围的一切(每REL型)。

Then you can find your offending nodes in the result, and make sure that you deleted everything (every rel-type) around them.

这篇关于Neo4j的实施意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆