Cypher Search Query Fuzzy query

左心房为你撑大大i 提交于 2019-12-12 03:08:13

问题


I want to use cypher to search,

  1. I have four movie enerties, forrest, sky, sky1, sky2
  2. I want search sky
  3. 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

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