意外的空值neo4j

时间:2015-04-28 08:12:24

标签: java neo4j cypher spring-data-neo4j

我不知道为什么我无法获得movie字段的价值。我调试了它,发现movie为空。我发布了一张图片,你会看到它enter image description here。请给我一些建议。我确信我已经成功建立了这种关系,可能在推荐方面出错了。类或密码?

public interface MovieRepository extends GraphRepository<Movie> {


@Query("match (user:User {login: {0}})-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) "
        + " where r.stars >= 3 and r2.stars >= r.stars and r3.stars >= r.stars "
        + " with otherMovie, avg(r3.stars) as rating, count(*) as cnt" 
        + " order by rating desc, cnt desc"
        + " return otherMovie as movie, rating limit 10")
List<MovieRecommendation> getRecommendations(String login);

}

recommend.class

@QueryResult
public class MovieRecommendation {


Movie movie;
int rating;
public Movie getMovie() {
    return movie;
}
public void setMovie(Movie movie) {
    this.movie = movie;
}
public int getRating() {
    return rating;
}
public void setRating(int rating) {
    this.rating = rating;
   }
}

控制器

@RequestMapping(value = "/user", method = RequestMethod.GET)
public String profile(Model model, HttpServletRequest request) {

    HttpSession session = request.getSession(false);
    User user = (User) session.getAttribute("user");
    model.addAttribute("user", user);

    if (user != null) {
        List<MovieRecommendation> mr = movieRepository.getRecommendations(user.getLogin());
    MovieRecommendation movie = new MovieRecommendation();
    Movie m = new Movie();
    m.setTitle("AA");
    movie.setMovie(m);
    mr.add(movie);
    model.addAttribute("recommendations", mr);
    }
    return "user/index";
}

运行cypher使用neo4j-community

match (user:ollie)-[r:RATED]->(movie)<-[r2:RATED]-(other)-[r3:RATED]->(otherMovie) 
where r.stars >= 1 and r2.stars >= r.stars and r3.stars >= r.stars 
with otherMovie, avg(r3.stars) as rating, count(*) as cnt
order by rating desc, cnt desc
return otherMovie limit 10

1 个答案:

答案 0 :(得分:0)

我认为您的查询返回null。

所以第一个元素[0]有一个空的电影......

电影“AA”应该在数组的[1]中,因为你进行了查询,之后你附加了推荐