- Why Dgraph
Dgraph GraphQL Tour
Regular expressions require the
regexp search by directive which applies a
trigram index. A trigram is a substring of three consecutive characters, or runes.
The trigrams of “trigram” are: “tri”, “rig”, “igr”, “gra” and “ram”.
Valid regular expressions can be converted to a trigram query against a search index. Dgraph searches the trigram index for possible matches and then runs the full regular expression against the possibles, requiring that at least one matching trigram is found.
It’s a good idea to think carefully about how and whether you want to use regular expression queries. The more possible trigrams matched by a query, the more results are checked against the full regular expression and the less efficient the query. The reverse, however, is also true: The more trigrams enforced by the regular expression, the better use Dgraph can make of the index, and the smaller the possible results set.
Therefore, writing efficient regular expressions generally means making use of long substrings and avoiding as much alternate choice as possible.
i may follow the final
/ to indicate case insensitive search.
Let’s query for lines that match the pattern of three upper case characters together.