我们已经见到一些使用has步骤来过滤路径的例子。下面这个例子是找出从AUS出中经过DFW的五条路径。
We have seen a number of examples that use a has step to filter routes. The example below looks
for five routes that start in Austin (AUS) and go via Dallas (DFW).

 运行查询,如我们所料,找到了五条路径,从AUS出发在DFW中转的路径。

When run the query, as expected finds us five routes that start in AUS and stop at DFW on the way.

 如果我们知道我们想在DFW的哪一站中转这个查询是奏效的。然而我们可能想写一个查询,它只返回访问某处的指定的机场的结果。现在分举一个例子,分两个阶段。首先看下面的查询。它找了从AUS出发的10条路径,路上在US或UK换乘,终点是爱丁堡。

This technique works well if we know which stop we want to be in DFW. However, we might want
to write a query that can only return results that include a visit to a specific airport anywhere in
the journey. Let’s build an example in two stages. First of all look at the query below. It looks for ten
routes that start in Austin and end up in Edinburgh only stopping along the way in US or the UK
airports.
 

 

 运行查询我们得到了下面的结果。

When run we get the following results.
 

 

然而为了让这个例子更有趣。让我们假设我们只想返回通过MAN的路径。我们可以这么做,对前一个查询进行调整找到MAN ,因为遍历了图,跟踪路径,用一个sack,路上会经过MAN的。一旦我们到达了EDI, 我们就用一个where步骤来排除sack中值不是1的。值是1就意味着着我们在路上遇到了MAN。

However, for the sake of making the example more interesting, let’s assume that we only want to
get back routes that go via Manchester (MAN). We can do this by adjusting the prior query to look
for "MAN" as it traverses the graph and keep track, using a sack, of paths that encounter
Manchester along the way. Once we arrive at EDI we use a where step to filter out routes where the
value of the sack is anything but "1". A value of "1" means we encountered Manchester along the
way.
 

 

 当我们运行修改后的查询,路径中的每条结果都包含了MAN。

When the modified query is run, each result includes MAN in the path.

 如果您把限制的数量调整为30,这会您将看到MAN可能出现地路径的任意位置上。 

If we you increase the limit step to use a value such as 30, then you will start to see that MAN can
appear in any position in the path.

 

 

posted on 2022-04-29 09:50  bokeyuannicheng0000  阅读(14)  评论(0)    收藏  举报