【发布时间】:2015-03-24 23:24:30
【问题描述】:
我有超过 50,000 个称为 weblogs 的节点,我正在尝试根据其属性连接两个节点,我的代码如下所示:
#!/usr/bin/env python
from py2neo import neo4j, Node, Relationship, Graph, GraphError
from py2neo.packages.httpstream import http
http.socket_timeout = 99999
graph = Graph()
relation_counter = 0
for node in graph.find("Weblogs"):
matches = graph.match(start_node=node, rel_type="hasDirectLinks")
if not matches:
continue
for relation in matches:
for weblog_node in graph.find("Weblogs", "entry_url", relation.end_node.properties["url"]):
if weblog_node:
graph.create_unique(Relationship(node, "hasDirectLinks", weblog_node))
relation_counter += 1
if relation_counter % 30 == 0:
print (relation_counter, ": Numbers of Relationship made")
print (relation_counter, ": Total numbers of relationship made")
代码运行良好,但速度很慢,有什么建议可以让它更快吗?
【问题讨论】: