0

我一直在浏览 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"在这种情况下..我该如何选择这个?

4

2 回答 2

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

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

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 文件中设置它,您也可以对关系执行相同的操作。您的操作方式与节点完全相同。

于 2013-01-16T18:46:04.450 回答
2

您必须手动将节点添加到索引中,例如

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

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

于 2013-01-16T14:41:27.203 回答