I have faced the problem in using Magento2
with search result commonly search based on SKU
but I want to search product using the name of the product so I want to change the search query in Magento2
but I am not found any option in admin section and code file so can anybody help me to change search query.
For that, i suggest you to override the core catalog_search and search module first and then you can get solution inside the model folder.
Check this 2 files: vendor/magento/module-catalog-search/Model/Layer/Search/Plugin/CollectionFilter.php afterFilter(){}
vendor/magento/module-search/Model/Query.php getSuggestCollection(){}
Hope this can be helpful.
Thanks
-
I will try this solution and get back to you with my comments. Thanks for your valuable information. – kapil dikshit Feb 18 '20 at 6:31
-
you have to set AND operator in your elastic search json queries, Override the module-elasticsearch/SearchAdapter/Query/Builder/Match.php. file in your custom module and then The code you have to edit in the build function in line no 75
if($matchKey != 'match_phrase_prefix'){$matchQuery['operator'] = "AND";}
Also make sure you are not setting the operator in match_phrase_prefix.
After this you'll get exact matches in catalog search.
This has been tested well for magento CC 2.4.0