Full Text Search
Full text search plugin offers full integration with tsvector
capabilities of Postgresql.
It allows you to query models through the text content of one or multiple fields.
Let's assume we have a blog and want to implement full text search over title and content:
This migration will create a 3rd column named full_text_vector
of type tsvector
, a gin index, a trigger and a function to update automatically this column.
Over the on
keyword, '{"title", 'A'}'
means it allows search of the content of "title", with level of priority (weight) "A", which tells postgres than title content is more meaningful than the article content itself.
Now, let's build some models:
Search is now easily done
Obviously, search call can be chained:
Additional parameters
catalog
Select the catalog to use to build the tsquery
. By default, pg_catalog.english
is used.
For now, Clear doesn't offers dynamic selection of catalog (for let's say multi-lang service). If your app need this feature, do not hesitate to open an issue.
trigger_name, function_name
In migration, you can change the name generated for the trigger and the function, using theses two keys.
dest_field
The field created in the database, which will contains your ts vector. Default is full_text_vector
.
Last updated