在 Neo4j 中使用索引 [英] Working with index in Neo4j

查看:18
本文介绍了在 Neo4j 中使用索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览 Neo4J 和 Neo4J C# 客户端..

I've been going through the Neo4J and Neo4J C# client..

neo4jclient wiki 帮助我处理节点 crud 操作.. 然而 wiki 突然结束了..我浏览了源代码中的测试方法并设法理解关系并在线搜索以了解索引的工作原理.

The neo4jclient wiki helped me to with node crud operations.. however the wiki ends there abruptly.. I poked around the test methods in source code and managed to understand about relationships and searched online to understand how indexing works.

到目前为止,这就是我所拥有的,大致如下:

So far, here's what I have, roughly:

//create indexing on user and car
client.CreateIndex("User", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node); 
client.CreateIndex("Car", new IndexConfiguration() { Provider = IndexProvider.lucene, Type = IndexType.fulltext }, IndexFor.Node);

//create user
client.Create(new User() { Name = "Dovakiin", Job = "Dragon Slayer" });
client.Create(new User() { Name = "Ulfric stormcloak", Job = "Imperial Slayer" });

//create Car
client.Create(new Car() { Name = "Paarthurnax", Modal = 212 });

//User owns car relationship
client.CreateRelationship(userRef, new Owns_CarRelationship(CarRef));

这就是我现在卡住的地方..当我尝试按名称查找用户时,我的密码查询返回零结果:

This is where I am stuck now.. When I try to look for the user by name, my cipher query is returning zero results:

 start u=node:User(Name="Dovakiin") return u;

我不太明白为什么它在清晰的时候返回零节点

and I don't quite understand why it returns zero nodes when clearly

start n=node(*) return n;

显示所有节点.

索引时我是否遗漏了其他东西?或者这根本与索引无关?我不需要将每个节点添加到索引中吗?

Am I missing something else while indexing? Or is this not index related at all? Do I not need to add each node to the index?

我要做的就是选择具有给定属性的节点:Name = "Dovakiin" 在这种情况下.. 我该如何选择?

All I am trying to do, is select the node with a given property: Name = "Dovakiin" in this case.. How do I select this please?

推荐答案

只是为了扩展 ulkas 的答案,如果您想启用自动索引并发现文档有点混乱(就像我第一次阅读时所做的那样),这就是您的设置方式.

Just to expand on ulkas' answer, if you want to enable auto indexing and found the documentation a little confusing (like I did the first time I read it), this is how you set it up.

假设你想自动索引一些节点属性;说,姓名"和工作".打开/conf/neo4j.properties 文件,您应该会看到如下内容:

Let's say you want to automatically index some node properties; say, "name" and "job". Open up the /conf/neo4j.properties file and you should see something like this:

# Autoindexing

# Enable auto-indexing for nodes, default is false
#node_auto_indexing=true

# The node property keys to be auto-indexed, if enabled
#node_keys_indexable=name,age

然后您必须将文件编辑为以下内容:

You then have to edit the file to the following:

# Autoindexing

# Enable auto-indexing for nodes, default is false
node_auto_indexing=true

# The node property keys to be auto-indexed, if enabled
node_keys_indexable=name,job

完成后,为了使自动索引生效,您必须重新启动neo4j.此外,作为旁注,任何当前存在的节点都不会被自动索引,这意味着您必须重新创建它们.如果您不想从头开始,这里有一些关于如何更新它们的文档:http://docs.neo4j.org/chunked/milestone/auto-indexing.html#auto-indexing-update-removal(我从未尝试过).

Once this is done, in order for auto indexing to take effect, you'll have to restart neo4j. Also, as a side note, any currently existing nodes won't be auto indexed, which means you'll have to recreate them. If you don't want to start from scratch, here's some documentation on how to update them: http://docs.neo4j.org/chunked/milestone/auto-indexing.html#auto-indexing-update-removal (I've never tried it).

然后你可以开始寻找这样的节点:

Then you can start finding nodes like this:

start n=node:node_auto_index(name="Dovakiin"), or
start n=node:node_auto_index(job="Dragon Slayer")

或者,像这样使用 C# 客户端:

Or, like this with the C# client:

Node<User> myNode = client.QueryIndex<User>("node_auto_index", IndexFor.Node, "name:Dovakiin").First();, or
Node<User> myNode = client.QueryIndex<User>("node_auto_index", IndexFor.Node, "job:Dragon Slayer").First();

只要在/conf/neo4j.properties 文件中设置了关系,您也可以对关系执行相同的操作.您的操作方式与节点完全相同.

You can do the same thing with with relationships as well, as soon as you set it up in the /conf/neo4j.properties file. You do it exactly the same way as with nodes.

这篇关于在 Neo4j 中使用索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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