Neo4JClient-如何将节点添加到索引 [英] Neo4JClient - How To Add Node to Index

查看:85
本文介绍了Neo4JClient-如何将节点添加到索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个非常简单的示例,说明如何使用Neo4JClient将节点添加到索引中

I need a very simple example of how to add a node to an index with using Neo4JClient

在下面的C#代码中,我创建了一个索引和一个雇员节点.

In the following C# code I have created an index and an employee node.

问题:
在以下代码中,如何将创建的节点添加到索引中?解决方案应允许搜索EmployeeID或Name.

Question:
In the following code, how can the node that was created be added to the index? The solutions should allow for the ability to search on EmployeeID or Name.


    class Program
    {
        static void Main(string[] args)
        {
            //Connect to Neo4J
            var graphClient = new GraphClient(new Uri(@"http://localhost:7474/db/data"));
            graphClient.Connect();

            //Create Index
            graphClient.CreateIndex("employee", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.exact }, IndexFor.Node);

            //Create an Employee node
            var employee = new Employee() { EmployeeID = "12345", Name = "Mike"};
            NodeReference employeeRef = graphClient.Create(employee);

            //Add the node that was just created to the Employee index.  

        }


        private class Employee
        {
            [JsonProperty("EmployeeID")]
            public string EmployeeID { get; set; }

            [JsonProperty("Name")]
            publi

推荐答案

注意:该答案适用于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.)

这篇关于Neo4JClient-如何将节点添加到索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆