use of com.publiccms.common.handler.FacetPageHandler 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;
}
use of com.publiccms.common.handler.FacetPageHandler in project PublicCMS-preview by sanluan.
the class CmsFacetSearchDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
String word = handler.getString("word");
Long[] tagIds = handler.getLongArray("tagId");
if (CommonUtils.notEmpty(word) || CommonUtils.notEmpty(tagIds)) {
SysSite site = getSite(handler);
if (CommonUtils.notEmpty(word)) {
statisticsComponent.search(site.getId(), word);
}
if (CommonUtils.notEmpty(tagIds)) {
for (Long tagId : tagIds) {
statisticsComponent.searchTag(tagId);
}
}
PageHandler page;
Integer pageIndex = handler.getInteger("pageIndex", 1);
Integer count = handler.getInteger("count", 30);
try {
page = service.facetQuery(site.getId(), handler.getStringArray("categoryId"), handler.getStringArray("modelId"), word, tagIds, handler.getDate("startPublishDate"), handler.getDate("endPublishDate", CommonUtils.getDate()), pageIndex, count);
} catch (Exception e) {
page = new FacetPageHandler(pageIndex, count, 0, null);
}
handler.put("page", page).render();
}
}
Aggregations