Implementing Custom Search Index

Sometimes it's necessary to have a specific type of Index which is either not included to our Magento 2 Elasticsearch Extension or Sphinx Extension, or belongs to some third-party extension. In this case, custom index can be implemented using the following instructions:

  1. Clone the example module from the repository
  2. Go to app/code/Mirasvit/SearchExtended/Index/ and rename the subpath Magento/Review/ to the required one. We suggest to use the following structure - ([provider]/[module]/[entity])
  3. Change class names in file app/code/Mirasvit/SearchExtended/Index/[provider]/[module]/[entity]/Index.php
    • Set your values to getName(), getPrimaryKey() and getIdentifier() methods
    • Configure the attributes you want to get in getAttributes() method
    • Change buildSearchCollection() and getIndexableDocuments() methods
  4. Change class names in file app/code/Mirasvit/SearchExtended/Index/[provider]/[module]/[entity]/InstantProvider.php
    • Set your values to map() and mapItem() methods
  5. Change registration for new index in file app/code/Mirasvit/SearchExtended/etc/di.xml
  6. Adjust layout file app/code/Mirasvit/SearchExtended/view/frontend/layout/catalogsearch_result_index.xml
    • Rename the template name/path and adjust it /app/code/Mirasvit/SearchExtended/view/frontend/templates/index/magento/review/review.phtml
  7. Adjust layout file app/code/Mirasvit/SearchExtended/view/frontend/layout/default.xml
    • Rename the template name/path and adjust it /app/code/Mirasvit/SearchExtended/view/frontend/templates/magento_review.phtml
  8. Enable the module and Clear magento cache

If everything was performed correctly, you should be able to add index of your custom type like any regular index.