Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Storefront API unexpected search results

Storefront API unexpected search results

rohantaneja-dh
Tourist
3 0 1

Hi, I'm using the Storefront API to fetch products for a particular vendor from my store. I have a few vendors whose names start with "Devpack" and one vendor who is named just "Devpack".

All these names being:
"Devpack"
"Devpack A"
"Devpack A B"
"Devpack B"
"Devpack_C" (Yes it's an underscore instead of a space)

As visible in the screenshot, these vendors have the following products respectively:
"Bananas"
"Bananas A"
"Bananas A B"
"Bananas B"
"Bananas C"

Screenshot 2021-07-06 at 15.52.02.png
Context:

When I search for the first 100 products with vendor "Devpack", I get the correct results:

 

// GraphQL Query

query {
	products(first: 100, query:"vendor:'Devpack'") {
		edges {
			node {
				title
			}
		}
	}
}

// Response

{
    "data": {
        "products": {
            "edges": [
                {
                    "node": {
                        "title": "Bananas"
                    }
                }
            ]
        }
    }
}

 



The issue:

Now, when I want to search for products from the vendor "Devpack" and only those that have the word "Bananas" in their title, I get the following results:

// GraphQL Query

query {
	products(first: 100, query:"vendor:'Devpack' title:*Bananas*") {
		edges {
			node {
				title
            }
		}
	}
}

// Response

{
    "data": {
        "products": {
            "edges": [
                {
                    "node": {
                        "title": "Bananas B"
                    }
                },
                {
                    "node": {
                        "title": "Bananas A"
                    }
                },
                {
                    "node": {
                        "title": "Bananas"
                    }
                },
                {
                    "node": {
                        "title": "Bananas A B"
                    }
                }
            ]
        }
    }
}


1. Observe that I now get results from all vendors that "contain" the word "Devpack" instead of exactly matching "Devpack". This happens as shown above when I append title=*Bananas* to the query.
2. Also, only products from vendors which have the exact word "Devpack" in their vendor name show up. Notice that "Bananas C" from vendor "Devpack_C" doesn't show up as expected.

Expected Behaviour:

I would expect Shopify to only return "Bananas" from vendor "Devpack" when my query is "vendor:'Devpack' title=*Bananas*" and not from all vendors that contain the exact word "Devpack" such as "Devpack A", "Devpack B" and "Devpack A B".

As per the documentation here"vendor:'Devpack' title=*Bananas*" is the same as"vendor:'Devpack' AND title=*Bananas*" so I'm guessing that's not the issue here. I've confirmed this by adding an "AND" in my query and I get the same results.

For now, my solution is to never have spaces in my vendor names and always use underscores. But I'm not sure if this is a failproof solution and the right approach. Please let me know. 

Thank you.

Replies 0 (0)