@regexp vs @trigram


I am using slash-gql and string types have all the regular search terms and then they have both regexp and trigram.
Can you explain what is the meaning of them and why they both there?
I could only find an explanation on regexp in the docs under the search section

I haven’t seen @regexp or @trigram directive in GraphQL.

It’s @search(by: [regexp])!

Regular expressions require the trigram index. A trigram is a substring of 3 consecutive characters, or runes.
The trigrams of trigram are: tri, rig, igr, gra and ram.

Refer: https://dgraph.io/tour/search/3/

TL;DR: Trigram is an indexing technique that allows Regular expression searches to work on strings. See documentation for String Search.

so if I use @search(by: [regexp]) I must add the trigram - @search(by: [regexp,trigram]) ?

No, trigram is internal to Dgraph. It’s a technique used to create index, by breaking up the string.

So all you need is: @search(by: [regexp]).

ok so do you know why the trigram checkbox appears in the slash-gql interface?

No, they are both the same thing. We support the name trigram to maintain backward compatibility. If trigram appears in Slash GraphQL interface we should fix it to read regexp instead. Tagging @gja

1 Like

ok thank you