Just like any other index, GIN can be extended. The following strategies are available:
Operation |
Strategy number |
Overlap |
1 |
Contains |
2 |
Is contained by |
3 |
Equal |
4 |
On top of this, the following support functions are available:
Function |
Description |
Support function number |
compare |
The compare function is similar to the same function you have seen in btrees. If two keys are compared, it returns -1 (lower), 0 (equal), or 1 (higher). |
1 |
extractValue |
Extracts keys from a value to be indexed. A value can have many keys. For example, a text value might consist of more than one word. |
2 |
extractQuery |
Extracts keys from a query condition. |
3 |
consistent |
Checks whether a value matches a query condition. |
4 |
comparePartial |
Compares a partial key from a query and a key from the index. Returns -1, 0, or 1 (similar to the same function supported by btrees). |
5 |
triConsistent |
Determines whether a value matches a query condition (ternary variant). It is optional if the consistent function is present. |
6 |
If you are looking for a good example of how to extend GIN, consider looking at the btree_gin module in the PostgreSQL contrib directory. It is a valuable source of information and a good way to start your own implementation.
If you are interested in full-text search, more information will be provided later on in this chapter.