Search in sources :

Example 1 with SearchFacetResultDTO

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

the class ToggleFacetLinkProcessor method getModifiedAttributes.

@Override
public BroadleafAttributeModifier getModifiedAttributes(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    String baseUrl = request.getRequestURL().toString();
    Map<String, String[]> params = new HashMap<>(request.getParameterMap());
    SearchFacetResultDTO result = (SearchFacetResultDTO) context.parseExpression(attributeValue);
    String key = facetService.getUrlKey(result);
    String value = facetService.getValue(result);
    String[] paramValues = params.get(key);
    if (ArrayUtils.contains(paramValues, facetService.getValue(result))) {
        paramValues = (String[]) ArrayUtils.removeElement(paramValues, facetService.getValue(result));
    } else {
        paramValues = (String[]) ArrayUtils.add(paramValues, value);
    }
    params.remove(SearchCriteria.PAGE_NUMBER);
    params.put(key, paramValues);
    String url = ProcessorUtils.getUrl(baseUrl, params);
    Map<String, String> newAttributes = new HashMap<>();
    newAttributes.put("href", url);
    return new BroadleafAttributeModifier(newAttributes);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HashMap(java.util.HashMap) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) BroadleafAttributeModifier(org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)

Example 2 with SearchFacetResultDTO

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

the class SolrSearchServiceImpl method filterEmptyFacets.

protected void filterEmptyFacets(List<SearchFacetDTO> facets) {
    Iterator<SearchFacetDTO> iter = facets.iterator();
    while (iter.hasNext()) {
        SearchFacetDTO dto = iter.next();
        boolean shouldRemove = true;
        for (SearchFacetResultDTO result : dto.getFacetValues()) {
            if (result.getQuantity() != null && result.getQuantity() > 0) {
                shouldRemove = false;
                break;
            }
        }
        if (shouldRemove) {
            iter.remove();
        }
    }
}
Also used : SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO)

Example 3 with SearchFacetResultDTO

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

the class DatabaseSearchServiceImpl method getMatchFacetValues.

protected List<SearchFacetResultDTO> getMatchFacetValues(SearchFacet facet) {
    List<SearchFacetResultDTO> results = new ArrayList<SearchFacetResultDTO>();
    String qualifiedFieldName = facet.getField().getQualifiedFieldName();
    qualifiedFieldName = getDatabaseQualifiedFieldName(qualifiedFieldName);
    List<String> values = searchFacetDao.readDistinctValuesForField(qualifiedFieldName, String.class);
    Collections.sort(values);
    for (String value : values) {
        SearchFacetResultDTO dto = new SearchFacetResultDTO();
        dto.setValue(value);
        dto.setFacet(facet);
        results.add(dto);
    }
    return results;
}
Also used : SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) ArrayList(java.util.ArrayList)

Example 4 with SearchFacetResultDTO

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

the class DatabaseSearchServiceImpl method getRangeFacetValues.

protected List<SearchFacetResultDTO> getRangeFacetValues(SearchFacet facet) {
    List<SearchFacetResultDTO> results = new ArrayList<SearchFacetResultDTO>();
    List<SearchFacetRange> ranges = facet.getSearchFacetRanges();
    Collections.sort(ranges, new Comparator<SearchFacetRange>() {

        @Override
        public int compare(SearchFacetRange o1, SearchFacetRange o2) {
            return o1.getMinValue().compareTo(o2.getMinValue());
        }
    });
    for (SearchFacetRange range : ranges) {
        SearchFacetResultDTO dto = new SearchFacetResultDTO();
        dto.setMinValue(range.getMinValue());
        dto.setMaxValue(range.getMaxValue());
        dto.setFacet(facet);
        results.add(dto);
    }
    return results;
}
Also used : SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) ArrayList(java.util.ArrayList)

Example 5 with SearchFacetResultDTO

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

the class SolrHelperServiceImpl method setFacetResults.

@Override
public void setFacetResults(Map<String, SearchFacetDTO> namedFacetMap, QueryResponse response) {
    if (response.getFacetFields() != null) {
        for (FacetField facet : response.getFacetFields()) {
            String facetFieldName = facet.getName();
            SearchFacetDTO facetDTO = namedFacetMap.get(facetFieldName);
            for (Count value : facet.getValues()) {
                SearchFacetResultDTO resultDTO = new SearchFacetResultDTO();
                resultDTO.setFacet(facetDTO.getFacet());
                resultDTO.setQuantity(new Long(value.getCount()).intValue());
                resultDTO.setValue(value.getName());
                facetDTO.getFacetValues().add(resultDTO);
            }
        }
    }
    if (response.getFacetQuery() != null) {
        for (Entry<String, Integer> entry : response.getFacetQuery().entrySet()) {
            String key = entry.getKey();
            String facetFieldName = key.substring(0, key.indexOf("["));
            SearchFacetDTO facetDTO = namedFacetMap.get(facetFieldName);
            String minValue = key.substring(key.indexOf("[") + 1, key.indexOf(":"));
            String maxValue = key.substring(key.indexOf(":") + 1, key.indexOf("]"));
            if (maxValue.equals("*")) {
                maxValue = null;
            }
            SearchFacetResultDTO resultDTO = new SearchFacetResultDTO();
            resultDTO.setFacet(facetDTO.getFacet());
            resultDTO.setQuantity(entry.getValue());
            resultDTO.setMinValue(new BigDecimal(minValue));
            resultDTO.setMaxValue(maxValue == null ? null : new BigDecimal(maxValue));
            facetDTO.getFacetValues().add(resultDTO);
        }
    }
    searchExtensionManager.getProxy().setFacetResults(namedFacetMap, response);
}
Also used : SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) FacetField(org.apache.solr.client.solrj.response.FacetField) Count(org.apache.solr.client.solrj.response.FacetField.Count) BigDecimal(java.math.BigDecimal)

Aggregations

SearchFacetResultDTO (org.broadleafcommerce.core.search.domain.SearchFacetResultDTO)5 ArrayList (java.util.ArrayList)2 SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 FacetField (org.apache.solr.client.solrj.response.FacetField)1 Count (org.apache.solr.client.solrj.response.FacetField.Count)1 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)1 SearchFacetRange (org.broadleafcommerce.core.search.domain.SearchFacetRange)1 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)1