Search in sources :

Example 1 with SearchFacetImpl

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

use of org.broadleafcommerce.core.search.domain.SearchFacetImpl 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)

Aggregations

CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 SearchFacet (org.broadleafcommerce.core.search.domain.SearchFacet)2 SearchFacetImpl (org.broadleafcommerce.core.search.domain.SearchFacetImpl)2 NoResultException (javax.persistence.NoResultException)1