【发布时间】:2019-02-26 00:13:33
【问题描述】:
我已经为 c3p0 池配置了 maxPoolSize 10。 minPoolSize 为 3。 每当我启动服务器并为 mysql 数据库执行 show processlist 时,都会建立三个连接。除非服务器有大量流量,否则这将保持为三个。这很好。
我已经实现了第一次开始索引的搜索功能。 当应用程序进行搜索并且当我检查我的数据库的显示进程列表时,所有数据库连接现在都打开了。我看到所有 10 个连接都是打开的。 这是公认的行为。理想情况下,我会说使用打开 2 或 3 个连接可能会很好。 为什么休眠 lucene 使用许多连接? 我可以在某处为 lucene 配置最大连接数吗?
我在下面发布我的代码。
fullTextEntityManager.createIndexer().startAndWait();
将只为应用程序执行一次
@Transactional
public List<E> searchRecord(String searchText) {
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
if (CREATE_INDEX.equals("START")) {
try {
log.info("creating indexes");
fullTextEntityManager.createIndexer().startAndWait();
CREATE_INDEX = "END";
} catch (InterruptedException e) {
log.info("error in creating indexes", e);
}
}
log.info("lucene query builder");
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(getEntityClass())
.get();
// org.apache.lucene.search.Query luceneQuery =
// qb.keyword().onFields("name")
// .matching(searchText).createQuery();
if(searchText.contains(" ")){
String[] splittedText = searchText.split(" ");
searchText = splittedText[0];
}
org.apache.lucene.search.Query luceneQuery = qb.keyword().wildcard().onField(getSearchField())
.matching(searchText.toLowerCase() + '*').createQuery();
javax.persistence.Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, getEntityClass());
List<E> result = jpaQuery.getResultList();
return result;
}
【问题讨论】:
标签: java spring-mvc lucene hibernate-search c3p0