【发布时间】:2012-05-07 17:56:11
【问题描述】:
我想知道当需要基于某些节点类型或字段有多个 indecies 时,有什么更好的方法。 例如,假设我想要一个学生图表,并希望按他们的学校和 id 对他们进行索引。
据我了解,我可以像这样为每所学校建立一个索引:
// add student
Index<Node> index = this.graphDb.index().forNodes(schoolName);
Node node = this.graphDb.createNode();
node.setProperty("id", studentId);
index.add(node, "id", studentId);
// get student
Index<Node> index = this.graphDb.index().forNodes(schoolName);
Node node = index.get("id", studentId).getSingle();
另一方面,我可以使用一个索引并执行以下操作:
// add student
Index<Node> index = this.graphDb.index().forNodes("schools");
Node node = this.graphDb.createNode();
node.setProperty("id", studentId);
index.add(node, schoolName + ":id", studentId);
// get student
Index<Node> index = this.graphDb.index().forNodes("schools");
Node node = index.get(schoolName + ":id", studentId).getSingle();
什么是更好的方法? 一个比另一个有什么优势? 当涉及到很多节点时,尤其是性能方面或存储方面。
谢谢
【问题讨论】: