简体   繁体   English

在Neo4j中使用索引

[英]Working with index in Neo4j

I've been going through the Neo4J and Neo4J C# client.. 我一直在研究Neo4J和Neo4J C#客户端。

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. neo4jclient Wiki帮助我完成了node crud操作。但是,该wiki突然结束了。.我在源代码中测试测试方法 ,设法了解了关系,并在线搜索了索引的工作方式。

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;

shows all nodes. 显示所有节点。

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? 我是否不需要将每个节点添加到索引?

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? 我要做的就是选择具有给定属性的节点:在这种情况下, Name = "Dovakiin" 。请问如何选择呢?

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. 只是为了扩展ulkas的答案,如果您想启用自动索引并发现文档有些混乱(就像我第一次阅读该文档一样),这就是设置方法。

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: 打开/conf/neo4j.properties文件,您应该看到类似以下内容:

# 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

Once this is done, in order for auto indexing to take effect, you'll have to restart neo4j. 完成此操作后,为了使自动索引生效,您必须重新启动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). 如果您不想从头开始,这里有一些有关如何更新它们的文档: http : //docs.neo4j.org/chunked/milestone/auto-indexing.html#auto-indexing-update-removal (I'从未尝试过)。

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")

Or, like this with the C# client: 或者,像这样使用C#客户端:

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();

You can do the same thing with with relationships as well, as soon as you set it up in the /conf/neo4j.properties file. 一旦在/conf/neo4j.properties文件中进行设置,就可以对关系进行相同的处理。 You do it exactly the same way as with nodes. 您执行此操作的方式与使用节点完全相同。

you must manually add the nodes to the index, something like 您必须手动将节点添加到索引,例如

client.indexRef1.addToIndex(nodeRef, 'name', 'Dovakiin') client.indexRef2.addToIndex(nodeRef, 'job', 'Dragon Slayer') client.indexRef1.addToIndex(nodeRef, 'name', 'Dovakiin') client.indexRef2.addToIndex(nodeRef, 'job', 'Dragon Slayer')

there is also an automatic indexing feature in neo4j in case you want the nodes to be automatically added to the index. 如果您希望将节点自动添加到索引 ,neo4j中还提供了自动索引功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM