密码查询条件无法按预期工作

时间:2015-06-11 19:55:25

标签: neo4j cypher

我有这个密码查询,我需要帮助来改善输出请:

MATCH (first:Hit) WHERE first.page_key =~ '(?i)(.*bonus.*)'
and NOT(()-[:NEXT*]->first)

MATCH (last:Hit) WHERE last.page_key =~ '(?i).*shop.*' 
and NOT(()<-[:NEXT*]-last)

MATCH  path=first-[:NEXT*]->last

with filter(n in NODES(path) where n:Hit) as filtered
with extract(v in filtered|lower(v.page)) as ex

UNWIND ex AS pages
with  COLLECT( distinct pages) as pages1,ex

return pages1,count(pages1) as cnt,length(pages1) as len
order by cnt desc

这些是(部分)结果,在csv导出之后:(域名和页面被扰乱)

"[""/bonus12"",""bonus2"",""/register1"",""/shop""]",1,10
"[""bonus5"",""/shop"",""/shop4""]",1,6
"[""bonus1"",""bonus2"",""/shop""]",1,4
"[""bonus2"",""/register1"",""/register5"",""/shop""]",1,4
"[""bonus2"",""/shop""]",4,17

第一件事我不明白为什么我有值:/ bonus12“,结果列表中的bonus2虽然我有这个条件:

and NOT(()-[:NEXT*]->first)

和/ shop,/ shop4相同,虽然我有这个条件:

and NOT(()<-[:NEXT*]-last)

第二个问题是我如何替换此过滤器:

and NOT(()<-[:NEXT*]-last)

“路径中的最后一页,名称为bonus,之后可能有其他页面,其他名称......”

另外,因为我知道neo4j只有2周,如果有人对上面的代码有反馈,我会很感激

这是一个数据模型:(除了Hit应该有一个“page”属性)

http://console.neo4j.org/?id=8wnskw

利奥尔

1 个答案:

答案 0 :(得分:0)

我会像这样清理你的查询:

MATCH (first:Hit) WHERE first.page_key =~ '(?i)(.*bonus.*)' and NOT(()-[:NEXT]->first)
MATCH (last:Hit) WHERE last.page_key =~ '(?i).*shop.*' and NOT(()<-[:NEXT]-last)
// this will be potentially a large list,
// consider allShortestPaths()
MATCH  path=(first)-[:NEXT*]->(last)
WHERE ALL(n in nodes(path) where n:Hit)
UNWIND extract(v in nodes(path) | lower(v.page)) as page
RETURN distinct page