{"id":7068,"date":"2024-03-26T13:01:01","date_gmt":"2024-03-26T05:01:01","guid":{"rendered":""},"modified":"2024-03-26T13:01:01","modified_gmt":"2024-03-26T05:01:01","slug":"Neo4j\uff1a\u4f7f\u9690\u5f0f\u5173\u7cfb\u6210\u4e3a\u663e\u5f0f\u548c\u53cc\u5411\u5173\u7cfb","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7068.html","title":{"rendered":"Neo4j\uff1a\u4f7f\u9690\u5f0f\u5173\u7cfb\u6210\u4e3a\u663e\u5f0f\u548c\u53cc\u5411\u5173\u7cfb"},"content":{"rendered":"
\n
\n
\n <\/span>\n <\/div>\n<\/p><\/div>\n

\u6700\u8fd1\uff0c\u6211\u9605\u8bfb\u4e86Michal Bachman\u5173\u4e8e Neo4j\u4e2d\u53cc\u5411\u5173\u7cfb\u7684\u6587\u7ae0 \uff0c\u4ed6\u5efa\u8bae\u5bf9\u4e8e\u67d0\u4e9b\u5173\u7cfb\u7c7b\u578b\uff0c\u6211\u4eec\u5bf9\u5173\u7cfb\u7684\u65b9\u5411\u4e0d\u90a3\u4e48\u611f\u5174\u8da3\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728\u67e5\u8be2\u65f6\u5ffd\u7565\u5b83\u3002 \u4ed6\u4f7f\u7528\u4ee5\u4e0b\u793a\u4f8b\u663e\u793a\u4e86Neo Technology\u548cGraphAware\u4e4b\u95f4\u7684\u5408\u4f5c\u5173\u7cfb\uff1a <\/p>\n<\/p>\n

\u4e24\u5bb6\u516c\u53f8\u90fd\u662f\u5f7c\u6b64\u7684\u5408\u4f5c\u4f19\u4f34\uff0c\u4f46\u662f\u7531\u4e8e\u6211\u4eec\u53ef\u4ee5\u5c3d\u5feb\u627e\u5230\u4f20\u5165\u548c\u4f20\u51fa\u7684\u5173\u7cfb\uff0c\u56e0\u6b64\u6211\u4eec\u6700\u597d\u5728\u4e24\u5bb6\u516c\u53f8\/\u8282\u70b9\u4e4b\u95f4\u53ea\u6709\u4e00\u79cd\u5173\u7cfb\u3002 <\/p>\n

\u5f53\u6211\u4eec\u60f3\u4f7f\u56fe\u4e2d\u7684\u9690\u5f0f\u5173\u7cfb\u660e\u786e\u65f6\uff0c\u7ecf\u5e38\u4f1a\u51fa\u73b0\u8fd9\u79cd\u6a21\u5f0f\u3002 \u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u80fd\u6709\u4ee5\u4e0b\u56fe\u5f62\u63cf\u8ff0\u4e86\u4ed6\u4eec\u6240\u4ece\u4e8b\u7684\u4eba\u5458\u548c\u9879\u76ee\uff1a <\/p>\n<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u5bc6\u7801\u8bed\u6cd5\u5728Neo4j 2.0\u4e2d\u521b\u5efa\u8be5\u56fe\uff1a <\/p>\n

CREATE (mark:Person {name: \"Mark\"})\nCREATE (dave:Person {name: \"Dave\"})\nCREATE (john:Person {name: \"John\"})\n\nCREATE (projectA:Project {name: \"Project A\"})\nCREATE (projectB:Project {name: \"Project B\"})\nCREATE (projectC:Project {name: \"Project C\"})\n\nCREATE (mark)-[:WORKED_ON]->(projectA)\nCREATE (mark)-[:WORKED_ON]->(projectB)\nCREATE (dave)-[:WORKED_ON]->(projectA)\nCREATE (dave)-[:WORKED_ON]->(projectC)\nCREATE (john)-[:WORKED_ON]->(projectC)\nCREATE (john)-[:WORKED_ON]->(projectB)<\/code><\/pre>\n

\u5982\u679c\u6211\u4eec\u60f3\u5f04\u6e05\u695a\u54ea\u4e9b\u4eba\u5f7c\u6b64\u8ba4\u8bc6\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u4ee5\u4e0b\u67e5\u8be2\uff1a <\/p>\n

MATCH (person1:Person)-[:WORKED_ON]-()<-[:WORKED_ON]-(person2)\nRETURN person1, person2\n\n==> +-------------------------------------------------------+\n==> | person1                   | person2                   |\n==> +-------------------------------------------------------+\n==> | Node[500363]{name:\"Mark\"} | Node[500364]{name:\"Dave\"} |\n==> | Node[500363]{name:\"Mark\"} | Node[500365]{name:\"John\"} |\n==> | Node[500364]{name:\"Dave\"} | Node[500363]{name:\"Mark\"} |\n==> | Node[500364]{name:\"Dave\"} | Node[500365]{name:\"John\"} |\n==> | Node[500365]{name:\"John\"} | Node[500364]{name:\"Dave\"} |\n==> | Node[500365]{name:\"John\"} | Node[500363]{name:\"Mark\"} |\n==> +-------------------------------------------------------+\n==> 6 rows<\/code><\/pre>\n

\u6211\u4eec\u53ef\u80fd\u8981\u5728\u6bcf\u5bf9\u4eba\u4e4b\u95f4\u521b\u5efa\u4e00\u4e2aKNOWS<\/cite>\u5173\u7cfb\uff1a <\/p>\n

MATCH (person1:Person)-[:WORKED_ON]-()<-[:WORKED_ON]-(person2)\nCREATE UNIQUE (person1)-[:KNOWS]->(person2)\nRETURN person1, person2<\/code><\/pre>\n

\u73b0\u5728\uff0c\u5982\u679c\u6211\u4eec\u8fd0\u884c\u4e00\u4e2a\u67e5\u8be2\uff08\u5ffd\u7565\u5173\u7cfb\u65b9\u5411\uff09\u4ee5\u627e\u51fa\u54ea\u4e9b\u4eba\u5f7c\u6b64\u8ba4\u8bc6\uff0c\u6211\u4eec\u5c06\u5f97\u5230\u5f88\u591a\u91cd\u590d\u7684\u7ed3\u679c\uff1a <\/p>\n

MATCH path=(person1:Person)-[:KNOWS]-(person2) \nRETURN person1, person2, path\n\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | person1                   | person2                   | path                                                                   |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | Node[500363]{name:\"Mark\"} | Node[500364]{name:\"Dave\"} | [Node[500363]{name:\"Mark\"},:KNOWS[528536]{},Node[500364]{name:\"Dave\"}] |\n==> | Node[500363]{name:\"Mark\"} | Node[500365]{name:\"John\"} | [Node[500363]{name:\"Mark\"},:KNOWS[528537]{},Node[500365]{name:\"John\"}] |\n==> | Node[500363]{name:\"Mark\"} | Node[500364]{name:\"Dave\"} | [Node[500363]{name:\"Mark\"},:KNOWS[528538]{},Node[500364]{name:\"Dave\"}] |\n==> | Node[500363]{name:\"Mark\"} | Node[500365]{name:\"John\"} | [Node[500363]{name:\"Mark\"},:KNOWS[528541]{},Node[500365]{name:\"John\"}] |\n==> | Node[500364]{name:\"Dave\"} | Node[500363]{name:\"Mark\"} | [Node[500364]{name:\"Dave\"},:KNOWS[528538]{},Node[500363]{name:\"Mark\"}] |\n==> | Node[500364]{name:\"Dave\"} | Node[500365]{name:\"John\"} | [Node[500364]{name:\"Dave\"},:KNOWS[528539]{},Node[500365]{name:\"John\"}] |\n==> | Node[500364]{name:\"Dave\"} | Node[500363]{name:\"Mark\"} | [Node[500364]{name:\"Dave\"},:KNOWS[528536]{},Node[500363]{name:\"Mark\"}] |\n==> | Node[500364]{name:\"Dave\"} | Node[500365]{name:\"John\"} | [Node[500364]{name:\"Dave\"},:KNOWS[528540]{},Node[500365]{name:\"John\"}] |\n==> | Node[500365]{name:\"John\"} | Node[500364]{name:\"Dave\"} | [Node[500365]{name:\"John\"},:KNOWS[528540]{},Node[500364]{name:\"Dave\"}] |\n==> | Node[500365]{name:\"John\"} | Node[500363]{name:\"Mark\"} | [Node[500365]{name:\"John\"},:KNOWS[528541]{},Node[500363]{name:\"Mark\"}] |\n==> | Node[500365]{name:\"John\"} | Node[500363]{name:\"Mark\"} | [Node[500365]{name:\"John\"},:KNOWS[528537]{},Node[500363]{name:\"Mark\"}] |\n==> | Node[500365]{name:\"John\"} | Node[500364]{name:\"Dave\"} | [Node[500365]{name:\"John\"},:KNOWS[528539]{},Node[500364]{name:\"Dave\"}] |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> 12 rows<\/code><\/pre>\n

\u6bcf\u5bf9\u4eba\u51fa\u73b04\u6b21\uff0c\u5982\u679c\u6211\u4eec\u4ee5Mark\u548cDave\u4e3a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u539f\u56e0\uff1a <\/p>\n

MATCH path=(person1:Person)-[:KNOWS]-(person2) \nWHERE person1.name = \"Mark\" AND person2.name = \"Dave\" \nRETURN person1, person2, path\n\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | person1                   | person2                   | path                                                                   |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | Node[500363]{name:\"Mark\"} | Node[500364]{name:\"Dave\"} | [Node[500363]{name:\"Mark\"},:KNOWS[528536]{},Node[500364]{name:\"Dave\"}] |\n==> | Node[500363]{name:\"Mark\"} | Node[500364]{name:\"Dave\"} | [Node[500363]{name:\"Mark\"},:KNOWS[528538]{},Node[500364]{name:\"Dave\"}] |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> 2 rows<\/code><\/pre>\n

\u5982\u679c\u6211\u4eec\u770b\u4e00\u4e0b\u8def\u5f84<\/cite>\u680f\u4e0b\u6709\u4e24\u4e2a\u4e0d\u540c\u7684KNOWS<\/cite>\u5173\u7cfb\uff08\u4e0eIDS 528536\u548c528538\uff09\uff0c\u9a6c\u514b\u548c\u6234\u592b\uff0c\u4e00\u4e2a\u53bb\u4e4b\u95f4\u4ece\u9a6c\u514b\u6234\u592b\u548c\u5176\u4ed6\u6765\u81eaDave\u9a6c\u514b\u3002 <\/p>\n

\u6b63\u5982Michal\u5728\u4ed6\u7684\u5e16\u5b50\u4e2d\u6307\u51fa\u7684\u90a3\u6837\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e0d\u9700\u8981\u4e24\u4e2a\u5173\u7cfb\u3002 \u6211\u4eec\u53ea\u9700\u8981\u4e00\u79cd\u5173\u7cfb\uff0c\u53ef\u4ee5\u901a\u8fc7\u521b\u5efaKNOWS<\/cite>\u5173\u7cfb\u65f6\u4e0d\u6307\u5b9a\u65b9\u5411\u6765\u5b9e\u73b0\uff1a <\/p>\n

MATCH (person1:Person)-[:WORKED_ON]-()<-[:WORKED_ON]-(person2)\nCREATE UNIQUE (person1)-[:KNOWS]-(person2)\nRETURN person1, person2<\/code><\/pre>\n

\u73b0\u5728\uff0c\u5982\u679c\u6211\u4eec\u91cd\u65b0\u8fd0\u884c\u67e5\u8be2\u4ee5\u68c0\u67e5Mark\u548cDave\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u5219\u53ea\u6709\u4e00\u4e2a\uff1a <\/p>\n

MATCH path=(person1:Person)-[:KNOWS]-(person2) WHERE person1.name = \"Mark\" AND person2.name = \"Dave\" RETURN person1, person2, path\n\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | person1                   | person2                   | path                                                                   |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | Node[500375]{name:\"Mark\"} | Node[500376]{name:\"Dave\"} | [Node[500375]{name:\"Mark\"},:KNOWS[528560]{},Node[500376]{name:\"Dave\"}] |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> 1 row<\/code><\/pre>\n

\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5173\u7cfb\u4eceMark\u5230Dave\uff0c\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4e00\u4e9b\u8003\u8651\u65b9\u5411\u7684\u67e5\u8be2\u6765\u770b\u5230\uff1a <\/p>\n

MATCH path=(person1:Person)-[:KNOWS]->(person2) \nWHERE person1.name = \"Mark\" AND person2.name = \"Dave\" \nRETURN person1, person2, path\n\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | person1                   | person2                   | path                                                                   |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> | Node[500375]{name:\"Mark\"} | Node[500376]{name:\"Dave\"} | [Node[500375]{name:\"Mark\"},:KNOWS[528560]{},Node[500376]{name:\"Dave\"}] |\n==> +--------------------------------------------------------------------------------------------------------------------------------+\n==> 1 row<\/code><\/pre>\n
MATCH path=(person1:Person)<-[:KNOWS]-(person2) \nWHERE person1.name = \"Mark\" AND person2.name = \"Dave\" \nRETURN person1, person2, path\n\n==> +--------------------------+\n==> | person1 | person2 | path |\n==> +--------------------------+\n==> +--------------------------+\n==> 0 row<\/code><\/pre>\n<\/p>\n
\n \u53c2\u8003\uff1a<\/i><\/b> Neo4j\uff1a\u901a\u8fc7 Mark Needham\u535a\u5ba2\u535a\u5ba2\u7684
\n JCG\u5408\u4f5c\u4f19\u4f34 Mark Needham \u4f7f\u9690\u5f0f\u5173\u7cfb\u6210\u4e3a\u663e\u5f0f\u548c\u53cc\u5411\u5173\u7cfb \u3002\n <\/div>\n

<\/p>\n

\n

\u7ffb\u8bd1\u81ea: https:\/\/www.javacodegeeks.com\/2013\/10\/neo4j-making-implicit-relationships-explicit-bidirectional-relationships.html<\/p>\n<\/blockquote>\n<\/div>\n","protected":false},"excerpt":{"rendered":"Neo4j\uff1a\u4f7f\u9690\u5f0f\u5173\u7cfb\u6210\u4e3a\u663e\u5f0f\u548c\u53cc\u5411\u5173\u7cfb\u6700\u8fd1\uff0c\u6211\u9605\u8bfb\u4e86MichalBachman\u5173\u4e8eNeo4j\u4e2d\u53cc\u5411\u5173\u7cfb\u7684\u6587\u7ae0\uff0c\u4ed6\u5efa\u8bae\u5bf9\u4e8e\u67d0\u4e9b\u5173\u7cfb\u7c7b\u578b\uff0c\u6211\u4eec...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7068"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7068"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7068\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}