on ‎2022 Jan 20 8:27 PM
By default, SOLR searches with multiple words, returns results with an OR operator between the words
For ex: If I search for black pant, it will return all results with word black as well as all products with word pant
I need it to be an AND operator, i.e. return products that has both black and pant in it.
Can this be achieved with simple configuration changes at either hybris or solr end. If not, how exactly can we modify the java classes to achieve this?
Request clarification before answering.
I think part of the issue here is that the two terms may be found in different Solr attributes. For example there may be both a field for "color" and another one for "clothingType". For this reason the Phrase Query Slop will not help.
Currently, Hybris is generating a SolrQuery similar to the following:
[SolrQueryDebuggingListener]
Parsed Solr Query:
+(DisjunctionMaxQuery((color_string:black | clothingType_string:black))
DisjunctionMaxQuery((color_string:pant | clothingType_string:pant))
DisjunctionMaxQuery((someOtherField_text:*black* | yetAnotherField_text:*black*))
DisjunctionMaxQuery((someOtherField_text:*pant* | yetAnotherField_text:*pant*))
DisjunctionMaxQuery((someDescriptionField_string:black pant | yetAnotherDescriptionField_text"black pant" | andAnotherField_text_en_string_mv:black pant)))
We would probably want something more like the following:
[SolrQueryDebuggingListener]
Parsed Solr Query:
(DisjunctionMaxQuery((color_string:black | clothingType_string:black) & (color_string:pant | clothingType_string:pant))
DisjunctionMaxQuery((someOtherField_text:*black* | yetAnotherField_text:black*) & (someOtherField_text:*pant* | yetAnotherField_text:pant*))
DisjunctionMaxQuery((someDescriptionField_string:black pant | yetAnotherDescriptionField_text"black pant" | andAnotherField_text_en_string_mv:black pant)))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, we probably need the query to be a bit more like the following:
[SolrQueryDebuggingListener]
Parsed Solr Query:
+(DisjunctionMaxQuery(
(color_string:black | clothingType_string:black | someOtherField_text:*black* | yetAnotherField_text:*black*)
&
(color_string:pant | clothingType_string:pant | someOtherField_text:*pant* | yetAnotherField_text:*pant*))
DisjunctionMaxQuery((someDescriptionField_string:black pant | yetAnotherDescriptionField_text"black pant" | andAnotherField_text_en_string_mv:black pant)))
I suggest you to look for Solr forums to get more accurate answer to your question.
I think your need is similar to the question in the following link: https://stackoverflow.com/questions/18224527/performing-exact-match-on-solr-search
There are two solutions proposed in the question.
You may also use Free Text Phrase Query with slop value which satisfies your needs, but this does not cover all your needs. For example if you set slop value as 1 the search result may include "Black Short Pant" but not "Black Short Cotton Pant". And you also need to disable Free Text Query on the field.
Hope this helps,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.