许多的查询语句,看起来使用match步骤是最佳的方案。它们也能以声名的方式,用一个where步骤来编写。我们可以重写前一节中的查询语句,查找从JFK出发但没有返程航班的路径,这次使用的是where步骤,如下所示。
As the Gremlin language has evolved, many queries that might seem a perfect candidate for a
match step can actually also be written using a where step but still in a more declarative style. We
can rewrite the query from the previous section that looks at routes from JFK that do not have a
return flight using a where step as shown below.
这种方式与使用match步骤的相似,如下所示。从JFK开始,查找我们能飞抵的所有的机场,但是我们只保留那些没有返回JFK的机场。注意在这个查询中as起到了两个作用。在where步骤之外,它用于标记我们在查询的后边想要引用的步骤,在where步骤内,它提供了一种简写的引用启程机场的方式。
The way to read this, in a similar way as with a match step is as follows. Starting at JFK, look at all
the places we can fly to but only keep those airports that do not have a route back to JFK. Note that
the as step plays two roles in this query. Outside of the where step it is used to label steps in the
query we want to refer back to later. Inside the where step it provides a convenient shorthand way
to refer back to the departure airport.
从前边的例子我们可能看到,如果您在结果中只想看到机场的代码code,没有s,d键值,那就增加一个额外的select步骤。
As we have seen in some prior examples, if you only want the airport codes in the result and not
the "s" and "d" keys, adding an additional select step is all that it takes.
这个查询可以扩展到搜索整个图中符合相同模式的。下面的例子返回了找到的前10个没有返程航班的路线。这些结果是按照启程机场的代码的升序排列的。
The query can be expanded to search for this same pattern across the whole graph. The example
below returns the first ten routes found where there is no return flight. The results are sorted in
ascending order using the departure airport code.
运行查询结果如下:
When run the query returns the following results.
浙公网安备 33010602011771号