Search in sources :

Example 1 with CatalogStructure

use of org.broadleafcommerce.core.search.dao.CatalogStructure in project BroadleafCommerce by BroadleafCommerce.

the class SolrIndexCachedOperation method setCache.

/**
 * Set the cache on the current thread
 *
 * @param cache the cache object (usually an empty map)
 */
public static void setCache(CatalogStructure cache) {
    BroadleafRequestContext ctx = BroadleafRequestContext.getBroadleafRequestContext();
    Catalog currentCatalog = ctx == null ? null : ctx.getCurrentCatalog();
    Map<Long, CatalogStructure> catalogCaches = CACHE.get();
    if (catalogCaches == null) {
        catalogCaches = new HashMap<Long, CatalogStructure>();
        CACHE.set(catalogCaches);
    }
    if (currentCatalog != null) {
        catalogCaches.put(currentCatalog.getId(), cache);
    } else {
        catalogCaches.put(DEFAULT_CATALOG_CACHE_KEY, cache);
    }
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) CatalogStructure(org.broadleafcommerce.core.search.dao.CatalogStructure) Catalog(org.broadleafcommerce.common.site.domain.Catalog)

Example 2 with CatalogStructure

use of org.broadleafcommerce.core.search.dao.CatalogStructure in project BroadleafCommerce by BroadleafCommerce.

the class SolrIndexServiceImpl method attachBasicDocumentFields.

protected void attachBasicDocumentFields(Indexable indexable, SolrInputDocument document) {
    CatalogStructure cache = SolrIndexCachedOperation.getCache();
    if (cache == null) {
        String msg = "SolrIndexService.performCachedOperation() must be used in conjuction with" + " solrIndexDao.populateProductCatalogStructure() in order to correctly build catalog documents or should" + " be invoked from buildIncrementalIndex()";
        LOG.error(msg);
        throw new IllegalStateException(msg);
    }
    // Add the namespace and ID fields for this product
    document.addField(shs.getNamespaceFieldName(), solrConfiguration.getNamespace());
    document.addField(shs.getIdFieldName(), shs.getSolrDocumentId(document, indexable));
    document.addField(shs.getTypeFieldName(), shs.getDocumentType(indexable));
    document.addField(shs.getIndexableIdFieldName(), shs.getIndexableId(indexable));
    extensionManager.getProxy().attachAdditionalBasicFields(indexable, document, shs);
    // current
    Long cacheKey = this.shs.getCurrentProductId(indexable);
    if (!cache.getParentCategoriesByProduct().containsKey(cacheKey)) {
        // parent
        cacheKey = sandBoxHelper.getOriginalId(cacheKey);
        if (!cache.getParentCategoriesByProduct().containsKey(cacheKey)) {
            // master
            cacheKey = shs.getIndexableId(indexable);
        }
    }
    // The explicit categories are the ones defined by the product itself
    if (cache.getParentCategoriesByProduct().containsKey(cacheKey)) {
        for (Long categoryId : cache.getParentCategoriesByProduct().get(cacheKey)) {
            document.addField(shs.getExplicitCategoryFieldName(), shs.getCategoryId(categoryId));
            // Make sure that we're always referencing the parent for the sort field
            String categorySortFieldName = shs.getCategorySortFieldName(shs.getCategoryId(categoryId));
            // The issue here was the super category id is always what is stored in the cache, while the category
            // by product id is the overridden versions. Need to always look at parent version for cache stuff, which
            // is given from shs.getCategoryId
            // First try the current level
            String displayOrderKey = categoryId + "-" + cacheKey;
            Long displayOrder = convertDisplayOrderToLong(cache, displayOrderKey);
            if (displayOrder == null) {
                // Didn't find the cache at the current level, this might be an override so look upwards
                displayOrderKey = shs.getCategoryId(categoryId) + "-" + cacheKey;
                displayOrder = convertDisplayOrderToLong(cache, displayOrderKey);
            }
            if (document.getField(categorySortFieldName) == null && displayOrder != null) {
                document.addField(categorySortFieldName, displayOrder);
            }
            // This is the entire tree of every category defined on the product
            buildFullCategoryHierarchy(document, cache, categoryId, new HashSet<Long>());
        }
    }
}
Also used : CatalogStructure(org.broadleafcommerce.core.search.dao.CatalogStructure)

Example 3 with CatalogStructure

use of org.broadleafcommerce.core.search.dao.CatalogStructure in project BroadleafCommerce by BroadleafCommerce.

the class SolrIndexServiceImpl method performCachedOperation.

@Override
public void performCachedOperation(SolrIndexCachedOperation.CacheOperation cacheOperation) throws ServiceException {
    try {
        CatalogStructure cache = new CatalogStructure();
        SolrIndexCachedOperation.setCache(cache);
        cacheOperation.execute();
    } finally {
        SolrIndexCachedOperation.clearCache();
    }
}
Also used : CatalogStructure(org.broadleafcommerce.core.search.dao.CatalogStructure)

Aggregations

CatalogStructure (org.broadleafcommerce.core.search.dao.CatalogStructure)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)1 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)1