vuestorefront / storefront-query-builder

ElasticSearch Query builder from the abstract "SearchQuery" object used by storefront-api, vue-storefront-api and vue-storefront projects
MIT License
7 stars 21 forks source link

Add `minimum_should_match` clause to `or`/`nor` filters to really filter by `should` clause #18

Open cewald opened 4 years ago

cewald commented 4 years ago

If you use an or/nor filter it would be applied without a specific minimum_should_match value. This could lead into wrong results as it is not adding a reducing filter, just a or/nor that doesn't affect the results.

Example:

Consider the following final query:

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "color": [ "blue" ]
              }
            }
          ],
          "should": [
            {
              "terms": {
                "size": [ 11 ]
              }
            },
            {
              "terms": {
                "is_in_sale": [ 1 ]
              }
            }
          ]
        }
      }
    }
  }
}

We wan't to load products that have the color "blue" and products that are "in sale" or have size "1"
– BUT without minimum_should_match we just ask for a definitiv color and the should filter must not be fulfilled as minimum_should_match is 0 by default.

cewald commented 3 years ago

@Fifciu @gibkigonzo I've updated to the latest master branch – are any updated/changes necessary?