Forage.SearchPostgreSQL (forage v0.8.0)

Utilities to help with search in PostgreSQL databases. Support for other databases may be added in the future.

Link to this section Summary

Functions

Adds a trigram index for the given column in the given table.

Adds a GENERATED column to help with accent-insensitive search across several columns.

Adds a new column (named column_name) to the table. The new column will be a concatenation of the columns. The new column will be updated whenever any of the columns changes.

For use in migration files. Create the necessary extensions in the database.

Convert a search term into params that can be used in a forage plan. Search will be case-insensitive.

Convert a search term into params that can be used in a forage plan. Search will be case-insensitive and will ignore accents.

Link to this section Functions

Link to this function

add_trigram_index(table, column)

Adds a trigram index for the given column in the given table.

This function is meant to be used in a migration file.

example

Example

TODO

Link to this function

add_unaccented_search_column_and_index(table, search_column, columns)

Adds a GENERATED column to help with accent-insensitive search across several columns.

This column

Link to this function

add_unnaccented_search_column(table, column_name, columns)

Adds a new column (named column_name) to the table. The new column will be a concatenation of the columns. The new column will be updated whenever any of the columns changes.

This function is meant to be used in a migration file.

To be able to use this functions you must have already defined the forage_unaccent() PostgreSQL function. The reason why we can't use unaccent directly is quite obscure; you can read more aboute it here

example

Example

TODO

Link to this function

define_forage_unaccent()

For use in migration files. Create the necessary extensions in the database.

Link to this function

naive_search_params(params, field)

Convert a search term into params that can be used in a forage plan. Search will be case-insensitive.

This is implemented internally as an ILIKE operator. By default, the ILIKE operator doesn't ignore accents. If you want to ignore accents, you need to use unaccented_search_params/2 and prepare a special column in your database (see here).

If it makes sense for your application, you can implement better search yourself.

Link to this function

unaccented_search_params(params, field)

Convert a search term into params that can be used in a forage plan. Search will be case-insensitive and will ignore accents.

Currently this function requires PostgreSQL.

This is implemented internally as an ILIKE operator. Thus function calls the special forage_unaccent() function, which you should have defined somehwere in your PostgreSQL database.

If it makes sense for your application, you can implement better search yourself.