使用 hibernate-search-4.1.1.Final.jar 进行 Hibernate 全文搜索,但无法解决查询生成器等错误
Hibernate full text search using hibernate-search-4.1.1.Final.jar but having error like query builder can not resolved
我在无法输入查询构建器和找不到 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;
}
}
}
我认为你需要 hibernate-search jar。
提到了所需的 jar here。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>5.3.0.Final</version>
</dependency>
您可以从here手动下载。
希望对您有所帮助。
我在无法输入查询构建器和找不到 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;
}
}
}
我认为你需要 hibernate-search jar。
提到了所需的 jar here。
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>5.3.0.Final</version>
</dependency>
您可以从here手动下载。
希望对您有所帮助。