问题
I want to use cypher to search,
- I have four movie enerties, forrest, sky, sky1, sky2
- I want search sky
- I want it returns sky, sky1, sky2
My cypher is
@Query("MATCH (movie:Movie) WHERE movie.title =~ '.*{0}.*' RETURN movie")
or
@Query("MATCH (movie:Movie) WHERE movie.title =~ '(?i).*{0}.*' RETURN movie")
Neither of those works well: it return forrest, sky,sky1, sky2 no matter what I search (forrest or sky). What is wrong? controller
@RequestMapping(value = "/movies", method = RequestMethod.GET, headers = "Accept=text/html")
public String findMovies(Model model, @RequestParam("q") String query) {
if (query != null && !query.isEmpty()) {
List<Movie> movies = movieRepository.findByTitleLike("(?i).*sky.*");
model.addAttribute("movies", IteratorUtil.asCollection(movies));
} else {
model.addAttribute("movies", Collections.emptyList());
}
model.addAttribute("query", query);
return "movies/list";
}
回答1:
The last time I was doing regular expression matching was in a previous version of Neo4j, at that time you could not construct the regular expression using a parameter in this way. The {0}
does not get converted. Instead you should change your query to:
@Query("MATCH (movie:Movie) WHERE movie.title =~ {0} RETURN movie")
List<Movie> findByTitleLike(String like)
And call it with:
myMovieRepository.findByTitleLike("(?i).*sky.*")
来源:https://stackoverflow.com/questions/29505787/cypher-search-query-fuzzy-query