use of org.broadleafcommerce.core.search.domain.SearchFacetRange 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.SearchFacetRange in project BroadleafCommerce by BroadleafCommerce.
the class SolrHelperServiceImpl method attachFacets.
@Override
public void attachFacets(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) {
query.setFacet(true);
for (Entry<String, SearchFacetDTO> entry : namedFacetMap.entrySet()) {
SearchFacetDTO dto = entry.getValue();
ExtensionResultStatusType status = searchExtensionManager.getProxy().attachFacet(query, entry.getKey(), dto, searchCriteria);
if (ExtensionResultStatusType.NOT_HANDLED.equals(status)) {
List<SearchFacetRange> facetRanges = searchFacetDao.readSearchFacetRangesForSearchFacet(dto.getFacet());
if (searchExtensionManager != null) {
searchExtensionManager.getProxy().filterSearchFacetRanges(dto, facetRanges);
}
if (CollectionUtils.isNotEmpty(facetRanges)) {
for (SearchFacetRange range : facetRanges) {
query.addFacetQuery(getSolrTaggedFieldString(entry.getKey(), "key", range));
}
} else {
query.addFacetField(getSolrTaggedFieldString(entry.getKey(), "ex", null));
}
}
}
}
use of org.broadleafcommerce.core.search.domain.SearchFacetRange in project BroadleafCommerce by BroadleafCommerce.
the class SearchFacetRangeCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
SearchFacetRange adminInstance = getAdminInstance(persistencePackage, dynamicEntityDao, helper, entity);
if (Status.class.isAssignableFrom(adminInstance.getClass())) {
((Status) adminInstance).setArchived('Y');
dynamicEntityDao.merge(adminInstance);
}
} catch (Exception e) {
throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.core.search.domain.SearchFacetRange in project BroadleafCommerce by BroadleafCommerce.
the class SearchFacetRangeCustomPersistenceHandler method getAdminInstance.
protected SearchFacetRange getAdminInstance(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity) throws ClassNotFoundException {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(SearchFacetRange.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
String type = entity.getType()[0];
SearchFacetRange adminInstance = (SearchFacetRange) dynamicEntityDao.retrieve(Class.forName(type), primaryKey);
return adminInstance;
}
use of org.broadleafcommerce.core.search.domain.SearchFacetRange in project BroadleafCommerce by BroadleafCommerce.
the class SearchFacetDaoImpl method readSearchFacetRangesForSearchFacet.
@Override
public List<SearchFacetRange> readSearchFacetRangesForSearchFacet(SearchFacet searchFacet) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<SearchFacetRange> criteria = builder.createQuery(SearchFacetRange.class);
Root<SearchFacetRangeImpl> ranges = criteria.from(SearchFacetRangeImpl.class);
criteria.select(ranges);
Predicate facetRestriction = builder.equal(ranges.get("searchFacet"), searchFacet);
// if it hadn't
if (ArchiveStatus.class.isAssignableFrom(SearchFacetRangeImpl.class)) {
criteria.where(builder.and(facetRestriction, builder.or(builder.isNull(ranges.get("archiveStatus").get("archived").as(String.class)), builder.notEqual(ranges.get("archiveStatus").get("archived").as(Character.class), 'Y'))));
} else {
criteria.where(facetRestriction);
}
TypedQuery<SearchFacetRange> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
try {
return query.getResultList();
} catch (NoResultException e) {
return new ArrayList<>();
}
}
Aggregations