Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog search randomized results #9020

Closed
luismaldonadov opened this issue Mar 27, 2017 · 8 comments
Closed

Catalog search randomized results #9020

luismaldonadov opened this issue Mar 27, 2017 · 8 comments
Labels
Component: Search improvement Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Release Line: 2.1 up for grabs

Comments

@luismaldonadov
Copy link

Catalog results from a search within magento 2.1.1 appear to be randomized when expected to be the same ,even with page refresh or page navigation. There's other isue related to this one (4132) that appear to be an extension problem, but in this case i contacted the template creator and they told me this:

Actually, our theme is using the Search module- core functionality of Magento default. So, this is how the Search of Magento works. If you want to get the better appearance and results, then you should use an advanced Search extension

So, appears not to be an extension related problem.

Preconditions

  1. Magento 2.1.1
  2. PHP 7.0.13
  3. MySQL 5.6.34-79.1

Steps to reproduce

  1. Realize a search for any product
  2. Navigate or refresh the page

Expected result

  1. Consistent results for the generated page for the search term

Actual result

Result in this GIF. I'm refreshing the page, and as you can see different order for results.
https://gifyu.com/image/SoU6

@maghamed
Copy link
Contributor

This happens because MySQL randomly returns documents which weights are the same.

For example,
providing generally used search term (like "bag" on a Bag Store )
Will always produce different order of results. Because most of products will contain this word, and MySQL assigns equivalent relevancy for all of them.

But if the search is more specific like Duffle Bag .
Even applying refresh many times -
First document is always the same (because its weight is higher than others).

What Magento could do here is to add additional sorting by entity_id, so all documents (read products) with the same weight would be sorted by product_id as well.

$select->order('relevance ' . Select::SQL_DESC);

instead of
$select->order('relevance ' . Select::SQL_DESC);

have something like:

$select->order('relevance ' . Select::SQL_DESC . ', entity_id ' . Select::SQL_DESC) ;

What @wicho91 you could do now, not changing Core code is to pluginize
MySQL\Mapper::buildQuery(RequestInterface $request) method

public function buildQuery(RequestInterface $request)

with afterPlugin and add ordering which I mentioned above.
It's pretty easy to do, because current method returns $select object.

@luismaldonadov
Copy link
Author

Hello @maghamed thank you for the detailed response, i've just changed this part of the code. Im fairly new to web development as i spent 2+ years in desktop development. So will look into jQuery afterPlugin because im really blank here. But thank you again for the awesome help! Ill keep posted!

@choukalos
Copy link

Hi @wicho91 - could you put in a PR for this? Thanks!

@maghamed
Copy link
Contributor

maghamed commented Mar 27, 2017

@wicho91 I meant not jQuery plugins, because jQuery is front-end JavaScript framework, but Magento Plugins, which is extension mechanism provided by Magento Framework. You can read the documentation of how Plugins could be used following the link above.

You are welcome to prepare Pull Request for Core changes.

@luismaldonadov
Copy link
Author

@maghamed Even beter. You've guide me the correct way. I'll dig deep into this. For me it's a pretty and obvious need to have consistent information. Thank you so much!

@richievalsalan
Copy link

i am working on this

@richievalsalan
Copy link

richievalsalan commented Jun 10, 2017

I am not able to reproduce this issue in Version 2.2 ,

Following are the steps I had taken.

a) Created 7 products from backend
b) Searched using multiple keywords, each keywords had its 'definite' listing of products which seem to be consistent every single time.

Note:
However this issue is found at 2.1.x version (2.1.4 to be precise) while tested. Hence should we not add a '2.1 development tag' to it, so that it could get solved in the 2.1 versions.

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Oct 6, 2017
@BezV8
Copy link
Contributor

BezV8 commented Jun 18, 2018

I am seeing this issue still in 2.2.1, though sometimes it will take several refreshes for it to become apparent. I see that this is marked as being done in 2.3 develop, but can't find the changed files. Does anyone know what files were changed so it could be manually patched?

magento-devops-reposync-svc pushed a commit that referenced this issue Oct 8, 2024
…fix-06202024

Cia 2.4.8 beta1 develop bugfix 06202024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Search improvement Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Release Line: 2.1 up for grabs
Projects
None yet
Development

No branches or pull requests

9 participants