Search in sources :

Example 1 with SearchFacetRange

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;
}
Also used : SearchFacetResultDTO(org.broadleafcommerce.core.search.domain.SearchFacetResultDTO) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) ArrayList(java.util.ArrayList)

Example 2 with SearchFacetRange

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));
            }
        }
    }
}
Also used : SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 3 with SearchFacetRange

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);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 4 with SearchFacetRange

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;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)

Example 5 with SearchFacetRange

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<>();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchFacetRangeImpl(org.broadleafcommerce.core.search.domain.SearchFacetRangeImpl) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) NoResultException(javax.persistence.NoResultException) Predicate(javax.persistence.criteria.Predicate)

Aggregations

SearchFacetRange (org.broadleafcommerce.core.search.domain.SearchFacetRange)5 ArrayList (java.util.ArrayList)1 NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 Status (org.broadleafcommerce.common.persistence.Status)1 SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)1 SearchFacetRangeImpl (org.broadleafcommerce.core.search.domain.SearchFacetRangeImpl)1 SearchFacetResultDTO (org.broadleafcommerce.core.search.domain.SearchFacetResultDTO)1 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)1 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)1