如何使用spring数据neo4j搜索全文

时间:2015-04-03 09:18:33

标签: spring spring-mvc neo4j spring-data-neo4j

我正在学习弹簧数据neo4j和spring。我想搜索全文,例如我有三部电影(天空,天空1,天空2),当我搜索“天空”时,它返回天空,sky1,sky2.firt我使用

下面的存储库
package com.oberon.fm.repository;
@Repository
     public interface MovieRepository extends GraphRepository<Movie> {
     Movie findById(String id);
     Page<Movie> findByTitleLike(String title, Pageable page);
}

我的控制器

@RequestMapping(value = "/movies", method = RequestMethod.GET, headers = "Accept=text/html")
public String findMovies(Model model, @RequestParam("q") String query) {
    log.debug("1");
    if (query != null && !query.isEmpty()) {
        Page<Movie> movies =movieRepository.findByTitleLike(query, new PageRequest(0, 20));
        model.addAttribute("movies", movies.getContent());
    } else {
        model.addAttribute("movies", Collections.emptyList());
    }
    model.addAttribute("query", query);
    addUser(model);
    return "/movies/list";
}

这些效果不好,我认为某处可能有问题,但我不知道,如果您有任何想法,请告诉我谢谢!顺便说一句,它抛出异常java.lang.NullPointerException。 我的电影实体

@NodeEntity
public class Movie {
@GraphId
Long nodeId;

@Indexed(indexType = IndexType.FULLTEXT, indexName = "id")
String id;

@Indexed(indexType = IndexType.FULLTEXT, indexName = "search")
String title;

String description;

@RelatedTo(type = "DIRECTED", direction = INCOMING)
Set<Director> directors;

@RelatedTo(type = "ACTS_IN", direction = INCOMING)
Set<Actor> actors;

@RelatedToVia(type = "ACTS_IN", direction = INCOMING)
Iterable<Role> roles;

@RelatedToVia(type = "RATED", direction = INCOMING)
@Fetch
Iterable<Rating> ratings;
private String language;
private String imdbId;
private String tagline;
private Date releaseDate;
private Integer runtime;
private String homepage;
private String trailer;
private String genre;
private String studio;
private Integer version;
private Date lastModified;
private String imageUrl;

0 个答案:

没有答案