我对 neo4j 很陌生,目前正在使用 Neo4jRestNet 客户端。为了学习,我创建了一个小型网络:
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.forNodes(“人”);关系索引角色 = index.forRelationships(“角色”);
并将其添加到使用 GenerateNetwork() 方法创建的人员中,该方法在 java 中使用以下方法完成:
people.add( nodeInstance, "valueName", reeves.getProperty( "valueName" ) );
无论如何,到目前为止,我还没有找到使用 Neo4jRestClient 处理索引的方法。有谁知道如何使用 Neo4jRestClient 检查现有索引并将节点分配给索引?
如果有人分享一个例子,我将非常感激。