本文整理汇总了Java中com.liferay.portal.kernel.search.Hits.setLength方法的典型用法代码示例。如果您正苦于以下问题:Java Hits.setLength方法的具体用法?Java Hits.setLength怎么用?Java Hits.setLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.liferay.portal.kernel.search.Hits
的用法示例。
在下文中一共展示了Hits.setLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSearchHits
import com.liferay.portal.kernel.search.Hits; //导入方法依赖的package包/类
/**
* Gets the search hits.
*
* @param searchEngineId the search engine id
* @param companyId the company id
* @param query the query
* @param sort the sort
* @param start the start
* @param end the end
* @return the search hits
*/
public Hits getSearchHits(String searchEngineId, long companyId, Query query, Sort[] sort, int start, int end) {
if (_log.isInfoEnabled()) {
_log.info("Search against Elasticsearch with searchEngineId, companyId, query, sort, start and end parameters");
}
Hits hits = new HitsImpl();
Client client = this._esConnector.getClient();
SearchRequestBuilder searchRequestBuilder = client
.prepareSearch(
ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX)
.setQuery(_esQueryBuilder.doSearch(query));
SearchResponse response = null;
if (getSort(sort) != null) {
response = searchRequestBuilder.setFrom(start)
.setSize(end)
.addSort(getSort(sort))
.execute().actionGet();
} else {
response = searchRequestBuilder.setFrom(start)
.setSize(end)
.execute().actionGet();
}
SearchHits searchHits = response.getHits();
hits.setDocs(getDocuments(searchHits));
hits.setScores(getScores(searchHits));
hits.setSearchTime(
(float)(System.currentTimeMillis() - hits.getStart()) /
Time.SECOND);
hits.setQuery(query);
hits.setLength((int)searchHits.getTotalHits());
hits.setStart(hits.getStart());
return hits;
}