意外的空值neo4j [英] Unexpected null value,neo4j

查看:204
本文介绍了意外的空值neo4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

}

recommended.class

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

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


推荐答案

我认为你的查询返回null。

I think that your query returns null.

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

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

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

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

这篇关于意外的空值neo4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆