Class: Huginn::Generators::FtsIndexesGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Huginn::Generators::FtsIndexesGenerator
- Includes:
- SearchableColumns
- Defined in:
- lib/generators/huginn/fts_indexes/fts_indexes_generator.rb
Overview
Scaffolds a migration that creates the PostgreSQL GIN tsvector indexes (on an IMMUTABLE wrapper around to_tsvector) backing Huginn::Searchable's :full_text strategy for every model that includes Huginn::Searchable.
rails g huginn:fts_indexes # all Searchable models
rails g huginn:fts_indexes Person Product # specific models
rails g huginn:fts_indexes --dictionary english # pick the dictionary
The migration creates an IMMUTABLE public.f_tsvector(text) wrapper that pins the configured dictionary and the GIN indexes. Point the gem at the wrapper (to_tsvector itself is STABLE and cannot be indexed directly):
Huginn.configure { |c| c.search_strategy = :full_text;
c.fts_dictionary = "portuguese";
c.fts_function = "public.f_tsvector" }
Apply the same searchable model/association resolution as the trigram generator, so both index sets cover identical columns.
Instance Method Summary collapse
Instance Method Details
#copy_migration ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/huginn/fts_indexes/fts_indexes_generator.rb', line 37 def copy_migration @entries = resolve_entries @dictionary = [:dictionary] return if @entries.empty? migration_template( "add_huginn_fts_indexes.rb.tt", "db/migrate/add_huginn_fts_indexes.rb" ) end |