Bug: productVariants query sometimes matches substrings

Query for “product_type:food”:

{
  productVariants(
    first: 10
    query: "product_type:food"
  ) {
    edges {
      node {
        displayName
        product {
          productType
        }
      }
    }
  }
}

Returns a single result:

    "productVariants": {
      "edges": [
        {
          "node": {
            "displayName": "Instant Noodles - Default Title",
            "product": {
              "productType": "Food"
            }
          }
        }
      ]
    }

Query for “location_id:52613677214 AND product_type:food”

{
  productVariants(
    first: 10
    query: "location_id:52613677214 AND product_type:food"
  ) {
    edges {
      node {
        displayName
        product {
          productType
        }
      }
    }
  }
}

Returns additional variant with productType “Dairy food”

    "productVariants": {
      "edges": [
        {
          "node": {
            "displayName": "Sliced cheese - Default Title",
            "product": {
              "productType": "Dairy Food"
            }
          }
        },
        {
          "node": {
            "displayName": "Instant Noodles - Default Title",
            "product": {
              "productType": "Food"
            }
          }
        }
      ]
    }

Hey @brdata - thanks for flagging.

I took a look into this and I can see what you’re running into here. The inconsistent part appears to be when location_id is combined with product_type in the productVariants query. In that path, the product type filter can behave more like a search-term match, so a product type like Dairy Food can match product_type:food.

I’m going to flag this internally on our end since I agree the result is confusing, especially when product_type:food by itself only returns the exact Food product type.

For now, the safest workaround would be to keep product { productType } in the selection and apply an exact productType === "Food" check in your app after paging through the results. Not ideal, but I don’t want to suggest quoting the value as a reliable workaround here since that may still match the same tokenized value.

I’ll loop back here once I have more info to share.

Thanks @Alan_G we have used your recommendation as a workaround for this issue.

We also tested queries using vendors and tags.

The same issue occurs when the vendor name query partially matches a word or phrase.

Interestingly, this bug does not appear when we query tags.

Thanks for following up @brdata, glad to hear the workaround is working for you! I still don’t have a concrete explanation for the root cause of the issue, but I’m still happy to look into things for you if needed, please just let me know!