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);
}
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();
}
}
}
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;
}
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;
}
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);
}
Aggregations