I am trying to do a "Phrase Query" on the product title field. In my example the phrase is: Quick Fuel
The following query returns everything with the word Quick in the title. The first 4 returned products in the screenshot do not have the phrase "Quick Fuel" in the title.
Based on the docs, the phrase needs to have double quotes around it:
Double quotes around the query and the phrase is a syntax error:
Single quotes around the query and double quotes around the phrase is a syntax error:
Double quotes around the query and single quotes around the phrase returns nothing:
How can this be done?
Solved! Go to the solution
Are you still able to replicate this? I set up some products in my own test shop titled "Quick Fuel Brawler" and then another called "Quick Test" but when performing the same query as you posted (query: "title:Quick Fuel") only the product with "Quick Fuel" in the title is being returned. So it looks like this may have been fixed.
If it's still not working as you'd expect though, could you post your shop domain here? Or if you'd rather not provide that, even a product ID would work and I could find your shop with that and attempt to replicate again.
So what actually happens when you run 'query: "title:Quick Fuel"' is a search for products that have 'quick' in the title, and then 'fuel' in any searched field (title, description, handle, product type, etc.) - so I'm assuming all of the products you weren't expecting to appear have 'fuel' as some product attribute somewhere. I had only been copying your product titles when trying to replicate this, which is why I wasn't seeing them show up on my own test store.
In order to make this search work and only return products with "Quick Fuel" in the title, this should work : query: "title:\"quick fuel\"*"
Thanks @Josh, I was getting tripped up on the same thing.
The docs didn't list " and ' as special characters that can be backslash escaped: https://help.shopify.com/en/api/getting-started/search-syntax#special-characters …just FYI incase they should be flagged for an update(?) Cheers.
Sorry - follow up question: Does this work when searching for a term with trailing whitespace?
I need to clean up duplicate vendors "my_vendor" and "my_vendor " (with trailing whitespace). Currently both:
products(query: "vendor:\"my_vendor \"*", first:3) # With asterisk
products(query: "vendor:\"my_vendor \"", first:3) # Without asterisk
return products containing:
Hey @malalta ,
I'm not sure off the top of my head, to be honest. I'd need to do some testing to see how to do that or if it can even be done, but I'm not having any luck saving a vendor with whitespace at the end of the name. Are you familiar at all with how you got a vendor name into that state? I've tried using the API, the admin, and a CSV import but the whitespace is getting stripped from the end of the name in each case.
I'm not sure how it got into this state unfortunately. The client has just hired our agency to help, so it was that way before I came along...
If it's an edge case don't worry too much about it. I'll just write some code to loop through all products and strip the whitespace from any vendor value. If your testing shows that whitespace is stripped when saving these days, we should be able to avoid this happening again going forward. Cheers, Andrew.
|3 hours ago|
|4 hours ago|
|4 hours ago|
|4 hours ago|