gpt4 book ai didi

java - 意外的空值,neo4j

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:58 27 4
gpt4 key购买 nike

我不知道为什么我无法获取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);

}

推荐.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";
}

使用 neo4j-community 运行 cypher

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。

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

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

关于java - 意外的空值,neo4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29913882/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com