v1.1.57

Implementing Custom Search Index

Sometimes it's need to have 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 repository http://github.com/mirasvit/module-search-extended

    Note

    There must be taken into account your Magento version. Correct steps should be:

    1. git clone <repo_url> - Clone the example module from the repository;
    2. 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, run git branch.

  2. Go to app/code/Mirasvit/SearchExtended/Index/ and rename subpath Magento/Review/Review/ to the required one ([provider]/[module]/[entity])
  3. Change class names in file app/code/Mirasvit/SearchExtended/Index/[provider]/[module]/[entity]/Index.php
    • Rename class
    • Set your values to getName(), getPrimaryKey() and getIdentifier() methods
  4. Configure the attributes you want to get in getAttributes() method
  5. Change methods buildSearchCollection() and getSearchableEntities()
  6. Change registration for new index in file app/code/Mirasvit/SearchExtended/etc/di.xml
  7. Adjust layout file app/code/Mirasvit/SearchExtended/view/frontend/layout/catalogsearch_result_index.xml

    Rename template name/path and adjust it /app/code/Mirasvit/SearchExtended/view/frontend/templates/index/magento/review/review.phtml

  8. Enable module and Clear magento cache

If everything was correct, you can add index of your custom type like any regular index.

  1. If you use SSU please go to: /vendor/mirasvit/module-search-autocomplete/src/SearchAutocomplete/Model/Index folder
  2. Create folder/file structure <Company>/<Extension>/<EntityType>.php i.e. /vendor/mirasvit/module-search-autocomplete/src/SearchAutocomplete/Model/Index/Ves/Blog/Post.php
  3. Open /vendor/mirasvit/module-search-autocomplete/src/SearchAutocomplete/etc/di.xml and add item to type name="Mirasvit\SearchAutocomplete\Model\Index\Pool" arguments