Interface MassIndexer
- Author:
- Sanne Grinovero
-
Method Summary
Modifier and TypeMethodDescriptionbatchSizeToLoadObjects(int batchSize) Sets the batch size used to load the root entities.Sets the cache interaction mode for the data loading tasks.dropAndCreateSchemaOnStart(boolean dropAndCreateSchema) Drops the indexes and their schema (if they exist) and re-creates them before indexing.environment(org.hibernate.search.mapper.pojo.massindexing.MassIndexingEnvironment environment) Sets theMassIndexingEnvironment, which can set up an environment (thread locals, ...) in mass indexing threads.failureFloodingThreshold(long threshold) Sets the threshold for failures that will be reported and sent toMassIndexingFailureHandlerper indexed type.failureHandler(org.hibernate.search.mapper.pojo.massindexing.MassIndexingFailureHandler failureHandler) Sets theMassIndexingFailureHandler.idFetchSize(int idFetchSize) Specifies the fetch size to be used when loading primary keys if objects to be indexed.limitIndexedObjectsTo(long maximum) Stops indexing after having indexed a set amount of objects.mergeSegmentsAfterPurge(boolean enable) Merges each index into a single segment after the initial index purge, just before indexing.mergeSegmentsOnFinish(boolean enable) Merges each index into a single segment after indexing.monitor(org.hibernate.search.mapper.pojo.massindexing.MassIndexingMonitor monitor) Sets theMassIndexingMonitor.purgeAllOnStart(boolean purgeAll) Removes all entities from the indexes before indexing.start()Starts the indexing process in background (asynchronous).voidStarts the indexing process, and then block until it's finished.threadsToLoadObjects(int numberOfThreads) Sets the number of threads to be used to load the root entities.transactionTimeout(int timeoutInSeconds) Timeout of transactions for loading ids and entities to be re-indexed.Define a filter on a giventypefor entities to be re-indexedtypesToIndexInParallel(int threadsToIndexObjects) Sets the number of entity types to be indexed in parallel.
-
Method Details
-
type
Define a filter on a giventypefor entities to be re-indexed- Parameters:
type- The type on which the filter will be applied- Returns:
- The step allowing to define the filter
-
typesToIndexInParallel
Sets the number of entity types to be indexed in parallel.Defaults to
1.- Parameters:
threadsToIndexObjects- number of entity types to be indexed in parallel- Returns:
thisfor method chaining
-
threadsToLoadObjects
Sets the number of threads to be used to load the root entities.- Parameters:
numberOfThreads- the number of threads- Returns:
thisfor method chaining
-
batchSizeToLoadObjects
Sets the batch size used to load the root entities.- Parameters:
batchSize- the batch size- Returns:
thisfor method chaining
-
cacheMode
Sets the cache interaction mode for the data loading tasks.Defaults to
CacheMode.IGNORE.- Parameters:
cacheMode- the cache interaction mode- Returns:
thisfor method chaining
-
mergeSegmentsOnFinish
Merges each index into a single segment after indexing.Defaults to
false.- Parameters:
enable-trueto enable this operation,falseto disable it.- Returns:
thisfor method chaining
-
mergeSegmentsAfterPurge
Merges each index into a single segment after the initial index purge, just before indexing.Defaults to
truefor indexes that support it,falsefor other indexes.This setting has no effect if
purgeAllOnStartis set to false.- Parameters:
enable-trueto enable this operation,falseto disable it.- Returns:
thisfor method chaining
-
dropAndCreateSchemaOnStart
Drops the indexes and their schema (if they exist) and re-creates them before indexing.Indexes will be unavailable for a short time during the dropping and re-creation, so this should only be used when failures of concurrent operations on the indexes (indexing caused by entity changes, ...) are acceptable.
This should be used when the existing schema is known to be obsolete, for example when the Hibernate Search mapping changed and some fields now have a different type, a different analyzer, new capabilities (projectable, ...), etc.
This may also be used when the schema is up-to-date, since it can be faster than a
purgeon large indexes.Defaults to
false.- Parameters:
dropAndCreateSchema- iftruethe indexes and their schema will be dropped then re-created before starting the indexing- Returns:
thisfor method chaining
-
purgeAllOnStart
Removes all entities from the indexes before indexing.Set this to false only if you know there are no entities in the indexes: otherwise search results may be duplicated.
Defaults to
true.- Parameters:
purgeAll- iftrueall entities will be removed from the indexes before starting the indexing- Returns:
thisfor method chaining
-
limitIndexedObjectsTo
Stops indexing after having indexed a set amount of objects.As a results the indexes will not be consistent with the database: use only for testing on an (undefined) subset of database data.
- Parameters:
maximum- the maximum number of objects to index- Returns:
thisfor method chaining
-
start
CompletionStage<?> start()Starts the indexing process in background (asynchronous).May only be called once.
- Returns:
- a
CompletionStageto react to the completion of the indexing task. CallCompletionStage.toCompletableFuture()on the returned object to convert it to aCompletableFuture(which implementsFuture).
-
startAndWait
Starts the indexing process, and then block until it's finished.May only be called once.
- Throws:
InterruptedException- if the current thread is interrupted while waiting.
-
idFetchSize
Specifies the fetch size to be used when loading primary keys if objects to be indexed.Some databases accept special values, for example MySQL might benefit from using
Integer.MIN_VALUEotherwise it will attempt to preload everything in memory.- Parameters:
idFetchSize- the fetch size to be used when loading primary keys- Returns:
thisfor method chaining
-
transactionTimeout
Timeout of transactions for loading ids and entities to be re-indexed.Specify a timeout which is long enough to load and index all entities of the type with the most instances, taking into account the configured batch size and number of threads to load objects.
Only supported in JTA-compatible environments.
- Parameters:
timeoutInSeconds- the transaction timeout in seconds; If no value is given, the global default timeout of the JTA environment applies.- Returns:
thisfor method chaining
-
monitor
Sets theMassIndexingMonitor.The default monitor just logs the progress.
- Parameters:
monitor- The monitor that will track mass indexing progress.- Returns:
thisfor method chaining
-
failureHandler
MassIndexer failureHandler(org.hibernate.search.mapper.pojo.massindexing.MassIndexingFailureHandler failureHandler) Sets theMassIndexingFailureHandler.The default handler just forwards failures to the
background failure handler.- Parameters:
failureHandler- The handler for failures occurring during mass indexing.- Returns:
thisfor method chaining
-
environment
@Incubating MassIndexer environment(org.hibernate.search.mapper.pojo.massindexing.MassIndexingEnvironment environment) Sets theMassIndexingEnvironment, which can set up an environment (thread locals, ...) in mass indexing threads.- Parameters:
environment- a component that gets a chance to set up e.g.ThreadLocalsin mass indexing threads before mass indexing starts, and to remove them after mass indexing stops.- Returns:
thisfor method chaining- See Also:
-
failureFloodingThreshold
Sets the threshold for failures that will be reported and sent toMassIndexingFailureHandlerper indexed type. Any failures exceeding this number will be ignored. A count of such ignored failures together with the operation they belong to will be reported to the failure handler upon the completion of indexing process.- Parameters:
threshold- The number of failures during one mass indexing beyond which the failure handler will no longer be notified. This threshold is reached separately for each indexed type. Overrides thethreshold defined by the failure handler itself.Defaults to
100with the default failure handler.- Returns:
thisfor method chaining
-