Class AbstractDocumentBuilder<T>

  • Type Parameters:
    T - The type of document to build
    All Implemented Interfaces:
    DocumentBuilder<T>

    public abstract class AbstractDocumentBuilder<T>
    extends Object
    implements DocumentBuilder<T>
    Builds documents from indexables based on FieldDefinitions for their IndexableType.

    Executes DocumentBuilderPreProcessors on the indexables prior to creating documents, and skips archived indexables by default. After documents are created, DocumentBuilderContributors are executed on them to add any additional information.

    • Method Detail

      • buildDocuments

        public List<T> buildDocuments​(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables)
                               throws com.broadleafcommerce.search.api.SearchIndexException
        Description copied from interface: DocumentBuilder
        Build documents to be indexed by the search engine. If the indexable has any trackable behavior, then the parameter indexables should include all objects sharing the same ID.
        Specified by:
        buildDocuments in interface DocumentBuilder<T>
        Parameters:
        indexables - The indexables to be converted into documents.
        Returns:
        The documents to index, including IDs of any documents to be deleted from the index.
        Throws:
        com.broadleafcommerce.search.api.SearchIndexException - if an error occurs preventing indexing
      • executePreProcessors

        protected void executePreProcessors​(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables)
        Execute all of the defined DocumentBuilderPreProcessors on the indexables together.
        Parameters:
        indexables - indexable objects to be pre-processed together
      • getContributorsForIndexableType

        protected List<DocumentBuilderContributor<T>> getContributorsForIndexableType​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
      • shouldIndex

        protected boolean shouldIndex​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
        Check whether a document should be indexed for this indexable.
        Parameters:
        indexable - The indexable to check
        Returns:
        Whether or not a document should be indexed. If it should not be indexed, this generally means it should be deleted from the index.
      • buildId

        protected abstract String buildId​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
        Build an ID value which routes documents based on context ID and is a unique representation of its context.

        Indexables with the same context ID, catalog, sandbox, and sandbox owner context should produce the same ID.

        Parameters:
        indexable - The indexable to create an ID for
        Returns:
        an ID unique by indexable context id, catalog, sandbox, and sandbox owner
      • createDocument

        protected abstract T createDocument​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable)
        Creates a new document.
        Parameters:
        indexable - The indexable to create a document for
        Returns:
        new document
      • populateDocument

        protected abstract void populateDocument​(com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                                 T document,
                                                 List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields,
                                                 com.jayway.jsonpath.DocumentContext context)
                                          throws com.broadleafcommerce.search.api.SearchIndexException
        Populate the document for the indexable with the given fields.
        Parameters:
        indexable - The indexable with data to populate into the document
        document - The document to be populated with data
        fields - The fields to be populated
        context - The document context for the indexable's JSON map
        Throws:
        com.broadleafcommerce.search.api.SearchIndexException
      • executeContributors

        protected void executeContributors​(List<DocumentBuilderContributor<T>> contributors,
                                           com.broadleafcommerce.search.api.domain.Indexable<?> indexable,
                                           T document,
                                           com.jayway.jsonpath.DocumentContext context,
                                           List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields)
                                    throws com.broadleafcommerce.search.api.SearchIndexException
        Execute all of the defined DocumentBuilderContributors on the indexable.
        Parameters:
        contributors - the contributors which should modify this indexable object
        indexable - indexable object used to create document
        document - document created from indexable object
        context - the context object derived from the indexable
        fields - fields which belong to the indexable's IndexableType
        Throws:
        com.broadleafcommerce.search.api.SearchIndexException - if a contributor encounters an error preventing indexing
      • getDefaultJsonPathConfiguration

        protected com.jayway.jsonpath.Configuration getDefaultJsonPathConfiguration()
        Returns:
        The default JsonPath configuration.
      • getSearchFieldService

        protected IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> getSearchFieldService()
      • getIndexableTypeContributors

        protected Map<com.broadleafcommerce.search.api.type.IndexableType,​List<DocumentBuilderContributor<T>>> getIndexableTypeContributors()
        If any contributors have been defined for a specific IndexableType via an IndexableTypeDocumentBuilderContributor, then the contributors listed here will be used instead of defaultContributors.

        For such an indexable type, this will contain the indexable-type-specific contributors in addition to the default contributors, excluding those which were extended by the indexable-type-specific contributors.

      • getJsonPathConfiguration

        protected com.jayway.jsonpath.Configuration getJsonPathConfiguration()