Casecommons / pg_search

pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search
http://www.casebook.net
MIT License
1.3k stars 369 forks source link

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

Open alex223125 opened 1 year ago

alex223125 commented 1 year ago

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!