use of org.hibernate.search.query.facet.FacetingRequest in project PublicCMS-preview by sanluan.
the class BaseDao method getFacetPage.
/**
* @param fullTextQuery
* @param facetFields
* @param valueMap
* @param pageIndex
* @param pageSize
* @param maxResults
* @return facet results page
*/
protected FacetPageHandler getFacetPage(QueryBuilder queryBuilder, FullTextQuery fullTextQuery, String[] facetFields, Map<String, List<String>> valueMap, int facetCount, Integer pageIndex, Integer pageSize, Integer maxResults) {
FacetManager facetManager = fullTextQuery.getFacetManager();
for (String facetField : facetFields) {
FacetingRequest facetingRequest = queryBuilder.facet().name(facetField + FACET_NAME_SUFFIX).onField(facetField).discrete().orderedBy(FacetSortOrder.COUNT_DESC).includeZeroCounts(false).maxFacetCount(facetCount).createFacetingRequest();
facetManager.enableFaceting(facetingRequest);
}
FacetPageHandler page = new FacetPageHandler(pageIndex, pageSize, fullTextQuery.getResultSize(), maxResults);
if (0 < page.getTotalCount()) {
Set<String> facetSet = new LinkedHashSet<>();
facetSet.addAll(valueMap.keySet());
facetSet.addAll(Arrays.asList(facetFields));
for (String facetField : facetSet) {
String facetingName = facetField + FACET_NAME_SUFFIX;
List<Facet> facets = facetManager.getFacets(facetingName);
Map<String, Integer> facetMap = new LinkedHashMap<>();
List<String> valueList = valueMap.get(facetField);
if (null != valueList) {
List<Facet> facetList = new ArrayList<>();
for (Facet facet : facets) {
facetMap.put(facet.getValue(), facet.getCount());
if (valueList.contains(facet.getValue())) {
facetList.add(facet);
}
}
if (!facetList.isEmpty()) {
facetManager.getFacetGroup(facetingName).selectFacets(facetList.toArray(new Facet[facetList.size()]));
}
} else {
for (Facet facet : facets) {
facetMap.put(facet.getValue(), facet.getCount());
}
}
page.getFacetMap().put(facetField, facetMap);
}
page.setTotalCount(fullTextQuery.getResultSize(), maxResults);
page.init();
}
if (CommonUtils.notEmpty(pageSize)) {
fullTextQuery.setFirstResult(page.getFirstResult()).setMaxResults(page.getPageSize());
}
page.setList(fullTextQuery.list());
return page;
}
Aggregations