Filtering on values as lower case

TLDR; Is there a way to filter on fields in a case insensitive way?

I’m trying to build a blog and on blog posts I want to link to list pages for tags. So, a blog post will have a tags property like:

{
  tags: ["Apples", "Bananas"]
}

However, when I create a link for a tag I want the URL to be lowercase, so the link should be /tag/apples. When I receive a request to /tag/apples I need to search for blog posts containing the tag apples in a case insensitive way. I can’t find anything in the docs regarding case insensitive querying, except for full text search but in theory using full text search may be risky (as that would also match tags such as “Green apples”).

1 Like

Hey,

thank you for your question. You can filter by a field using case insensitive matches by using the [match] operator:

curl -X GET -H "Authorization: Bearer $CPA_TOKEN" "https://preview.contentful.com/spaces/$SPACE_ID/entries?content_type=$TYPE&fields.tags\[match\]=apple"

returns

  "sys": {
    "type": "Array"
  },
  "total": 1,
  "skip": 0,
  "limit": 100,
  "items": [
    {
      "sys": { //…
      },
      "fields": {
        "title": "My apple title!",
        "tags": [
          "Apple"
        ]
      }
    }
  ]
}

for me … :smiley:

I hope it does work for you too. Please let us know your results, if you got any … :smiley:

Hi!

For most cases this work but it does introduce a potential bug. Let’s say one blog post has the tag “Green apples”, then that post shouldn’t be returned by the query but using [match] it will. Any ideas?

We would also like a way of doing a case insensitive equals search. As the [match] operator is not an exact match, it searches anywhere within the string its not really a viable option for us.

We had a problem last week where content was setup with tags all in UPPERCASE, however the tag configuration within our own database to link to that content was entered in lowercase, causing a bit of a problem when no content was found.

We are going to implement steps to enforce the same casing on both sides, but it would be great if there was a case insensitive equals operator we could use and not have to worry about the case.

Did anyone find a solution to this? My current solution is to use match and then filter the response in my application since I get too many entries in my result (for the reason joelabrahamsson pointed out above).

Hi, Did anyone find a solution to this in graphql for an equals operator?

By the looks of this, I am assuming there is no way to to case insensitive filtering? I am having the same issue, where I am treating the a blog title as the document id (just to make URLs more SEO-friendly). But, match is not doing it for me.

1 Like

Just in case anyone is still trying to find out about this:
In Graphql you can use fields.name_contains
Contains works for me