Class AbstractSearchIndexingProcessor
- java.lang.Object
-
- org.craftercms.deployer.impl.processors.AbstractDeploymentProcessor
-
- org.craftercms.deployer.impl.processors.AbstractMainDeploymentProcessor
-
- org.craftercms.deployer.impl.processors.AbstractSearchIndexingProcessor
-
- All Implemented Interfaces:
DeploymentProcessor
,InitializableByConfigBean
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
- Direct Known Subclasses:
ElasticsearchIndexingProcessor
public abstract class AbstractSearchIndexingProcessor extends AbstractMainDeploymentProcessor
Processor that indexes the files on the change set, using one or severalBatchIndexer
. After the files have been indexed it submits a commit. A processor instance can be configured with the following YAML properties:- ignoreIndexId: If the index ID should be ignored, in other words, if the index ID should always be null on update calls.
- indexId: The specific index ID to use
- reindexItemsOnComponentUpdates: Flag that indicates that if a component is updated, all other pages and components that include it should be updated too. This needs to be done when flattening is enabled, since the component needs to be re-included in pages/components. By default is true.
- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description protected List<org.craftercms.search.batch.BatchIndexer>
batchIndexers
protected org.craftercms.core.util.cache.CacheTemplate
cacheTemplate
protected Pattern
componentPathPattern
protected org.craftercms.core.service.ContentStoreService
contentStoreService
protected org.springframework.beans.factory.ObjectFactory<org.craftercms.core.service.Context>
contextFactory
protected static String
CREATE_INDEX_IF_MISSING_CONFIG_KEY
protected boolean
createIndexIfMissing
protected static Pattern
DEFAULT_COMPONENT_PATH_PATTERN
protected static Pattern
DEFAULT_DESCRIPTOR_PATH_PATTERN
protected static int
DEFAULT_ITEMS_THAT_INCLUDE_COMPONENT_QUERY_ROWS
protected Pattern
descriptorPathPattern
protected static String
IGNORE_INDEX_ID_CONFIG_KEY
protected static String
INDEX_ID_CONFIG_KEY
protected String
indexId
protected String
indexIdFormat
protected int
itemsThatIncludeComponentQueryRows
protected static String
REINDEX_ITEMS_ON_COMPONENT_UPDATES
protected boolean
reindexItemsOnComponentUpdates
protected boolean
xmlFlatteningEnabled
-
Fields inherited from class org.craftercms.deployer.impl.processors.AbstractMainDeploymentProcessor
FAIL_DEPLOYMENT_CONFIG_KEY, failDeploymentOnFailure
-
Fields inherited from class org.craftercms.deployer.impl.processors.AbstractDeploymentProcessor
alwaysRun, env, excludeFiles, includeFiles, JUMPING_TO_PARAM_NAME, jumpTo, label, name, siteName, targetId
-
-
Constructor Summary
Constructors Constructor Description AbstractSearchIndexingProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addAffectedItemsToUpdatedFiles(String path, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles, BiFunction<String,String,List<String>> function)
protected void
addItemsThatIncludeComponentToUpdatedFiles(String componentPath, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles)
protected void
addItemsThatInheritFromDescriptorToUpdatedFiles(String descriptorPath, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles)
protected abstract void
doCommit(String indexId)
protected abstract void
doCreateIndexIfMissing(Target target)
protected void
doDestroy()
Allows extending classes perform any custom cleanupprotected void
doInit(org.apache.commons.configuration2.Configuration config)
Allows extending classes perform any custom initializationprotected ChangeSet
doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet)
void
execute(Deployment deployment)
Executes the processorprotected ChangeSet
getFilteredChangeSet(ChangeSet changeSet)
Override to add pages/components that need to be updated because a component that they include was updated.protected abstract List<String>
getItemsThatIncludeComponent(String indexId, String componentPath)
protected abstract List<String>
getItemsThatInheritDescriptor(String indexId, String descriptorPath)
protected boolean
isBeingUpdatedOrDeleted(String path, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles)
protected boolean
isComponent(String path)
protected boolean
isDescriptor(String path)
void
setBatchIndexer(org.craftercms.search.batch.BatchIndexer batchIndexer)
Sets the single batch indexer used for indexing.void
setBatchIndexers(List<org.craftercms.search.batch.BatchIndexer> batchIndexers)
Sets the list of batch indexers used for indexing.void
setCacheTemplate(org.craftercms.core.util.cache.CacheTemplate cacheTemplate)
void
setComponentPathRegex(String componentPathRegex)
Sets the regex used to match component paths (used whenreindexItemsOnComponentUpdates
is enabled).void
setContentStoreService(org.craftercms.core.service.ContentStoreService contentStoreService)
Sets the content store used to retrieve the files to index.void
setContextFactory(org.springframework.beans.factory.ObjectFactory<org.craftercms.core.service.Context> contextFactory)
Sets the factory for theContext
.void
setDescriptorPathRegex(String descriptorPathRegex)
Sets the regex used to match descriptor paths for detecting inheriting items that should be reindex.void
setIndexIdFormat(String indexIdFormat)
The format used for the index idvoid
setItemsThatIncludeComponentQueryRows(int itemsThatIncludeComponentQueryRows)
Sets the rows to fetch for the search query used to find items that include components (used whenreindexItemsOnComponentUpdates
is enabled).void
setXmlFlatteningEnabled(boolean xmlFlatteningEnabled)
Sets whether XML flattening is enabled.boolean
supportsMode(Deployment.Mode mode)
Indicates if the processor should be included in the given deployment mode-
Methods inherited from class org.craftercms.deployer.impl.processors.AbstractMainDeploymentProcessor
doExecute, failDeploymentOnProcessorFailure, init, shouldExecute
-
Methods inherited from class org.craftercms.deployer.impl.processors.AbstractDeploymentProcessor
destroy, isJumpToActive, isPostDeployment, setBeanName, setEnv, setSiteName, setTargetId, shouldIncludeFile, startJumpTo
-
-
-
-
Field Detail
-
INDEX_ID_CONFIG_KEY
protected static final String INDEX_ID_CONFIG_KEY
- See Also:
- Constant Field Values
-
IGNORE_INDEX_ID_CONFIG_KEY
protected static final String IGNORE_INDEX_ID_CONFIG_KEY
- See Also:
- Constant Field Values
-
REINDEX_ITEMS_ON_COMPONENT_UPDATES
protected static final String REINDEX_ITEMS_ON_COMPONENT_UPDATES
- See Also:
- Constant Field Values
-
CREATE_INDEX_IF_MISSING_CONFIG_KEY
protected static final String CREATE_INDEX_IF_MISSING_CONFIG_KEY
- See Also:
- Constant Field Values
-
DEFAULT_DESCRIPTOR_PATH_PATTERN
protected static final Pattern DEFAULT_DESCRIPTOR_PATH_PATTERN
-
DEFAULT_COMPONENT_PATH_PATTERN
protected static final Pattern DEFAULT_COMPONENT_PATH_PATTERN
-
DEFAULT_ITEMS_THAT_INCLUDE_COMPONENT_QUERY_ROWS
protected static final int DEFAULT_ITEMS_THAT_INCLUDE_COMPONENT_QUERY_ROWS
- See Also:
- Constant Field Values
-
cacheTemplate
protected org.craftercms.core.util.cache.CacheTemplate cacheTemplate
-
contextFactory
protected org.springframework.beans.factory.ObjectFactory<org.craftercms.core.service.Context> contextFactory
-
contentStoreService
protected org.craftercms.core.service.ContentStoreService contentStoreService
-
batchIndexers
protected List<org.craftercms.search.batch.BatchIndexer> batchIndexers
-
xmlFlatteningEnabled
protected boolean xmlFlatteningEnabled
-
descriptorPathPattern
protected Pattern descriptorPathPattern
-
componentPathPattern
protected Pattern componentPathPattern
-
itemsThatIncludeComponentQueryRows
protected int itemsThatIncludeComponentQueryRows
-
indexIdFormat
protected String indexIdFormat
-
indexId
protected String indexId
-
reindexItemsOnComponentUpdates
protected boolean reindexItemsOnComponentUpdates
-
createIndexIfMissing
protected boolean createIndexIfMissing
-
-
Method Detail
-
setCacheTemplate
public void setCacheTemplate(org.craftercms.core.util.cache.CacheTemplate cacheTemplate)
-
setContextFactory
public void setContextFactory(org.springframework.beans.factory.ObjectFactory<org.craftercms.core.service.Context> contextFactory)
Sets the factory for theContext
.
-
setContentStoreService
public void setContentStoreService(org.craftercms.core.service.ContentStoreService contentStoreService)
Sets the content store used to retrieve the files to index.
-
setBatchIndexer
public void setBatchIndexer(org.craftercms.search.batch.BatchIndexer batchIndexer)
Sets the single batch indexer used for indexing.
-
setBatchIndexers
public void setBatchIndexers(List<org.craftercms.search.batch.BatchIndexer> batchIndexers)
Sets the list of batch indexers used for indexing.
-
setXmlFlatteningEnabled
public void setXmlFlatteningEnabled(boolean xmlFlatteningEnabled)
Sets whether XML flattening is enabled. Only used in conjunction withreindexItemsOnComponentUpdates
to see if pages/components should be re-indexed when components they include are updated.
-
setDescriptorPathRegex
public void setDescriptorPathRegex(String descriptorPathRegex)
Sets the regex used to match descriptor paths for detecting inheriting items that should be reindex.
-
setComponentPathRegex
public void setComponentPathRegex(String componentPathRegex)
Sets the regex used to match component paths (used whenreindexItemsOnComponentUpdates
is enabled).
-
setItemsThatIncludeComponentQueryRows
public void setItemsThatIncludeComponentQueryRows(int itemsThatIncludeComponentQueryRows)
Sets the rows to fetch for the search query used to find items that include components (used whenreindexItemsOnComponentUpdates
is enabled).
-
setIndexIdFormat
public void setIndexIdFormat(String indexIdFormat)
The format used for the index id
-
doInit
protected void doInit(org.apache.commons.configuration2.Configuration config) throws org.craftercms.commons.config.ConfigurationException
Description copied from class:AbstractDeploymentProcessor
Allows extending classes perform any custom initialization- Specified by:
doInit
in classAbstractDeploymentProcessor
- Parameters:
config
- the bean's configuration- Throws:
org.craftercms.commons.config.ConfigurationException
- if there's configuration related exception
-
doDestroy
protected void doDestroy() throws DeployerException
Description copied from class:AbstractDeploymentProcessor
Allows extending classes perform any custom cleanup- Specified by:
doDestroy
in classAbstractDeploymentProcessor
- Throws:
DeployerException
- if an error occurs
-
supportsMode
public boolean supportsMode(Deployment.Mode mode)
Description copied from interface:DeploymentProcessor
Indicates if the processor should be included in the given deployment mode- Specified by:
supportsMode
in interfaceDeploymentProcessor
- Overrides:
supportsMode
in classAbstractDeploymentProcessor
- Parameters:
mode
- the deployment mode to check- Returns:
- true if the processor should be included
-
execute
public void execute(Deployment deployment)
Description copied from interface:DeploymentProcessor
Executes the processor- Specified by:
execute
in interfaceDeploymentProcessor
- Overrides:
execute
in classAbstractDeploymentProcessor
- Parameters:
deployment
- the current deployment info
-
doCreateIndexIfMissing
protected abstract void doCreateIndexIfMissing(Target target)
-
getFilteredChangeSet
protected ChangeSet getFilteredChangeSet(ChangeSet changeSet)
Override to add pages/components that need to be updated because a component that they include was updated.- Overrides:
getFilteredChangeSet
in classAbstractDeploymentProcessor
- Parameters:
changeSet
- original change set- Returns:
- filtered change set
-
doMainProcess
protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException
Description copied from class:AbstractMainDeploymentProcessor
Performs the actual work of processing the files in theChangeSet
, it is also possible to return a newChangeSet
to be used for the following processors in the pipeline- Specified by:
doMainProcess
in classAbstractMainDeploymentProcessor
- Parameters:
deployment
- the current deploymentexecution
- the current executionfilteredChangeSet
- the filtered change set (as returned byAbstractDeploymentProcessor.getFilteredChangeSet(ChangeSet)
)originalChangeSet
- the original change set (as returned by the previous processors in the pipeline)- Returns:
- a new
ChangeSet
or null - Throws:
DeployerException
- if there is any error processing theChangeSet
-
doCommit
protected abstract void doCommit(String indexId)
-
isDescriptor
protected boolean isDescriptor(String path)
-
isComponent
protected boolean isComponent(String path)
-
isBeingUpdatedOrDeleted
protected boolean isBeingUpdatedOrDeleted(String path, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles)
-
getItemsThatInheritDescriptor
protected abstract List<String> getItemsThatInheritDescriptor(String indexId, String descriptorPath)
-
addItemsThatInheritFromDescriptorToUpdatedFiles
protected void addItemsThatInheritFromDescriptorToUpdatedFiles(String descriptorPath, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles)
-
getItemsThatIncludeComponent
protected abstract List<String> getItemsThatIncludeComponent(String indexId, String componentPath)
-
addItemsThatIncludeComponentToUpdatedFiles
protected void addItemsThatIncludeComponentToUpdatedFiles(String componentPath, List<String> createdFiles, List<String> updatedFiles, List<String> deletedFiles)
-
-