Search in sources :

Example 6 with SearchFacet

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

the class DatabaseSearchServiceImpl method buildSearchFacetDtos.

/**
 * Create the wrapper DTO around the SearchFacet
 * @param categoryFacets
 * @return the wrapper DTO
 */
protected List<SearchFacetDTO> buildSearchFacetDtos(List<SearchFacet> categoryFacets) {
    List<SearchFacetDTO> facets = new ArrayList<SearchFacetDTO>();
    for (SearchFacet facet : categoryFacets) {
        SearchFacetDTO dto = new SearchFacetDTO();
        dto.setFacet(facet);
        dto.setShowQuantity(false);
        dto.setFacetValues(getFacetValues(facet));
        dto.setActive(false);
        facets.add(dto);
    }
    return facets;
}
Also used : SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ArrayList(java.util.ArrayList)

Example 7 with SearchFacet

use of org.broadleafcommerce.core.search.domain.SearchFacet 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 8 with SearchFacet

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

the class SearchFacetDaoImpl method readAllSearchFacets.

@Override
public List<SearchFacet> readAllSearchFacets(FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<SearchFacet> criteria = builder.createQuery(SearchFacet.class);
    Root<SearchFacetImpl> facet = criteria.from(SearchFacetImpl.class);
    criteria.select(facet);
    criteria.where(builder.equal(facet.get("showOnSearch").as(Boolean.class), true), facet.join("fieldType").join("indexField").join("field").get("entityType").as(String.class).in(entityType.getAllLookupTypes()));
    TypedQuery<SearchFacet> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) SearchFacetImpl(org.broadleafcommerce.core.search.domain.SearchFacetImpl)

Example 9 with SearchFacet

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

the class SearchFacetDaoImpl method readSearchFacetForField.

@Override
public SearchFacet readSearchFacetForField(Field field) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<SearchFacet> criteria = builder.createQuery(SearchFacet.class);
    Root<SearchFacetImpl> facet = criteria.from(SearchFacetImpl.class);
    criteria.select(facet);
    criteria.where(builder.equal(facet.join("fieldType").join("indexField").join("field").get("id").as(Long.class), field.getId()));
    TypedQuery<SearchFacet> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    try {
        return query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) SearchFacetImpl(org.broadleafcommerce.core.search.domain.SearchFacetImpl) NoResultException(javax.persistence.NoResultException)

Example 10 with SearchFacet

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

the class SolrSearchServiceImpl method getCategoryFacets.

@Override
public List<SearchFacetDTO> getCategoryFacets(Category category) {
    List<SearchFacet> searchFacets = new ArrayList<>();
    ExtensionResultStatusType status = extensionManager.getProxy().getCategorySearchFacets(category, searchFacets);
    if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, status)) {
        List<CategorySearchFacet> categorySearchFacets = category.getCumulativeSearchFacets();
        for (CategorySearchFacet categorySearchFacet : categorySearchFacets) {
            searchFacets.add(categorySearchFacet.getSearchFacet());
        }
    }
    return buildSearchFacetDTOs(searchFacets);
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Aggregations

SearchFacet (org.broadleafcommerce.core.search.domain.SearchFacet)10 ArrayList (java.util.ArrayList)6 CategorySearchFacet (org.broadleafcommerce.core.search.domain.CategorySearchFacet)5 SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 SearchFacetImpl (org.broadleafcommerce.core.search.domain.SearchFacetImpl)2 NoResultException (javax.persistence.NoResultException)1 Element (net.sf.ehcache.Element)1 Predicate (org.apache.commons.collections.Predicate)1 Transformer (org.apache.commons.collections.Transformer)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 Status (org.broadleafcommerce.common.persistence.Status)1 CategoryExcludedSearchFacet (org.broadleafcommerce.core.search.domain.CategoryExcludedSearchFacet)1 SearchFacetRange (org.broadleafcommerce.core.search.domain.SearchFacetRange)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)1 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)1