2017-05-29 45 views
0

我必須在A和B之間找到所有具有附加屬性的最短路徑。查詢以查找附加條件的所有最短路徑都不會返回

該查詢返回我只有一個路由(這是真的,只有一個具有3個部分路線):

MATCH (darjeeling { name: 'Darjeeling' }),(sandakphu { name: 'Sandakphu' }), 
    paths = allShortestPaths((darjeeling)-[*]-(sandakphu)) 
RETURN paths 

結果:

{"start":{"identity":1,"labels":["town"],"properties":{"name":"Darjeeling"}},"end":{"identity":3,"labels":["peak"],"properties":{"altitude":"12400 ft","name":"Sandakphu"}},"segments":[{"start":{"identity":1,"labels":["town"],"properties":{"name":"Darjeeling"}},"relationship":{"identity":2,"start":1,"end":0,"type":"trek","properties":{"distance":15,"name":"Darjeeling-Rimbik","winter":"true","summer":"true"}},"end":{"identity":0,"labels":["town"],"properties":{"name":"Rimbik"}}},{"start":{"identity":0,"labels":["town"],"properties":{"name":"Rimbik"}},"relationship":{"identity":3,"start":0,"end":2,"type":"trek","properties":{"distance":18,"name":"Rimbik-BhikeBhanja","winter":"true","summer":"true"}},"end":{"identity":2,"labels":["village"],"properties":{"name":"BhikeBhanja"}}},{"start":{"identity":2,"labels":["village"],"properties":{"name":"BhikeBhanja"}},"relationship":{"identity":4,"start":2,"end":3,"type":"trek","properties":{"distance":4,"name":"BhikeBhanja-Sandakphu","winter":"true","summer":"true"}},"end":{"identity":3,"labels":["peak"],"properties":{"altitude":"12400 ft","name":"Sandakphu"}}}],"length":3} 

這條路線的所有部分都有屬性冬季設置爲true,但是如果我想將這樣的條件添加到我的查詢中,我沒有結果:

MATCH (darjeeling { name: 'Darjeeling' }),(sandakphu { name: 'Sandakphu' }), 
    paths = allShortestPaths((darjeeling)-[*]-(sandakphu)) 
WHERE ALL (p IN relationships(paths) WHERE p.winter = true) 
RETURN paths 

我的問題是,即使A和B之間存在路由,爲什麼第二個查詢不會返回結果,這是最短的路由,並且此路由上的所有路徑都將屬性winter設置爲true?

+1

是'冬天'布爾屬性或字符串屬性?如果條件是WHERE p.winter =「true」',你會得到結果嗎? – InverseFalcon

+0

確實這是一個字符串屬性!它適用於「」...... – TheOpti

回答

0

我相信你需要的路徑做另一MATCH,像這樣:

MATCH (darjeeling { name: 'Darjeeling' }), (sandakphu { name: 'Sandakphu' }) 
MATCH paths = allShortestPaths((darjeeling)-[*]-(sandakphu)) 
WHERE ALL (p IN relationships(paths) WHERE p.winter = true) 
RETURN paths 
+0

不幸的是,您的查詢不會返回任何結果。 – TheOpti

+0

添加第一個查詢的結果,希望它能幫助你? – TheOpti

1

形式化爲回答這個問題。

看起來像你有字符串屬性,而不是布爾屬性。這種情況應該爲你工作:

WHERE p.winter = "true"

如果你想改變這些成布爾屬性,則需要匹配具有這種性質和使用的所有關係:

SET p.winter = (p.winter = "true")