【发布时间】:2015-12-22 07:25:01
【问题描述】:
我正在尝试使用 Hibernate 创建全文索引并将特定搜索结果作为列表。 我不能超越会话初始化。
这是我的代码:
这是 HibernateUtil 类:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
这是我启动 FullTextSession 的代码:
try {
fullTextSession = Search.getFullTextSession(HibernateUtil.getSessionFactory().getCurrentSession());
fullTextSession.createIndexer().startAndWait();
} catch (InterruptedException ex) {
Logger.getLogger(SatisYonetimiEkrani.class.getName()).log(Level.SEVERE, null, ex);
}
这是我要进行全文搜索的功能:
private void aramaYap() {
QueryBuilder productQb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Satislar.class).get();
Query fullTextQuery = (Query) productQb.keyword().onField("musteriadi").matching("Ramazan").createQuery();
List<Satislar> satis = fullTextQuery.list();
for (int i = 0; i < satis.size(); i++) {
System.out.println(satis.get(i).getMusteriadi());
}
}
我认为我的 jar 文件可能有问题。以下是 jar 文件列表:
【问题讨论】:
标签: java hibernate lucene full-text-search hibernate-search