我正在尝试将休眠搜索集成到我现有的应用程序中。根据休眠搜索的教程,我在applicationContext.xml的休眠属性中添加了以下属性
<prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</prop>
<prop key="hibernate.search.default.indexBase">./lucene/indexes</prop>
另外,我在要启用搜索的实体类上添加了注释。在类上使用@Indexed,在字段上使用@Field。
以下是我使用的版本(我不使用Maven):
我正在使用此示例代码在MySQL数据库中执行搜索:
public void search() {
FullTextSession searchSession = Search.getFullTextSession(sessionFactory.getCurrentSession());
QueryParser parser = new QueryParser(Version.LUCENE_32, "contenu", new StandardAnalyzer(Version.LUCENE_32));
org.apache.lucene.search.Query query = parser.parse("décarbonateront");
org.hibernate.Query hibQuery = searchSession.createFullTextQuery(query, Book.class);
List result = hibQuery.list();
System.out.println("lucene results: " + result.size());
}
但是我得到这个错误: The type org.hibernate.classic.Session cannot be resolved. It is indirectly referenced from required .class files
在 : searchSession.createFullTextQuery(query, Book.class);
可能是什么问题?
您需要对齐Hibernate和Hibernate Search版本。您需要Hibernate 3.5.x才能进行Hibernate Search 3.2。检查Maven pom中的版本-https: //repository.jboss.org/nexus/content/repositories/public/org/hibernate/hibernate-search-parent/3.2.0.Final/hibernate-search-parent- 3.2.0.Final.pom。
您也可以从Sourceforge下载Hibernate Search发行版。该发行版还包含所有正确的依赖项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句