我對neo4j很陌生,目前正在使用Neo4jRestNet客戶端。我創建了一個小型網絡學習的目的:Neo4jRestClient:如何創建節點和連接後創建索引?
private static void GenerateNetwork()
{
var rootNode = Node.GetRootNode();
// Create a User Node with Properties
var prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Madeline J. Parnell");
prop.SetProperty(NodeProperty.Age.ToString(), "25");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "LA");
var nodeUserWithName1 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Jack S. Waldrop");
prop.SetProperty(NodeProperty.Age.ToString(), "28");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "San Francisco");
var nodeUserWithName2 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Willis O. Hicks");
prop.SetProperty(NodeProperty.Age.ToString(), "33");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "Ann Arbor");
var nodeUserWithName3 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Leroy P. Wagner");
prop.SetProperty(NodeProperty.Age.ToString(), "40");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "Hattiesburg");
var nodeUserWithName4 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Nancy J. Rose");
prop.SetProperty(NodeProperty.Age.ToString(), "25");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "Cornish");
var nodeUserWithName5 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Sally G. Gee");
prop.SetProperty(NodeProperty.Age.ToString(), "48");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "Charlestown");
var nodeUserWithName6 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Blanche T. Perez");
prop.SetProperty(NodeProperty.Age.ToString(), "35");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "Philadelphia");
var nodeUserWithName7 = Node.CreateNode(NodeType.Person.ToString(), prop);
prop = new Properties();
prop.SetProperty(NodeProperty.Name.ToString(), "Robert S. Johnston");
prop.SetProperty(NodeProperty.Age.ToString(), "22");
prop.SetProperty(NodeProperty.LivesIn.ToString(), "Lancaster");
var nodeUserWithName8 = Node.CreateNode(NodeType.Person.ToString(), prop);
// Create Relationships to Nodes
rootNode.CreateRelationshipTo(nodeUserWithName1, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName2, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName3, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName4, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName5, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName6, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName7, RelationshipType.Knows.ToString());
rootNode.CreateRelationshipTo(nodeUserWithName8, RelationshipType.Knows.ToString());
// Create Relationship with Properties
//var relProp = new Properties();
//relProp.SetProperty(RelationshipProperty.Name.ToString(), "MyRelationship");
//relProp.SetProperty("CustomRelProp", "CustomPropValue");
nodeUserWithName1.CreateRelationshipTo(nodeUserWithName2, RelationshipType.Knows.ToString());
nodeUserWithName1.CreateRelationshipTo(nodeUserWithName3, RelationshipType.Knows.ToString());
nodeUserWithName2.CreateRelationshipTo(nodeUserWithName3, RelationshipType.Knows.ToString());
nodeUserWithName5.CreateRelationshipTo(nodeUserWithName6, RelationshipType.Knows.ToString());
nodeUserWithName6.CreateRelationshipTo(nodeUserWithName8, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName1, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName1, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName3, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName4, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName5, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName6, RelationshipType.Knows.ToString());
nodeUserWithName7.CreateRelationshipTo(nodeUserWithName8, RelationshipType.Knows.ToString());
}
我試圖找到一個方法來創建索引,這將是等同於下面的Java方法:
IndexManager指數= graphDb.index(); Index people = index.forNodes(「people」); RelationshipIndex roles = index.forRelationships(「roles」);
,並把它添加到人,用GenerateNetwork()方法,創建了在Java中與下面的方法做:
people.add(nodeInstance, "valueName", reeves.getProperty("valueName"));
反正到目前爲止我還沒有找到對付使用Neo4jRestClient指標的方式。有誰知道如何檢查現有索引並使用Neo4jRestClient將節點分配給索引?
如果有人分享了一個例子,我會非常感激。
傑克,謝謝你的回答。我無法運行新版本。舊的運行沒有問題,但新的引發異常在線var rootNode = Node.GetRootNode(); –
你能否給我你的電子郵件地址或聯繫方式,以便談論解決方案? –
Niko,如果根節點已從圖中刪除,則GetRootNode方法將引發錯誤。這裏是關於neo4j.org的討論鏈接(https://groups.google.com/forum/#!topic/neo4j/Sb2ANlJtLDY)。我個人對此的看法;我不喜歡RootNode的想法。由於neo4j討論中提出的問題,我更願意將節點作爲根節點創建到我的圖。如果你想在https://github.com/SepiaGroup/Neo4jRestNet上打開問題,謝謝。 –