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

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

问题描述

我一直在研究Neo4J和Neo4J C#客户端.

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

neo4jclient Wiki 帮助我进行了node crud操作. .. 我戳了一下源代码中的测试方法,并设法理解了关于关系的信息,并在线搜索以了解索引的工作原理.

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.另外,请注意,当前所有现有节点都不会自动索引,这意味着您必须重新创建它们.如果您不想从头开始,这里有一些有关如何更新它们的文档:

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天全站免登陆