使用Neo4j中的索引

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

neo4jclient wiki帮助我完成了节点crud操作..然而wiki突然终止了..我在源代码中 探索了测试方法并设法了解关系并在线搜索以了解索引是如何工作的。

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

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

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

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

我不太明白为什么它清楚地返回零节点

 start n=node(*) return n; 

显示所有节点。

索引时我是否遗漏了其他内容? 或者这与索引有关系吗? 我不需要将每个节点添加到索引中吗?

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

只是为了扩展ulkas的答案,如果你想启用自动索引并发现文档有点令人困惑(就像我第一次读它时那样),这就是你设置它的方法。

假设您想自动索引某些节点属性; 比如,“名字”和“工作”。 打开/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 

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

 # 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 (我’从来没有尝试过)。

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

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

或者,与C#客户端一样:

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

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

你必须手动将节点添加到索引,如

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

如果您希望节点自动添加到索引中,neo4j中还有一个自动索引function。