使用hibernate-search-4.1.1.Final.jar进行Hibernate全文搜索但是像查询构建器这样的错误无法解决

时间:2015-12-19 04:36:37

标签: java spring hibernate lucene hibernate-search

我在查询构建器中遇到错误,无法输入,并且找不到 org.apache.lucene

我将添加与spring-mvc和hibernate相关的所有jar

@Repository
public class SearchDAO {
    @Autowired
    SessionFactory sessionFactory;

    @Transactional
    public List<SearchVO> viewSeachResult(String searchText) throws Exception
     {
      try
      {
        Session s= this.sessionFactory.openSession();
        //Session s= HibernateUtil.getSession();
        FullTextSession text = Search.getFullTextSession(s);

        // create native Lucene query unsing the query DSL
        // alternatively you can write the Lucene query using the Lucenquery
        // parser
        // or the Lucene programmatic API. The Hibernate Search DSL is
        // recommended though

        QueryBuilder qb =     text.getSearchFactory().buildQueryBuilder().forEntity(SearchVO.class).get();

        org.apache.lucene.search.Query query= qb.keyWord().onFields("Description","Title","Author","Area").matching(searchText).createQuery();

        org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query,SearchVO.class);
        List<SearchVO> result= hibQuery.list();
        return result;
      }catch(Exception e)
      {
        throw e;
      }
    }
}

1 个答案:

答案 0 :(得分:1)

我认为你需要hibernate-search jar

提到所需的罐子here

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-search</artifactId>
    <version>5.3.0.Final</version>
</dependency>

您可以从here手动下载。

希望这有帮助。