且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Neo4JClient-如何将节点添加到索引

更新时间:2023-11-24 22:06:28

注意:该答案适用于Neo4jClient 1.0.0.474.确保您已更新.

Note: This answer applies to Neo4jClient 1.0.0.474. Make sure you have updated.

创建节点时,可以提供索引条目:

When you create the node, you can supply the index entries:

var employeeRef = graphClient.Create(
    employee,
    new IRelationshipAllowingParticipantNode<Employee>[0],
    new []
    {
        new IndexEntry("employee")
        {
            {"EmployeeID", 1234 },
            { "Name", "Mike" }
        }
    }
);

由于某些原因,它看起来有些冗长:

It looks a little verbose for a few reasons:

  1. 如果没有至少一个关系,您几乎永远不会创建一个节点.关系将很好地堆叠在第二个参数中.

  1. You would almost never create a node without at least one relationship. The relationships would stack nicely in that second parameter.

一个节点可以以多个索引结尾,并且键和值不必与该节点匹配.

One node can end up in multiple indexes, and the keys and values don't have to match the node.

对于默认情况,我们希望使该语法更好,但尚未完成.

We would like to make this syntax nicer for the default scenario, but haven't done it yet.

更新节点时,还需要提供新的索引条目,然后:

When you update a node, you also need to supply new index entries then:

graphClient.Update(employeeRef,
    e =>
    {
        e.Name = "Bob";
    },
    e => new[]
    {
        new IndexEntry("employee") { { "Name", e.Name } }
    });

您可以使用graphClient.ReIndex重新索引节点,而无需更新节点本身.

You can reindex a node without updating the node itself using graphClient.ReIndex.

如果您想将现有节点添加到索引中而不进行更新,则只需使用graphClient.ReIndex. (该方法不对节点已在索引中做出任何假设.)

If you want to add an existing node to the index, without updating it, just use graphClient.ReIndex as well. (That method doesn't make any assumptions about the node already being in the index.)