4

ArangoDB 的许多(全部?)图形函数都接受“示例”文档。示例参数的文档说:

{} : Returns all possible vertices for this graph
idString : Returns the vertex/edge with the id idString
[idString1, idString2 ...] : Returns the vertices/edges with the ids matching the given strings.
{key1 : value1, key2 : value2} : Returns the vertices/edges that match this example, which means that both have key1 and key2 with the corresponding attributes
{key1.key2 : value1, key3 : value2} : It is possible to chain keys, which means that a document {key1 : {key2 : value1}, key3 : value2} would be a match
[{key1 : value1}, {key2 : value2}] : Returns the vertices/edges that match one of the examples, which means that either key1 or key2 are set with the corresponding value

在每种情况下(idString 除外),我似乎都为 Arango 提供了一个键和一个值来匹配。

有没有办法让我创建一个匹配任何具有特定键的文档的示例(只要值不为空)?

只是为了说明,在这里我想获取任何具有“actor”键的相邻顶点,我不在乎该键的值是什么(只要它有一个):

db._query('RETURN GRAPH_NEIGHBORS("movies", {movie: "Scarfies"}, {neighborExamples: [{actor: *}]})').toArray()

这在 ArangoDB 中可行吗?

4

1 回答 1

4

我认为目前无法做到这一点,因为在示例中您无法指定通配符。

由于我们最近向其他几个图形函数添加了自定义访问者选项,因此也可以直接为GRAPH_NEIGHBORS. 访问者将如下所示:

var func = function (config, result, vertex, path) { 
  if (vertex.hasOwnProperty('actor')) { 
    return vertex; 
  } 
};
require("org/arangodb/aql/functions").register("my::actorVisitor", func);

以及获取感兴趣的邻居的 AQL 查询:

RETURN GRAPH_NEIGHBORS("movies", { movie: "Scarfies" }, {
  visitorReturnsResult: true, 
  visitor: "my::actorVisitor" 
})

不确定这是否是最佳选择,但至少它会产生预期的结果。如果您认为这是明智的,请告诉我们,以便我们可以在 2.4.4 中添加它

于 2015-02-10T18:52:31.010 回答