Example usage for org.springframework.data.solr.core.query.result FacetEntry getKey

List of usage examples for org.springframework.data.solr.core.query.result FacetEntry getKey

Introduction

In this page you can find the example usage for org.springframework.data.solr.core.query.result FacetEntry getKey.

Prototype

Object getKey();

Source Link

Document

The key of the facetEntry

Usage

From source file:com.dm.estore.search.services.impl.CatalogSearchServiceImpl.java

@Override
public ProductSearchResultDto findProducts(ProductSearchDto searchRequest) {

    Sort sort = new Sort(Sort.Direction.fromString(searchRequest.getSortOrder()),
            searchRequest.getSortColumn());
    PageRequest pageRequest = new PageRequest(searchRequest.getPage(), searchRequest.getPageSize(), sort);
    FacetPage<CatalogItemDto> catalogItems = catalogSearchRepository.searchProducts(
            searchRequest.getSearchTerms(), searchRequest.getCategory(), searchRequest.getMaterials(),
            searchRequest.getColors(), pageRequest);

    ProductSearchResultDto result = new ProductSearchResultDto();
    result.setTotalCount(catalogItems.getTotalElements());

    for (Page<? extends FacetEntry> page : catalogItems.getAllFacets()) {
        for (FacetEntry facetEntry : page.getContent()) {
            String key = String.valueOf(facetEntry.getKey());
            String facetCode = facetEntry.getValue(); // name of the category
            long count = facetEntry.getValueCount(); // number of books in this category

            if (StringUtils.isEmpty(facetCode))
                continue;

            if (CatalogItemDto.FIELD_CATEGORY.equalsIgnoreCase(key)) {
                result.getCategoriesFacet().put(facetCode, count);
            } else if (CatalogItemDto.FIELD_VARIANT_GROUP.equalsIgnoreCase(key)) {
                result.getGroupFacet().put(facetCode, count);
            } else if (CatalogItemDto.FIELD_CATEGORY.equalsIgnoreCase(key)) {
                result.getSubGroupFacet().put(facetCode, count);
            }/*w  w w.  jav  a 2  s. c o m*/
        }
    }

    result.setProducts(productConverter.convert(catalogItems.getContent()));
    result.setTotalCount((int) (catalogItems.getTotalElements()));
    return result;
}