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";
}
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:And call it with: