How to tweak Magento 2 for two letter search in fulltext mode

The problem:

Magento 2 wont return any search results if the search token is 2 letters in length.

Solution:

Alter MySQL conf file. Edit my.cnf file on your server
In CentOS, use command

nano /etc/my.cnf

and add the following lines:

ft_min_word_len=2
innodb_ft_min_token_size=2

Save using CTRL+x and then restart mysqld service.
Now we need to regenerate the index in order to get updated search results. Use the following SQL commands to regenerate:

Don’t forget to replace “jack_db1” with your database name

ALTER TABLE `jack_db1`.`catalogsearch_fulltext_scope1` DROP PRIMARY KEY, ADD PRIMARY KEY (`entity_id`, `attribute_id`) USING BTREE;
ALTER TABLE `jack_db1`.`catalogsearch_fulltext_scope1` DROP INDEX `FTI_FULLTEXT_DATA_INDEX`, ADD FULLTEXT `FTI_FULLTEXT_DATA_INDEX` (`data_index`);
ALTER TABLE `jack_db1`.`catalog_eav_attribute` DROP PRIMARY KEY, ADD PRIMARY KEY (`attribute_id`) USING BTREE;
ALTER TABLE `jack_db1`.`catalog_eav_attribute` DROP INDEX `CATALOG_EAV_ATTRIBUTE_USED_IN_PRODUCT_LISTING`, ADD INDEX `CATALOG_EAV_ATTRIBUTE_USED_IN_PRODUCT_LISTING` (`used_in_product_listing`) USING BTREE;
ALTER TABLE `jack_db1`.`catalog_eav_attribute` DROP INDEX `CATALOG_EAV_ATTRIBUTE_USED_FOR_SORT_BY`, ADD INDEX `CATALOG_EAV_ATTRIBUTE_USED_FOR_SORT_BY` (`used_for_sort_by`) USING BTREE;

References:
https://magento.stackexchange.com/a/157478/32283
https://dev.mysql.com/doc/refman/5.7/en/fulltext-fine-tuning.html


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *