Querying images with tags that contains dashes/hyphens
Hello,
I'm trying to query images using the Search API, and in my query I'm adding a clause that should match the images' tags. It works fine for one-word tags, so for example if in my query I request images that have the "floorplan" and "ballroom" tags, I get the correct results/images back in the response.
If, however, in my query I try to include a tag that has a dash/hyphen in it's name, for example "macatawa-ballroom", the Search API doesn't return an image that has a such a tag in my library. I've tried putting the tag name in quotes in my code, and also escaping the dash, however that didn't work for me. The Search API documentation does not mention anything about dashes in tag names either.
Is there a way to include tags that contain dashes in the Search API queries?
Thanks
-
Hi Leanne,
I have tested the dash on my side and I am able to get some results, here is my code snippet in NodeJS:
cloudinary.search.expression('tags:test-tag').with_field('tags').execute().then(result=>console.log(result));However, this request will also return results for images tagged with either `test` or `tag`, to avoid that, you can add a `*` after the tag itself like this:
cloudinary.search.expression('tags:test-tag*').with_field('tags').execute().then(result=>console.log(result));In case it is still not working for you, may I ask you to share an example URL of an image with the tag `macatawa-ballroom`?
Hope it helps.
Best,
Loic
0 -
Hi Loic,
I'm experiencing two issues.
1) I've tried your approach and it does work, however if I use the star (*) symbol at the end of a tag with a dash in it, the Search API interprets it as a wildcard symbol, and matches any tags that start with "macatawa-ballroom". There could be cases where the wildcard might match with tags that we don't intend to match with, if both tags start with "macatawa-ballroom".
Is there anyway to create a search query that matches exactly "macatawa-ballroom", or any other tags that have dashes in them?
2) Another issue I found is that if an image has a tag with a dash, like "macatawa-ballroom", and if I search for a tag "macatawa", I'd expect an image with the "macatawa-ballroom" tag to not get returned, however it does get returned in the response.
Is there a way to exclude tags with dashes from the search results in this scenario, where the tag I'm searching for is a subset of the tag with a dash in it? In this scenario, I'm trying to get an exact "macatawa" tag match.
Thanks
0 -
I was also looking for this code and great it is here.
0 -
Hi Leanne,
Could you try using `=` instead of `:` for exact matches:
cloudinary.search.expression('tags=test-tag').with_field('tags').execute().then(result=>console.log(result));Hope it helps.
Best,
Loic
0
Post is closed for comments.
Comments
4 comments