我一直在浏览Neo4J和Neo4J C#客户端..
neo4jclient wiki帮助我进行节点crud操作..然而wiki突然终止了.. 我在test methods in source code周围探索并设法了解关系并在线搜索以了解索引的工作原理。
到目前为止,这就是我所拥有的,粗略地说:
//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"
在这种情况下..我该如何选择这个?
答案 0 :(得分:3)
只是为了扩展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<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文件中设置后,您也可以使用关系执行相同的操作。您的操作方式与节点完全相同。
答案 1 :(得分:2)
您必须manually add指向索引的节点,例如
client.indexRef1.addToIndex(nodeRef, 'name', 'Dovakiin')
client.indexRef2.addToIndex(nodeRef, 'job', 'Dragon Slayer')
如果您希望节点自动添加到索引中,neo4j中还有automatic indexing功能。