Class CategoryProductSortSolrDocumentContributor

  • All Implemented Interfaces:
    com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>

    public class CategoryProductSortSolrDocumentContributor
    extends Object
    implements com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
    Component to pull Category / Product references off of the source data and index the category ID along with a sorting value.
    Author:
    Kelly Tisdell (ktisdell)
    • Constructor Detail

      • CategoryProductSortSolrDocumentContributor

        public CategoryProductSortSolrDocumentContributor()
    • Method Detail

      • contributeInternal

        public void contributeInternal​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                       org.apache.solr.common.SolrInputDocument document,
                                       com.jayway.jsonpath.DocumentContext jsonContext,
                                       List<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFields)
                                throws com.broadleafcommerce.search.api.SearchIndexException
        Specified by:
        contributeInternal in interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
        Throws:
        com.broadleafcommerce.search.api.SearchIndexException
      • canHandle

        public boolean canHandle​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
        Specified by:
        canHandle in interface com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>
      • getUnsortedValue

        protected String getUnsortedValue()
        Returns the unsorted value. By default, this is 'z'. The result MUST NOT be null.
        Returns:
        the unsorted value
      • parseSortingMap

        protected Map<String,​String> parseSortingMap​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                                           com.jayway.jsonpath.DocumentContext jsonContext)
        Attempts to parse the category sorting map from the JSON field, $.productSortingWithinCategories. If an exception occurs here we log it and simply return an empty map. This default behavior allows us to avoid holding up indexing, continuing to build the document without proper sorting capabilities.
        Parameters:
        indexable - the Product to be indexed.
        jsonContext - the JSON context from which to parse the map.
        Returns:
        a Map with category ID as the key and a lexicographical sort value as the value.