0

我对 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 检查现有索引并将节点分配给索引?

如果有人分享一个例子,我将非常感激。

4

1 回答 1

0

您可以使用该AddToIndex方法将节点/关系添加到索引。例如:

var node1 = Node.CreateNode();
node1.AddToIndex("nodes", "name", "jack");

或者你可以使用静态函数Node

Node.AddToIndex(node1, "nodes", "name", "jack");

其中"nodes"是索引的名称,"name"/"jack"是键/值对。

如果您Enum为 value 参数传递一个值,它将使用节点上属性集合中的值。

注意:我刚刚在 2012 年 6 月 6 日推送了新代码,您应该尝试开始使用它。它现在支持命令的批处理,我将很快更新 API 以支持密码变异命令。我也将尽快更新文档,因为它们目前已过时。

hth。

于 2012-06-07T23:10:18.450 回答