如何通过输入边缘的数量进行计数和排序 [英] How to count and order by number of incoming edges

查看:179
本文介绍了如何通过输入边缘的数量进行计数和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让十位出演过大部分电影的人获得名字和电影的数量。我正在使用 IMDB数据集



这是我到目前为止:

  arangosh [_system]> var Graph = require(org / arangodb / graph)。Graph; 
arangosh [_system]> var db = require(org / arangodb)。db;
arangosh [_system]> statement = db._createStatement({query:'FOR vert IN imdb_vertices FILTER vert.type ==PersonLET edge_count =(LENGTH(EDGES(imdb_edges,vert,outbound,[{type:ACTS_IN}])) )RETURN {name:vert.name,count:edge_count}'})
[object ArangoStatement]

arangosh [_system]> cursor = statement.execute()
[object ArangoQueryCursor]

arangosh [_system]> cursor.next()
{
name:Stephanie Faracy,
count:0
}
pre>

如何使用AQL做到这一点?

解决方案

一个索引:以下将返回Top-10:

  arangosh [_system]> db._createStatement({query:'FOR vert IN imdb_vertices FILTER vert.type ==PersonLET edge_count =(LENGTH(EDGES(imdb_edges,vert,outbound,[{type:Role,$ label :ACTS_IN}])))SORT edge_count DESC LIMIT 10 RETURN {name:vert.name,count:edge_count}'})。execute()。toArray()
[
{
name:Clint Eastwood,
count:148
},
{
name:Claude Jade,
count:142
},
{
name:Samuel L. Jackson,
count:122
},
$ bname:Armin Mueller-Stahl,
count:112
},
{
name:GérardDepardieu ,
count:104
},
{
name:Marisa Mell,
count:104
},
{
name:Robert De Niro,
count:104
},
{
name:Bruce Willis ,
count:96
},
{
name:成龙,
count:94
},
{
name:Michael Caine,
count:90
}

$ / code>

基本上,您也可以使用sort对于用LET创建的变量。限制允许您限制为TOP 10。请注意,顶点中的类型是'角色',标签是'ACTS_IN'。



添加编号到文档并使用排序后的索引。但这需要更新文件。

  arangosh [_system]> c = db._createStatement({query:'FOR vert IN imdb_vertices FILTER vert.type ==PersonLET edge_count =(LENGTH(EDGES(imdb_edges,vert,outbound,[{type:Role, $ label $ {
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' b arangosh [_system]> while(c.hasNext()){var d = c.next(); db.imdb_vertices.update(d._key,{COUNT:d.count}); }

arangosh [_system]> db.imdb_vertices.ensureSkiplist( 计数);

arangosh [_system]> x = db._createStatement({query:'FOR in imdb_vertices FILTER vert.COUNT> = 0 SORT vert.COUNT DESC LIMIT 10 RETURN vert}}。execute()
[object ArangoQueryCursor]


I am trying to get get the ten people who have starred in the most movies and get the name and the number of movies in decending order. I am using the IMDB dataset.

This is what I have so far:

arangosh [_system]>   var Graph = require("org/arangodb/graph").Graph;
arangosh [_system]>   var db = require("org/arangodb").db;
arangosh [_system]> statement = db._createStatement({query: 'FOR vert IN imdb_vertices FILTER vert.type == "Person" LET edge_count = (LENGTH(EDGES(imdb_edges, vert, "outbound", [{type: "ACTS_IN"}]))) RETURN {"name": vert.name,  "count": edge_count}'})
[object ArangoStatement]

arangosh [_system]> cursor = statement.execute()
[object ArangoQueryCursor]

arangosh [_system]> cursor.next()
{ 
  "name" : "Stephanie Faracy", 
  "count" : 0 
}

How can I do that with AQL?

解决方案

Without an index: The following will return the Top-10:

arangosh [_system]> db._createStatement({query: 'FOR vert IN imdb_vertices FILTER vert.type == "Person" LET edge_count = (LENGTH(EDGES(imdb_edges, vert, "outbound", [{"type": "Role", "$label": "ACTS_IN"}]))) SORT edge_count DESC LIMIT 10 RETURN {"name": vert.name,  "count": edge_count}'}).execute().toArray()
[ 
  { 
    "name" : "Clint Eastwood", 
    "count" : 148 
  }, 
  { 
    "name" : "Claude Jade", 
    "count" : 142 
  }, 
  { 
    "name" : "Samuel L. Jackson", 
    "count" : 122 
  }, 
  { 
    "name" : "Armin Mueller-Stahl", 
    "count" : 112 
  }, 
  { 
    "name" : "Gérard Depardieu", 
    "count" : 104 
  }, 
  { 
    "name" : "Marisa Mell", 
    "count" : 104 
  }, 
  { 
    "name" : "Robert De Niro", 
    "count" : 104 
  }, 
  { 
    "name" : "Bruce Willis", 
    "count" : 96 
  }, 
  { 
    "name" : "Jackie Chan", 
    "count" : 94 
  }, 
  { 
    "name" : "Michael Caine", 
    "count" : 90 
  } 
]

Basically you can use the "sort" also for variables created with LET. Limit allows you to restrict to the TOP 10. Note that the type in vertex is 'Role' and label is 'ACTS_IN'.

It would be more efficient to add the number to the documents and use a sorted index. But this would require to updating the documents.

arangosh [_system]> c = db._createStatement({query: 'FOR vert IN imdb_vertices FILTER vert.type == "Person" LET edge_count = (LENGTH(EDGES(imdb_edges, vert, "outbound", [{"type": "Role", "$label": "ACTS_IN"}]))) RETURN {"_key": vert._key,  "count": edge_count}'}).execute()
[object ArangoQueryCursor]

arangosh [_system]> while (c.hasNext()) { var d = c.next(); db.imdb_vertices.update(d._key, {COUNT: d.count}); }

arangosh [_system]> db.imdb_vertices.ensureSkiplist("COUNT");

arangosh [_system]> x = db._createStatement({query: 'FOR vert in imdb_vertices FILTER vert.COUNT >= 0 SORT vert.COUNT DESC LIMIT 10 RETURN vert'}).execute()
[object ArangoQueryCursor]

这篇关于如何通过输入边缘的数量进行计数和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆