Class ProductOptionSolrDocumentBuilder

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

    public class ProductOptionSolrDocumentBuilder
    extends com.broadleafcommerce.search.index.solr.document.DefaultSolrDocumentBuilder
    If a product is designated as search on option (see ProductOptionUtil.isSearchOnOption(DocumentContext)), this class handles building out product option documents to be indexed.

    • Constructor Summary

      Constructors 
      Constructor Description
      ProductOptionSolrDocumentBuilder​(com.broadleafcommerce.search.index.core.service.IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFieldService, List<com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>> contributors, List<com.broadleafcommerce.search.index.core.document.DocumentBuilderPreProcessor> preProcessors, com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService, com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper documentBuilderHelper, com.fasterxml.jackson.databind.ObjectMapper objectMapper)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addProductOptionFields​(org.apache.solr.common.SolrInputDocument document, com.jayway.jsonpath.DocumentContext context, String productOptionName, String productOptionValue)
      Add the option name, label, and value as indexed values.
      List<org.apache.solr.common.SolrInputDocument> buildDocuments​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)  
      List<org.apache.solr.common.SolrInputDocument> buildDocuments​(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables)  
      protected String buildProductOptionId​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, String productOptionName, String productOptionValue)
      Returns a unique ID for a searchable product option.
      protected Map<String,​Object> copyMap​(Map<String,​Object> jsonMap)
      Create a copy of the product's JSON map.
      protected List<org.apache.commons.lang3.tuple.Pair<org.apache.solr.common.SolrInputDocument,​com.jayway.jsonpath.DocumentContext>> createOptionDocuments​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, com.jayway.jsonpath.DocumentContext context)
      Creates a list of Pair objects.
      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()  
      protected List<String> getOptionValues​(com.jayway.jsonpath.DocumentContext context, String productOptionName, String contextId)
      Return a list of option values for a searchable option.
      protected List<String> getProductOptionAttributeNames​(com.jayway.jsonpath.DocumentContext context, String contextId)
      Return a list of attribute names that are available as searchable options.
      protected com.jayway.jsonpath.DocumentContext removeUnusedOptions​(com.jayway.jsonpath.DocumentContext optionContext, String productOptionAttrName, String productOptionValue)
      Removes options that are not applicable to the product option that is going to be indexed.
      • Methods inherited from class com.broadleafcommerce.search.index.solr.document.DefaultSolrDocumentBuilder

        buildId, createDocument, getCatalogId, getDocumentBuilderHelper, getSolrFieldService, idMapEntryToString, isEmptyOrNull, populateDocument
      • Methods inherited from class com.broadleafcommerce.search.index.core.document.AbstractDocumentBuilder

        executeContributors, executePreProcessors, getContributorsForIndexableType, getDefaultContributors, getDefaultJsonPathConfiguration, getIndexableTypeContributors, getJsonPathConfiguration, getPreProcessors, getSearchFieldService, shouldIndex
    • Constructor Detail

      • ProductOptionSolrDocumentBuilder

        public ProductOptionSolrDocumentBuilder​(com.broadleafcommerce.search.index.core.service.IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFieldService,
                                                List<com.broadleafcommerce.search.index.core.document.DocumentBuilderContributor<org.apache.solr.common.SolrInputDocument>> contributors,
                                                List<com.broadleafcommerce.search.index.core.document.DocumentBuilderPreProcessor> preProcessors,
                                                com.broadleafcommerce.search.provider.solr.SolrFieldService solrFieldService,
                                                com.broadleafcommerce.search.index.core.document.helper.DocumentBuilderHelper documentBuilderHelper,
                                                com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • Method Detail

      • buildDocuments

        public List<org.apache.solr.common.SolrInputDocument> buildDocuments​(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables)
                                                                      throws com.broadleafcommerce.search.api.SearchIndexException
        Specified by:
        buildDocuments in interface com.broadleafcommerce.search.index.core.document.DocumentBuilder<org.apache.solr.common.SolrInputDocument>
        Overrides:
        buildDocuments in class com.broadleafcommerce.search.index.core.document.AbstractDocumentBuilder<org.apache.solr.common.SolrInputDocument>
        Throws:
        com.broadleafcommerce.search.api.SearchIndexException
      • buildDocuments

        public List<org.apache.solr.common.SolrInputDocument> buildDocuments​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
      • createOptionDocuments

        protected List<org.apache.commons.lang3.tuple.Pair<org.apache.solr.common.SolrInputDocument,​com.jayway.jsonpath.DocumentContext>> createOptionDocuments​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                                                                                                                                                      com.jayway.jsonpath.DocumentContext context)
        Creates a list of Pair objects. The left side of the pair is the Solr input document for one of the searchable product options, and the right is the DocumentContext for that document. The pairs returned from this method can then be used in the regular document index flow.
        Parameters:
        indexable - The indexable to retrieve option documents for.
        context - The original document context.
        Returns:
        A list of pairs.
      • copyMap

        protected Map<String,​Object> copyMap​(Map<String,​Object> jsonMap)
        Create a copy of the product's JSON map. This is necessary because we need to modify each input document, and the reindex flow may potentially modify each document context, so we can't share a document context across all product options.
        Parameters:
        jsonMap - The product's JSON map. See Product.getJsonMap()
        Returns:
        A deep copy of Product.getJsonMap()
      • removeUnusedOptions

        protected com.jayway.jsonpath.DocumentContext removeUnusedOptions​(com.jayway.jsonpath.DocumentContext optionContext,
                                                                          String productOptionAttrName,
                                                                          String productOptionValue)
        Removes options that are not applicable to the product option that is going to be indexed. For instance, if the options are the colors red, black, and blue and this product option is for the color red, then the black and blue options will be removed from the document context
        Parameters:
        optionContext - The document context for this product option.
        productOptionAttrName - The product option name
        productOptionValue - The product option value
      • addProductOptionFields

        protected void addProductOptionFields​(org.apache.solr.common.SolrInputDocument document,
                                              com.jayway.jsonpath.DocumentContext context,
                                              String productOptionName,
                                              String productOptionValue)
        Add the option name, label, and value as indexed values.
        Parameters:
        document -
        productOptionName -
        productOptionValue -
      • getOptionValues

        protected List<String> getOptionValues​(com.jayway.jsonpath.DocumentContext context,
                                               String productOptionName,
                                               @Nullable
                                               String contextId)
        Return a list of option values for a searchable option. For example, if the searchable option is Color, and the color options are red, blue, and black, then those values will be returned. Note that this will return the _value_ of the option, not the label.
        Parameters:
        context -
        productOptionName -
        contextId -
        Returns:
      • getProductOptionAttributeNames

        protected List<String> getProductOptionAttributeNames​(com.jayway.jsonpath.DocumentContext context,
                                                              @Nullable
                                                              String contextId)
        Return a list of attribute names that are available as searchable options. For example, if we have a T-Shirt, and we tag 'Color' and 'Size' as searchable options, this will return a list including 'Color' and 'Size'.
        Parameters:
        context - The document context.
        contextId - The product context ID, used for debug logging. Optional.
        Returns:
        A list of searchable product options.
      • buildProductOptionId

        protected String buildProductOptionId​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                              String productOptionName,
                                              String productOptionValue)
        Returns a unique ID for a searchable product option.
        Parameters:
        indexable - The indexable
        productOptionName - The product option name, e.g. 'Color'
        productOptionValue - The product option value, e.g. 'Red'
        Returns:
        a unique ID for a product option.
      • getObjectMapper

        protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()