Vertex u1 = g.addVertex(null);
Vertex u2 = g.addVertex(null);
Vertex u3 = g.addVertex(null);
Vertex u4 = g.addVertex(null);
Vertex u5 = g.addVertex(null);
Vertex u6 = g.addVertex(null);
Vertex u7 = g.addVertex(null);
Edge addEdge = u1.addEdge("testRate",page);
addEdge.setProperty("testRating", 1);
Edge addEdge1 = u2.addEdge("testRate",page);
addEdge1.setProperty("testRating", 2);
Edge addEdge2 = u3.addEdge("testRate",page);
addEdge2.setProperty("testRating", 1);
Edge addEdge3 = u4.addEdge("testRate",page);
addEdge3.setProperty("testRating", 3);
Edge addEdge4 = u5.addEdge("testRate",page);
addEdge4.setProperty("testRating", 2);
Edge addEdge5 = u6.addEdge("testRate",page);
addEdge5.setProperty("testRating", 2);
Edge addEdge6 = u7.addEdge("testRate",page);
addEdge6.setProperty("testRating", 1);
获得评级-1的数量
page.query().direction(Direction.IN).labels("testRate").has("testRating", 1).count();
现在为了获得所有不同类型的评级,我应该执行相同类型的代码还是有其他方式?
我找到了一些groupCount()
gremlin方法。这就是我需要的,在java中也有同样的方法吗?
答案 0 :(得分:1)
似乎groupCount
似乎是一种更好的方法,原因如下:
has
为每个评级级别(1,2,3等),如果您添加另一个级别
等级,你将不得不回来并添加另一个“计数”
遍历。testRate
边缘。为什么不在一次遍历中进行。答案 1 :(得分:0)
最后这有效:
HashMap<Integer,Number>itemCount = new HashMap<Integer,Number>();
GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>();
pipe.start(v).inE("testRate").property("testRating").groupCount(itemCount).iterate();
Iterator<Integer> iterator = itemCount.keySet().iterator();
while(iterator.hasNext()) {
Integer next = iterator.next();
System.out.println(next+"------"+itemCount.get(next));
}