4
我正在運行一個應用程序,它使用hibernate搜索來查找系統中的人。我在JBoss AS 7.1.1上運行它,該應用程序基於Seam 3,Weld和JSF 2.1。它運行平穩,但在一些較高的負載後,事實證明使用FullTextEntityManager
的頁面加載非常緩慢。在某些時候,整個應用程序正在放緩。在JBoss 7.1.1上進行休眠搜索最後,焊接和縫3
因此,我想我也許使用Hibernate搜索不正確。我使用的是單啓動索引數據庫:
@Singleton
@Startup
public class Initializer implements Serializable {
private static final long serialVersionUID = 1L;
@PersistenceContext
private EntityManager entityManager;
@PostConstruct
public void startup() throws Exception {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
fullTextEntityManager.createIndexer().startAndWait();
}
}
然後我用的方法FullTextEntityManager
是在PrimeFaces的自動完成組件中使用:
@Session Scoped
public class ... {
private QueryBuilder queryBuilder;
@Inject
private EntityManager entityManager;
@PostConstruct
public void initFulltext() {
fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get();
}
@Override
@SuppressWarnings("unchecked")
public List<Person> autocomplete(Object event) throws Exception {
if (event.toString() != null && !event.toString().trim().isEmpty()) {
org.apache.lucene.search.Query query = queryBuilder.keyword()
.onFields("username", "firstname", "lastname").matching(event.toString())
.createQuery();
FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Person.class);
persistenceQuery.setMaxResults(MAX_RESULTS_ON_PAGE);
return persistenceQuery.getResultList();
}
return null;
}
}
這是一個正確用法Java EE應用程序中的Hibernate搜索?是不是有可能在一段時間後,hibernate搜索試圖同步實體和Lucene索引的變化?如果是這樣,它是否有可能對性能造成巨大影響?
看起來沒錯。我會做一些測試。感謝參考。 – lukas
是啊,不只是有任何辦法做到這一點。從查詢到查詢各不相同。樂於幫助。 Regards –
@lukas,好奇地知道你是否解決了你的問題?如何? –