2013-02-15 74 views
1

你好,这里是我当前的查询,我想“再过滤器”:滤波过滤一个暗号查询结果

START movie = node(*) 
MATCH user-[:LIKE]->category-[:SIMILAR*0..3]-()<-[:TAGGED]->movie 
WHERE user.name = "current_user" 

WITH DISTINCT movie, user, category 

RETURN user.name, category.name, ID(movie), movie.name 
ORDER BY movie.name; 

http://console.neo4j.org/r/u19iim

这是它看起来像当前查询后:

+--------------+----------------+-----------+-------------------------+ 
| user.name | category.name | ID(movie) | movie.name    | 
+--------------+----------------+-----------+-------------------------+ 
| current_user | c    | 14  | movie_c_and_d_and_e  | 
| current_user | d    | 14  | movie_c_and_d_and_e  | 
| current_user | e    | 14  | movie_c_and_d_and_e  | 
| current_user | a    | 9   | movie_of_a_and_b_and_b1 | 
| current_user | b    | 9   | movie_of_a_and_b_and_b1 | 
| current_user | b    | 10  | movie_of_b2_first  | 
| current_user | b    | 11  | movie_of_b2_second  | 
| current_user | c    | 12  | movie_of_c    | 
| current_user | d    | 13  | movie_of_d_and_e  | 
| current_user | e    | 13  | movie_of_d_and_e  | 
+--------------+----------------+-----------+-------------------------+ 

我想GROUP BY COUNT(sugg) AS category_count提取此:

+--------------+----------------+-----------+-------------------------+ 
| user.name | category_count | ID(movie) | movie.name    | 
+--------------+----------------+-----------+-------------------------+ 
| current_user | 3    | 14  | movie_c_and_d_and_e  | 
| current_user | 2    | 9   | movie_of_a_and_b_and_b1 | 
| current_user | 2    | 13  | movie_of_d_and_e  | 
| current_user | 1    | 10  | movie_of_b2_first  | 
| current_user | 1    | 11  | movie_of_b2_second  | 
| current_user | 1    | 12  | movie_of_c    | 
+--------------+----------------+-----------+-------------------------+ 

我该如何做到这一点?

类似的问题: - how to have two aggregation in cypher query in neo4j?

更新
这里的工作结果(有示范:http://tinyurl.com/cywlycc):

START movie = node(*) 
MATCH user-[:LIKE]->category-[:SIMILAR*0..3]-()<-[:TAGGED]->movie 
WHERE user.name = "current_user" 
WITH DISTINCT movie, category WITH COUNT(movie) AS category_count, movie, collect(category.name) as categorized 
RETURN category_count, ID(movie), movie.name, categorized 
ORDER BY category_count DESC; 

回答

2
START movie = node(*) 
MATCH user-[:LIKE]->category-[:SIMILAR*0..3]-()<-[:TAGGED]->movie 
WHERE user.name = "current_user" 
WITH DISTINCT movie, user, category 
RETURN user.name, count(category.name) as category_count, ID(movie), movie.name 
ORDER BY category_count desc, movie.name asc 

http://console.neo4j.org/r/69rfkn

+0

您的解决方案作品,并回答我的问题,我的查询有点恐怖我发现可以放置如下结果的WITH语句:START movie = node(*)MATCH user - [:LIKE] - > category - [:SIMILAR * 0..3] - ()<-[:TAGGED]->电影WHERE user.name =“current_user”WITH DISTINCT电影,类别WITH COUNT(电影)AS category_count,movie,collect(category.name)作为分类RETURN category_count,ID(电影),movie.name,分类 ORDER按category_count DESC;所以我可以有效地'重新筛选'我的结果。谢谢! http://tinyurl.com/cywlycc – 2013-02-15 23:49:51

+1

是的,这就是为什么,你也可以应用顺序和限制每个与聚合,然后过滤聚合后。也许把更新后的查询放在你的问题中,以便更好地格式化和可读。 – 2013-02-20 07:35:16