# frozen_string_literal: true # La representación indexable de un artículo class IndexedPost < ApplicationRecord include PgSearch::Model # La traducción del locale según Sutty al locale según PostgreSQL DICTIONARIES = { es: 'spanish', en: 'english' }.freeze # TODO: Los indexed posts tienen que estar scopeados al idioma actual, # no buscar sobre todos pg_search_scope :search, lambda { |locale, query| { against: :content, query: query, using: { tsearch: { dictionary: IndexedPost.to_dictionary(locale: locale), tsvector_column: 'indexed_content' } } } } belongs_to :site # Convertir locale a direccionario de PG # # @param [String,Symbol] # @return [String] def self.to_dictionary(locale:) DICTIONARIES[locale.to_sym] || 'simple' end end