* @param document
*/
protected void attachBasicDocumentFields(Product product, SolrInputDocument document) {
boolean cacheOperationManaged = false;
try {
CatalogStructure cache = SolrIndexCachedOperation.getCache();
if (cache != null) {
cacheOperationManaged = true;
} else {
cache = new CatalogStructure();
SolrIndexCachedOperation.setCache(cache);
solrIndexDao.populateCatalogStructure(Arrays.asList(product.getId()), SolrIndexCachedOperation.getCache());
}
// Add the namespace and ID fields for this product
document.addField(shs.getNamespaceFieldName(), shs.getCurrentNamespace());
document.addField(shs.getIdFieldName(), shs.getSolrDocumentId(document, product));
document.addField(shs.getProductIdFieldName(), product.getId());
extensionManager.getProxy().attachAdditionalBasicFields(product, document, shs);
// The explicit categories are the ones defined by the product itself
if (cache.getParentCategoriesByProduct().containsKey(product.getId())) {
for (Long categoryId : cache.getParentCategoriesByProduct().get(product.getId())) {
document.addField(shs.getExplicitCategoryFieldName(), shs.getCategoryId(categoryId));
String categorySortFieldName = shs.getCategorySortFieldName(shs.getCategoryId(categoryId));
String displayOrderKey = categoryId + "-" + shs.getProductId(product.getId());
BigDecimal displayOrder = cache.getDisplayOrdersByCategoryProduct().get(displayOrderKey);
if (displayOrder == null) {
displayOrderKey = categoryId + "-" + product.getId();
displayOrder = cache.getDisplayOrdersByCategoryProduct().get(displayOrderKey);
}
if (document.getField(categorySortFieldName) == null) {
document.addField(categorySortFieldName, displayOrder);
}