Search in sources :

Example 11 with SearchFacetDTO

use of org.broadleafcommerce.core.search.domain.SearchFacetDTO in project BroadleafCommerce by BroadleafCommerce.

the class DatabaseSearchServiceImpl method getCategoryFacets.

@Override
@SuppressWarnings("unchecked")
public List<SearchFacetDTO> getCategoryFacets(Category category) {
    List<SearchFacetDTO> facets = null;
    String cacheKey = CACHE_KEY_PREFIX + "category:" + category.getId();
    Element element = cache.get(cacheKey);
    if (element != null) {
        facets = (List<SearchFacetDTO>) element.getValue();
    }
    if (facets == null) {
        List<CategorySearchFacet> categorySearchFacets = category.getCumulativeSearchFacets();
        List<SearchFacet> searchFacets = new ArrayList<SearchFacet>();
        for (CategorySearchFacet categorySearchFacet : categorySearchFacets) {
            searchFacets.add(categorySearchFacet.getSearchFacet());
        }
        facets = buildSearchFacetDtos(searchFacets);
        element = new Element(cacheKey, facets);
        cache.put(element);
    }
    return facets;
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) Element(net.sf.ehcache.Element) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ArrayList(java.util.ArrayList)

Example 12 with SearchFacetDTO

use of org.broadleafcommerce.core.search.domain.SearchFacetDTO in project BroadleafCommerce by BroadleafCommerce.

the class DatabaseSearchServiceImpl method findSearchResultsByCategory.

@Override
public SearchResult findSearchResultsByCategory(Category category, SearchCriteria searchCriteria) {
    SearchResult result = new SearchResult();
    setQualifiedKeys(searchCriteria);
    List<Product> products = catalogService.findFilteredActiveProductsByCategory(category, searchCriteria);
    List<SearchFacetDTO> facets = getCategoryFacets(category);
    setActiveFacets(facets, searchCriteria);
    result.setProducts(products);
    result.setFacets(facets);
    result.setTotalResults(products.size());
    result.setPage(1);
    result.setPageSize(products.size());
    return result;
}
Also used : SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) Product(org.broadleafcommerce.core.catalog.domain.Product) SearchResult(org.broadleafcommerce.core.search.domain.SearchResult)

Aggregations

SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)12 ArrayList (java.util.ArrayList)4 Product (org.broadleafcommerce.core.catalog.domain.Product)3 SearchFacet (org.broadleafcommerce.core.search.domain.SearchFacet)3 SearchResult (org.broadleafcommerce.core.search.domain.SearchResult)3 BigDecimal (java.math.BigDecimal)2 Element (net.sf.ehcache.Element)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 CategorySearchFacet (org.broadleafcommerce.core.search.domain.CategorySearchFacet)2 SearchFacetResultDTO (org.broadleafcommerce.core.search.domain.SearchFacetResultDTO)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 FacetField (org.apache.solr.client.solrj.response.FacetField)1 Count (org.apache.solr.client.solrj.response.FacetField.Count)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1