GraphQL Products Tag Query Tokenization

vf-telwing
Shopify Partner
1 0 0

We are facing an issue when trying to query products by tag where the tag tokenization is returning unexpected results. The goal of our tagging is to allow products to be queried by SKU via the Storefront API. In other posts, the suggested solution was to create more specific tags to prevent overlap, so we landed on the following tag format:

 

sku:[SKU-HERE]:uks

 

 

We were hoping that the existence of a prefix/suffix would yield more targeted results. This seemed to work well enough until we started building out queries with multiple tags. We noticed that the order of the tags affects the results that are returned. Unfortunately, the order of the tags is important in our use-case and are being provided via metadata. Please see the queries below:

 

Query with Unexpected Result

We ask for two SKUs and we receive an unexpected result.

  • Expected: HFC16, BO-SU-12
  • Actual: BO-SU-12, BO-SU-16

 

query {
  products(first:2, query:"tag:sku\\:HFC16\\:uks OR sku\\:BO-SU-12\\:uks") {
    edges {
      node {
        variants(first:1) {
          edges {
            node {
              sku
            }
          }
        }
      }
    }
  }
}

 


Query with Reordered Tags

We move BO-SU-12 to the first tag in the query and receive the expected results.

  • Expected: BO-SU-12, HFC16
  • Actual: BO-SU-12, HFC16

 

query {
  products(first:2, query:"tag:sku\\:BO-SU-12\\:uks OR sku\\:HFC16\\:uks") {
    edges {
      node {
        variants(first:1) {
          edges {
            node {
              sku
            }
          }
        }
      }
    }
  }
}

 


Questions

  • Is there anything we can do with our tagging format to try to further reduce overlap?
  • Why would the order of tags affect the results?
Replies 0 (0)