【发布时间】:2013-09-04 15:01:40
【问题描述】:
我正在尝试将休眠搜索集成到我现有的应用程序中。根据休眠搜索的教程,我在 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):
- 休眠搜索 - 3.2.0.Final
- hibernate-commons-annotations 4.0.1.Final
- hibernate-core - 4.1.11 最终版
- 休眠实体管理器 - 3.4.0.GA
- 春天 - 3.2.2 发布
- lucene-core - 3.2.0
我正在使用此示例代码在 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.jar 来解决问题
标签: java spring lucene hibernate-search