Class AbstractDocumentBuilder<T>
java.lang.Object
com.broadleafcommerce.search.index.core.document.AbstractDocumentBuilder<T>
- Type Parameters:
T- The type of document to build
- All Implemented Interfaces:
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDocumentBuilder(IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFieldService, ProcessStateService processStateService, List<DocumentBuilderContributor<T>> contributors, List<DocumentBuilderPreProcessor> preProcessors) AbstractDocumentBuilder(IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFieldService, ProcessStateService processStateService, List<DocumentBuilderContributor<T>> contributors, List<DocumentBuilderPreProcessor> preProcessors, com.jayway.jsonpath.Configuration jsonPathConfiguration, int localFieldDefCacheSize) -
Method Summary
Modifier and TypeMethodDescriptionbuildDocuments(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables) Build documents to be indexed by the search engine.protected abstract StringbuildId(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.protected abstract TcreateDocument(com.broadleafcommerce.search.api.domain.Indexable<?> indexable) Creates a new document.protected voidexecuteContributors(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) Execute all of the definedDocumentBuilderContributorson the indexable.protected voidexecutePreProcessors(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables) Execute all of the definedDocumentBuilderPreProcessorson the indexables together.protected List<DocumentBuilderContributor<T>>getContributorsForIndexableType(com.broadleafcommerce.search.api.type.IndexableType indexableType) protected List<DocumentBuilderContributor<T>>protected com.jayway.jsonpath.Configurationprotected Map<com.broadleafcommerce.search.api.type.IndexableType,List<DocumentBuilderContributor<T>>> If any contributors have been defined for a specificIndexableTypevia anIndexableTypeDocumentBuilderContributor, then the contributors listed here will be used instead ofdefaultContributors.protected com.jayway.jsonpath.Configurationprotected intThe maximum size of theLRUMapthat is used for local cachingFieldDefinitionsduring reindexing.protected List<DocumentBuilderPreProcessor>protected ProcessStateServiceprotected IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition>protected abstract voidpopulateDocument(com.broadleafcommerce.search.api.domain.Indexable<?> indexable, T document, List<com.broadleafcommerce.search.api.domain.FieldDefinition> fields, com.jayway.jsonpath.DocumentContext context) Populate the document for the indexable with the given fields.protected List<com.broadleafcommerce.search.api.domain.FieldDefinition>readFieldsForIndexable(com.broadleafcommerce.search.api.domain.Indexable<?> indexable) This adds a layer of primary caching toFieldDefinitionswhile full reindexing is occurring.protected booleanshouldIndex(com.broadleafcommerce.search.api.domain.Indexable<?> indexable) Check whether a document should be indexed for this indexable.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.search.index.core.document.DocumentBuilder
buildDocuments
-
Field Details
-
LOCAL_FIELD_DEFINITION_CACHE_NAME
- See Also:
-
-
Constructor Details
-
AbstractDocumentBuilder
public AbstractDocumentBuilder(IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFieldService, ProcessStateService processStateService, @Nullable List<DocumentBuilderContributor<T>> contributors, @Nullable List<DocumentBuilderPreProcessor> preProcessors) -
AbstractDocumentBuilder
public AbstractDocumentBuilder(IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> searchFieldService, ProcessStateService processStateService, @Nullable List<DocumentBuilderContributor<T>> contributors, @Nullable List<DocumentBuilderPreProcessor> preProcessors, @Nullable com.jayway.jsonpath.Configuration jsonPathConfiguration, int localFieldDefCacheSize)
-
-
Method Details
-
buildDocuments
public List<T> buildDocuments(List<? extends com.broadleafcommerce.search.api.domain.Indexable<?>> indexables) throws com.broadleafcommerce.search.api.SearchIndexException Description copied from interface:DocumentBuilderBuild documents to be indexed by the search engine. If the indexable has any trackable behavior, then the parameterindexablesshould include all objects sharing the same ID.- Specified by:
buildDocumentsin interfaceDocumentBuilder<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 definedDocumentBuilderPreProcessorson 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
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
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 documentdocument- The document to be populated with datafields- The fields to be populatedcontext- 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 definedDocumentBuilderContributorson the indexable.- Parameters:
contributors- the contributors which should modify this indexable objectindexable- indexable object used to create documentdocument- document created from indexable objectcontext- the context object derived from the indexablefields- fields which belong to the indexable'sIndexableType- 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.
-
readFieldsForIndexable
protected List<com.broadleafcommerce.search.api.domain.FieldDefinition> readFieldsForIndexable(com.broadleafcommerce.search.api.domain.Indexable<?> indexable) This adds a layer of primary caching toFieldDefinitionswhile full reindexing is occurring. The cached items are stored in aLRUMapto prevent unbounded growth. The key of this Map is the tenant ID. Since this caches the results on heap for immediate use by other threads that might need the values, this can be more efficient and avoid instantiating objects unnecessarily which helps with GC. We still rely on and fall back to more formal caching methods as well, but this is a more local cache, to be used by multiple reindex threads, each trying to index a particularIndexableType, specifically for a given tenant.- Parameters:
indexable-- Returns:
-
getProcessStateService
-
getSearchFieldService
protected IndexerSearchService<com.broadleafcommerce.search.api.domain.FieldDefinition> getSearchFieldService() -
getDefaultContributors
-
getLocalFieldDefCacheSize
protected int getLocalFieldDefCacheSize()The maximum size of theLRUMapthat is used for local cachingFieldDefinitionsduring reindexing. This value must be greater than 0 and should be greater than the number of worker threads. If the value is less than 1 then the localized cache will be disabled. The default value is 100, meaning that the Field Definitions for 100 tenants can be cached at the same time for a givenIndexableType. -
getIndexableTypeContributors
protected Map<com.broadleafcommerce.search.api.type.IndexableType,List<DocumentBuilderContributor<T>>> getIndexableTypeContributors()If any contributors have been defined for a specificIndexableTypevia anIndexableTypeDocumentBuilderContributor, then the contributors listed here will be used instead ofdefaultContributors.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.
-
getPreProcessors
-
getJsonPathConfiguration
protected com.jayway.jsonpath.Configuration getJsonPathConfiguration()
-