Unexpected null value,neo4j

白昼怎懂夜的黑 提交于 2019-12-08 04:43:15

问题


I don't know why I can't get the value of the movie fields. I debugged it and I found the movie is null. I post a picture and you will see it

. Please give me some advice. I am sure I had created the relationship successfully, may somewhere wrong with recommendation. Class or cypher?
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;
   }
}

controller

@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";
}

run cypher use 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:


I think that your query returns null.

So the first element [0] have a movie which is null...

The movie 'AA' should be in [1] in your array because you make the query and after it you append the recommendation



来源:https://stackoverflow.com/questions/29913882/unexpected-null-value-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!