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

Magento 2 Multi Word Search #5590

Closed
ednacool opened this issue Jul 12, 2016 · 21 comments
Closed

Magento 2 Multi Word Search #5590

ednacool opened this issue Jul 12, 2016 · 21 comments
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed

Comments

@ednacool
Copy link

Search is working weird as it is not giving the proper result by matching whole word for e.g if i search for
Radiant Tee it is giving other results too. You can check it out in given link

http://magento2demo.firebearstudio.com/catalogsearch/result/?q=Radiant+Tee+

Seems to be search feature needs fixing

@choukalos choukalos self-assigned this Jul 12, 2016
@choukalos
Copy link

Hello @ednacool this is by design. We've change our search in Magento 2 to use a full text algorithm. So what its doing is running that algorithm against the words in the search query. You'll notice that 'Radiant Tee' is the first hit as it has the highest relevance - both words match, then the other results are coming up because the engine is finding Tee in those products as well (lower relevance). Our market research indicated shoppers are looking for the most relevant results to be first, if there are extra results it's not a big deal. We understand that for some merchants this isn't desired behavior and have been looking at options to address in core. Unfortunately we haven't been able to come up with a design that covers our entire customer base as tuning the behavior is really merchant/catalog specific.

If this is important to you I'd like to point out you can customize this behavior by doing an after plugin on the query interface and only show products with a certain relevance score or higher. Please note that filtering on that score is dependent on your search engine, the catalog and the queries that your customers are using. For that reason I think it would be very hard for us to find a generic solution that would work for the majority of our merchants. If anyone can suggest an approach or algorithm that would work across verticals for the majority of our merchants please share.

@ednacool
Copy link
Author

Hi choukalos,

Thanks for getting me back but is this possible you guys can add any method like full word search at least we have any configuration in backhand which allow to search the full word as some merchants don't won't search to give the additional results because sometimes it is confusing on client side for e.g if they are searching for Natural Oil and search result also show Natural Cream or Natural Aloevera and natural oil on 3rd page as i am doing for one of my merchant site the search result not looks good.

Or is this possible for now i can allow the full text result only any extension or core file modification you can let me know

But i think it should have any option in magento configuration

@choukalos
Copy link

Hi @ednacool the algorithm in both MySQL and Elasticsearch should return products containing 'Natural Oil' with a higher relevancy then products that only contain one of those words. So you should see Natural Oil on the 1st page right at the top with Natural Cream or Natural Aloevera lower in the search results. Note that our search algorithm looks at several product fields and has a weighting on those fields. There were cases where catalogs had query terms in the description multiple times and it was bringing those to the top rather then products with those query terms in the product name or sku. If that's the case for your catalog you can tune the weighting that search uses for those fields. To do that look Stores/Attributes/Product ; then filter for the searchable attribute. You can click onto each of those attributes and check the storefront properties tab; look at the search weight field. That's the one you'd adjust on a scale of 1-10 to change behavior ( note you have to do a full reindex of the full text search index to make the change happen ). At some point we'll update the old data grid to the new style and you'll be able to just add the search weight attribute to the grid display but we haven't gotten to that yet so it's a little buried. I believe name has weight 5, and sku weight 6 with description weight 1 ( along with most other attributes ). In our research that seemed to work the best for search accuracy for example data we had + advice from search experts (by the way big props to RocketWeb, Smile, Phoenix Media, and the eBay search team for all their help!).

So I think at most, for out of the box, you'd just have to tune the attributes and you should get the multi-word query matches at the top of the results. More nuanced, but easy would be introducing a search filtering plugins that's specific to a search engine - that should be a fairly simple job for an extension developer. More complex would be to substitute your own search algorithm; likely that'd be tied to the search engine and would require a bit more work to get right.

If you'd like to discuss further please feel free to email me (email address in profile) and we can setup a time to chat more. At this point though I'm going to close the issue as this is as designed and call out the opportunity for extension developers!

@cuiyang000
Copy link

Hi @choukalos

I think the search is not working as you described, and it became a problem.

I have a clean installation of 2.1.0, when I search for "abc 999" here as you can see the product with both words was on the second: http://m2-demo.mgt4.iggo.fi/catalogsearch/result/?q=abc+999

And it's second because there're not so many products, if there're many and that product was created late (=big product id), I'd bet it would be in a very late position. Because we're facing this problem in our real project, product which matches the best was put on the 4th/5th page in the search result, this is quite annoying.

@Szymon-GP
Copy link

Hi,

The search behaviour seems to be like @cuiyang000 described. I have products showing at the end of the list which should be positioned at the beginning according to @choukalos and it's causing a huge problem for some merchants.

@michalbiarda
Copy link
Contributor

In case anyone is looking for solution for this issue:

To switch OR logic to AND for search query, add etc/search_request.xml file in your local module with the following content:

<?xml version="1.0"?>
<requests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Search/etc/search_request.xsd">
<request query="quick_search_container" index="catalogsearch_fulltext">
<queries>
<query xsi:type="boolQuery" name="quick_search_container" boost="1">
<!-- Change OR search logic to AND -->
<queryReference clause="must" ref="search" />
<queryReference clause="must" ref="category"/>
<queryReference clause="must" ref="price"/>
<queryReference clause="must" ref="visibility"/>
</query>
</queries>
</request>
</requests>

Also, in your local module's etc/module.xml file add the following dependency:

<sequence>
<module name="Magento_CatalogSearch"/>
</sequence>

I hope it will help someone. I spent a lot of time on digging it :-).

@sooong
Copy link

sooong commented Jun 9, 2017

hi @ednacool Can you tell me how to fix it?

@AliPs94
Copy link

AliPs94 commented Jun 21, 2017

@michalbiarda
In my local module what file should I create either than module.xml , search_request and register file ?

@korostii
Copy link
Contributor

Hi @AliPs94, please try reading this tutorial first or devdocs for a jump start on module development.
Please refer to the Community Forums or the Magento Stack Exchange for technical questions and support.

@AliPs94
Copy link

AliPs94 commented Jun 21, 2017

@korostii
Thanks for help , I know how to develop a magento module but I'm try to set @michalbiarda solution but this code is not working alone , I think there another files.

@gerben86
Copy link

@AliPs94
Any update on your problem? Because I see this problem:
Element 'request': Missing child element(s). Expected is one of ( filters, aggregations, from ).

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Nov 10, 2017
@nathanmerrill
Copy link

@gerben86 @korostii @michalbiarda

Apparently, the entire request object is needed.

  1. Go \vendor\magento\module-catalog-search\etc\search_request.xml, and copy the entire file
  2. Paste inside of your search_request.xml in your module.
  3. Remove all but the first <request> element
  4. Change <queryReference clause="should" ref="search" /> to "must"

This is because the XML validator requires multiple elements in each <request>, meaning we can't just override the few elements we want.

@harshvardhanmalpani
Copy link

harshvardhanmalpani commented Feb 20, 2018

This works on Magento 2.2.2
https://github.com/harshvardhanmalpani/magento2-search-with-AND/releases
Works for multiple words, forces "AND" query and returns only 1 result if search string matches any SKU in store.

@Rickertje
Copy link

I implemnented the above (michalbiarda). It works. However for every keyword that a search synonym exists for NO results wll be found any longer. It seems like the adapted query now searches for products that matches 'keyword' AND 'synonym' => which ofcourse will never give any result. Any solution?

@Rickertje
Copy link

@michalbiarda @nathanmerrill - any comment?

@dev-dyna
Copy link

dev-dyna commented May 2, 2018

any solution , guys ?

@johnmpasq
Copy link

This works on Magento 2.2.2
https://github.com/harshvardhanmalpani/magento2-search-with-AND/releases
Works for multiple words, forces "AND" query and returns only 1 result if search string matches any SKU in store.

Yes this works but do you know how to add other attributes besides sku. I have some products with multiple cross references and the hyphens are constantly throwing no search results.

@frostbitten
Copy link

Hi, I noticed it mentioned there was market research and that "if there are extra results it's not a big deal." Can somebody point me to that research? Everyone we have test our magento site complains they see a bunch of random search results. If the first few results are correct it doesn't seem to help, they see the rest and think they're way off base with their search criteria. I can't imagine search working well without it being a filtering mechanism. Imagine a customer trying to add the color of item they want into the search text, they'll be looking at everything of that color rather than filtering down their current results. This search mechanism out of the box is undeniably counterintuitive.

@amitebizon
Copy link

I implemnented the above (michalbiarda). It works. However for every keyword that a search synonym exists for NO results wll be found any longer. It seems like the adapted query now searches for products that matches 'keyword' AND 'synonym' => which ofcourse will never give any result. Any solution?

Any Solutions ?

@harshvardhanmalpani
Copy link

I had same situation and i was using my own code
https://github.com/harshvardhanmalpani/magento2-search-with-AND/releases

I could not override the other interceptors for synonyms as it was becoming huge mess to edit whole chain of functions for this purpose.
The way I fixed it was by editing my code to add synonym maps in code. Of course, it makes the inbuilt functionality for synonyms useless. But gets the job done (only when synonyms have singular and plural words)
Example: If "necklace" has synonym "necklaces", I can replace necklaces with necklace in my Match.php code.
But in case of synonyms where one is not a substring of others, It could not figure out the logic.
I can write what exactly we need

If search term is "gold necklace", the AND based search query is "+gold* +necklace*"
If necklace has synonym "pendant"
The search query becomes
"+gold* +necklace* +pendant*"
Hence resulting in 0 results.

Expected search term is (gold and necklace)OR(gold and pendant)
If anyone knows its equivalent in plus minus format, please tell me
Ill try to make it work over the weekend.

@o-mega
Copy link

o-mega commented Dec 16, 2023

Did anyone found proper solution to fix this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed
Projects
None yet
Development

No branches or pull requests