SKU based search in Predictive Search API

Hello ALL!

I want to enable SKU based search in search bar of shopify trade theme so I updated the fetch request for predictive search API but it is not working fine as it is not returning exact matched results. Below is the fetch request:

fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(searchTerm)}&${encodeURIComponent('resources[options][fields]')}=title,product_type,variants.title,vendor,tag,variants.sku&section_id=predictive-search`, {
  signal: this.abortController.signal,
})

Below is the response for an SKU searched. The response does not include matched variant but I have noticed 1 thing that in the response the variants array is empty even this product has variants:

{
“resources”: {
“results”: {
“products”: [
{
“available”: true,
“body”: “The Madra Blush Tone Rug is a perfect addition to your home with beautiful colors and an intriguing, traditional pattern. This rug is carefully handmade by artisans made with jute and cotton. Add this rug to any room to add charming character with a natural touch.”
“title”: “Madra Blush Tone Area Rug”,
“type”: “Matrix Item”,
“variants”:
}
]
}
}
}

Can someone tell me what can be the issue ?

Hey @tov_hamza, I found some information that may be helpful here.

Also,

You should check the note under the example product response for more details.

Hi @tov_hamza

Are you still experiencing this issue?

I solved the issue using another workaround. But technically, yes, the issue is still there. The API is still not working properly. I even had the products re-indexed by the Shopify support, which turned out to be of no use.

How did you resolve this issue?

I added each variant’s SKU for each product in product boosts section of Search & Discovery shopify app.

Thanks, it turns out I solved it the same way. I was hoping it could be done faster, without manual filling.

@Liam-Shopify wouldn’t it be possible to add native logic to search also by product/variant SKU, since it already catches them, for example, by color options (if I’m not wrong)? SKU can be very important for B2B customers in stores with a very large product assortment, where clients often use SKU codes in their product catalogs.