Casecommons/pg_search

Multi-language indexing with searchable column and indexes for same Model

alex223125 opened this issue · 0 comments

Hi,

I'm using pg_search in my project and have 'searchable' column:

class AddSearchableColumnToEntities < ActiveRecord::Migration[7.0]
  def up
    execute <<-SQL
      ALTER TABLE entities
      ADD COLUMN searchable tsvector GENERATED ALWAYS AS (
        setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
        setweight(to_tsvector('english', coalesce(source_page_description,'')), 'B')
      ) STORED;
    SQL
  end

  def down
    remove_column :entities, :searchable
  end
end

Is it possible to create indexes if I'm expecting title and source_page_description being written in other languages, not only in English?

I also have search scope like this:

  include PgSearch::Model
  pg_search_scope :english_global_search,
                  against: {
                    title: 'A',
                    source_page_description: 'B'
                  },
                  using: {
                    tsearch: {
                      dictionary: 'english',
                      tsvector_column: 'searchable',
                      any_word: true,
                      prefix: true
                    }
                  }

I was looking for examples how I can achieve it with pg_search, but only found how to do it with English language.

Is it supported to have multi-language indexes on same model?

Many thanks!