4

I'm trying to figure out why Magento 2 Search is working that way. My products have SKUS like 111-222-333. When i'm trying to search by SKU, magento 2.4 returns a product collection of ther product sku i've search ( at first position ) , and after that a lot of other similar products ( i suppose ).

Is there a way to override the search functionality or some setting in order for the search query to return only one result, if the given term matches an sku?

I've already investigated the search modules with no luck at all

PS Magento 2.4 uses only Elasticsearch

2 Answers 2

1

did you manage to solve this problem?

I wrote a small module addresses your issue - if you search for a string that matches the SKU of a product, then you get redirected to the product details page of that product. I did it this way so that no query gets to the search engine since you would get only one result when searching for an SKU. You can check the code on my github repo.

And in order to shed some light into why is Elasticsearch 'working this way' (you get a bunch of results even if you searched for one item), it's like that because you are not limiting the search engine to show only exact matches. In a generic e-commerce scenario you normally don't want that; you want at least some results to be shown, the most relevant to the searched query, even if no exact match was found.

Your search query will provide a set of results that are sorted by relevance, from the most relevant to the least relevant, measured as a score between 0 and 1 (closest to 1 means higher the match). The relevance is influenced by many factors and if you are interested on the topic I recommend reading about how scoring works in Elasticsearch.

0

Catalog search relevance and search results in native Magento2 Open Source are notoriously bad - a simple SKU search is a great example of Magento2 returning very poor search results.

There are ways to fine tune Elastisearch and improve relevance but by far the best solution is to use

https://github.com/Smile-SA/elasticsuite

Simply put, installing the Smile ElasticSuite modules and changing catalog search to ElasticSuite will immediately give you almost perfect search results. ElasticSuite is very simple to install and works out of the box improving search results and search relevance.

I wrote a blog post about this that describes in detail the problems with SKU search and the options I looked at to try and improve default search myself.

https://blog.gaiterjones.com/how-to-improve-magento-2-elasticsearch-catalog-search-results-and-relevance/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.