Implementing Custom Search Index
Sometimes it's necessary to have a specific type of Index which is either not included to our search extension, or belongs to some third-party extension. In this case, custom index can be implemented using the following instructions:
-
Clone the example module from the repository https://github.com/mirasvit/module-search-extended.git
Note
There must be taken into account your Magento version. Correct steps should be:git clone <repo_url>
- Clone the example module from the repository;cd module-search-extended/
- Change directory;git checkout magento23
- Navigate to specific tagname for Magento 2.1-2.3 please use tag magento23.git checkout magento24
- For Magento 2.4+ please use tag magento24.
To make sure you switched to the correct tagname, rungit branch
.
- Go to
app/code/Mirasvit/SearchExtended/Index/
and rename the subpathMagento/Review/
to the required one. We suggest to use the following structure -([provider]/[module]/[entity])
- Change class names in file
app/code/Mirasvit/SearchExtended/Index/[provider]/[module]/[entity]/Index.php
- Set your values to
getName()
,getPrimaryKey()
andgetIdentifier()
methods - Configure the attributes you want to get in
getAttributes()
method - Change
buildSearchCollection()
andgetIndexableDocuments()
methods
- Set your values to
- Change class names in file
app/code/Mirasvit/SearchExtended/Index/[provider]/[module]/[entity]/InstantProvider.php
- Set your values to
map()
andmapItem()
methods
- Set your values to
- Change registration for new index in file
app/code/Mirasvit/SearchExtended/etc/di.xml
- 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
- Rename the template name/path and adjust it
- 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
- Rename the template name/path and adjust it
- 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.