我从这本非常有用的书中修改了这个推荐系统cypher查询..(学习Neo4j By Rik Van Bruggen)到我的数据集,它基本上破坏了服务器。
match (p1:Person)-[:BOUGHT]->(prod1:Product)<-[:BOUGHT]-(p2:Person)- [:BOUGHT]->(prod2:Product)
with p1,p2,count(prod1) as NrOfSharedProducts, collect(prod1) as SharedProducts,prod2
where not(p1-[:BOUGHT]->prod2) AND NrOfSharedProducts > 2
return p1.name as FirstPerson, p2.name as SecondPerson, extract(x in SharedProducts | x.name) as SharedProducts, prod2.name as RecommendedProduct;
我的意思是“打破了服务器”是在查询开始后1)网络浏览器断开与服务器的连接几次2)花了很长时间3)查询失败给出“未知错误”
我不知道会发生这种情况。由于我在紧接之前(下面)运行了相关查询,我尝试了第二次,并且它在几秒钟内给出了正确的输出,我认为我排列正确并且它可以工作。
match (p1:Person)-[:BOUGHT]->(prod1:Product)<-[:BOUGHT]-(p2:Person)- [:BOUGHT]->(prod2:Product)
where not (p1-[:BOUGHT]->prod2)
return p1.name as FirstPerson, p2.name as SecondPerson, prod1.name as CommonProduct, prod2.name as RecommendedProduct;
这次失败我应该感到惊讶吗?有没有已知原因?我该怎么解释这个失败?
答案 0 :(得分:1)
是的,绝对可以!我想在conf/neo4j-server.properties
文件中设置以下内容:
org.neo4j.server.transaction.timeout=60
这样,如果60秒没有任何结果,查询将被终止。如果您正在使用可能很昂贵的查询并以各种方式多次运行它,那么这一点尤为出色。如果您同时有多个查询,那么这样做真的可以减慢速度。
答案 1 :(得分:1)
查询
PROFILE
match (p1:Person)-[:BOUGHT]->(prod1:Product) 2 MATCH (p2)- [:BOUGHT]->(prod2:Product) where not(p1-[:BOUGHT]->prod2) AND return p1.name as FirstPerson, p2.name as SecondPerson, extract(x in SharedProducts | x.name) as SharedProducts, prod2.name as RecommendedProduct;