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

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

Introduction

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

Prototype

String getValue();

Source Link

Document

The value within the field

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);
            }//from   w  ww  . j a  v  a 2 s .co  m
        }
    }

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