We have taken care of the following points while creating a custom indexer.
- Indexer Configuration
- MView Configuration
- Indexer Logic
Mageto2: The Indexer Configuration
|id||Yes||It is the id of the indexer, which must be unique.|
|class||No||The class that processes indexer methods (executeFull, executeList, executeRow and execute)|
|primary||No||It is the source of provider|
|shared_index||No||Use this option to improve performance if your indexer is related to another. You can take an example from the catalog product catalog rule’s indexer. If the Catalog product rule index needs to be reindexed, but other catalog product rule indexes are up-to-date, then only the Catalog product rule index needs to be reindexed.|
|view_id||The id which we define in the view.xml file|
The indexer.xml also has the parameters, so let’s look into it.
|description||The description of the indexer is to be displayed on the System > Tools > Index Management page.|
Describes the fields, source, and data provider of the flat index table.
|saveHandler||The class for processing (deleting, saving, updating) items when indexing.|
|structure||The class that processes (creates, removes) flat index tables.|
|title||The title of indexer to be displayed on the |
mview.xml contains the indexer view id, indexer class, the database name that the indexer will track, and the column data to be sent to the indexer.
The View Node
The view node defines an indexer. It contains attributes given below:
|id||This attribute contains the name of the indexer table.|
|class||This contains a class that will be responsible for executing the indexer.|
|group||It defines the indexer group.|
The Subscription Node
This node contains children nodes with the name table. This node observes changes in given tables in the children node.
The Table Node
This node defines a table to track changes.
|name||This attribute contains the table name|
|entity_column||This attribute defines field name to be re-indexer|
Indexing can be done by cron as well as the command:
php bin/magento indexer:reindex
Re-indexing can be performed in two modes: 1) Update On Save and 2) Update By Schedule.
- Update On Save: Indexer table will be updated immediately on saving or updating data on tables
- Update By Schedule: The index table will be updated based on the cron job schedule.
Note: Magento doesn’t support the update by schedule on the customer_grid indexer. Apart from customer_grid, You may set the update by schedule on all Magento’s indexers.
For customer_grid, You may set the Update on Save model. You may also re-index by using the command
php bin/magento indexer:reindex customer_grid
I hope you like the post and have more clarity about the configuration of the indexer.
Please subscribe to the SbDevBlog. Use the comment box to share your feedback. Thank You!
Thanks for the reading Mageto2: The Indexer Configuration
Note: Please verify the code of this blog and the relevant git repository before using it in production.
🙂 HAPPY CODING 🙂