Single Character String Filter

I tried to run this filter, which obviously does not work, as my name field is @search(by [term]) and my name is Julian :grinning_face_with_smiling_eyes: .

{
    "filter": {
        "name": {
            "anyofterms": "J"
        }
    }
}

My question is now, if there is an other way except regex to filter for single character or also show Julian when Julia was request.

A term is generally a β€œword” (by some definition of what a β€œword” is). "J" is a single letter of a word. anyofterms is not the correct index to use. You want to use trigram indexing

1 Like

Thanks for providing a solution. As I am not familiar with the term trigram indexing and my google search was way over my head, I would appreciate it, if you could provide a filter code example, how that would look :smiley:

@search(by [term, regexp])

queryYourType(filter: { name: { regexp: "/Julian?/" } }) { ... }

Regexp is a whole language within itself. This example with a question mark says to match with or without the β€œn” character. You could make it any character replacing β€œn” with β€œ.”

A regexp filter uses a trigram index under the hood which requires the regexp to be at least 3 characters.