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

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

问题描述

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

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

问题:
在下面的代码中,如何将创建的节点添加到索引中?解决方案应允许搜索员工 ID 或姓名.

<前>课程计划{静态无效主(字符串 [] args){//连接到Neo4Jvar graphClient = new GraphClient(new Uri(@"http://localhost:7474/db/data"));graphClient.Connect();//创建索引graphClient.CreateIndex("employee", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.exact }, IndexFor.Node);//创建一个员工节点var 员工 = 新员工(){ EmployeeID = "12345", Name = "Mike"};NodeReference employeeRef = graphClient.Create(employee);//将刚刚创建的节点添加到Employee索引中.}

<前>私人班级员工{[JsonProperty("EmployeeID")]公共字符串员工 ID { 获取;放;}[JsonProperty("名称")]公开

解决方案

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

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

var employeeRef = graphClient.Create(员工,新的 IRelationshipAllowingParticipantNode[0],新的 []{新索引条目(员工"){{员工ID",1234},{姓名",迈克"}}});

由于以下几个原因,它看起来有点冗长:

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

  2. 一个节点可以在多个索引中结束,并且键和值不必与节点匹配.

我们想让这个语法更适合默认场景,但还没有做到.

当你更新一个节点时,你还需要提供新的索引条目:

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

您可以使用 graphClient.ReIndex 在不更新节点本身的情况下重新索引节点.

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

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

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

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

解决方案

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. You would almost never create a node without at least one relationship. The relationships would stack nicely in that second parameter.

  2. 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 } }
    });

You can reindex a node without updating the node itself using 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天全站免登陆