/   /   /  Magento 2 For developer : some ideas about frontend search


For more extensions and themes visit our store

Magento 2 For developer : some ideas about frontend search

For customize behavior of search you need know the mechanism of how Magento 2 stock and collect infos and how use  it, Now in Magento 2 we have in database catalogsearch_fulltext_scope1 and catalogsearch_fulltext_scope2 , is related to how many scope you have , let's imagine you have 2 store one for English and other for Arabic ,  the system create 2 scope . And stock the map of search inside this tables , but how ? Yeah let's go and see the structure of table ,this table have 3columns entity_id and atrribute_id and data_index :
entity_id : id of entity or product that mapped with this infos
atrribute_id  : id of attribute related to attribute set of product by default title and short description and description attribute used in map
 data_index : the work used for map taking from attribute like title or description

the system use the module Catalog_Search for manage creation and re-index of catalogsearch_fulltext_scopeX ,yes for creation of fulltext table Magento 2 use the class vendor/magento/module-catalog-search/Model/Indexer/IndexStructure.php , we have here the method create ,with create we call createFulltextIndex() function , but you need see the variable $this->indexScopeResolver we pass 2 parms for getting the  indexer table name by scope or default value the class responsible is: vendor/magento/framework/Indexer/ScopeResolver/IndexScopeResolver.php .

Ok when you create new index command the system will use the class vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php , for update the table in db with new value of column  data_index , in this class we have many way and function of indexing (full index or by entity id)

 when you create an attribute with option of search-able option (use in search) , the system add automatically this attribute to catalogsearch_fulltext_scope for indexing .

Ok we have other table search_query , that table stock the query  text with number of results , popularity active updated_at and other  information , the system use for report and sort and give more statistic to administrator , and  augment the user experience .


IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.