# frozen_string_literal: true class VectorModel < ActiveRecord::Base include PgSearchable pg_search fields: %i[vector_models.id vector_models.name vector_models.value], cache: :search_cache end class VectorModelWithTwoDefaultColumns < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[vector_models.id vector_models.name vector_models.value], default_fields: %i[vector_models.name vector_models.value], cache: :search_cache end class VectorModelWithMappings < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[vector_models.id vector_models.name vector_models.value], fields_mappings: {device_id: "vector_models.id"}, cache: :search_cache end class VectorModelWithoutCallback < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[id name value], cache: :search_cache, skip_callback: true end class VectorWithCustomCallback < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[id name value], cache: :search_cache, skip_callback: true, external_cache_data: :colors after_save :update_pg_search_cache def colors %w[orange blue] end end class VectorWithCustomPrimaryKeyModel < ActiveRecord::Base include PgSearchable pg_search fields: %i[uuid name value] self.primary_key = :uuid before_save { self.uuid = SecureRandom.uuid } end class SimpleVectorModel < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[vector_models.id vector_models.name vector_models.value], cache: :search_cache, language: :simple end class VectorWithoutWildcardModel < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[id name value], cache: :search_cache, wildcard: false end class VectorModelWithCustomSearchScope < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[id name value], cache: :search_cache, scope: 'fulltext' end class VectorModelWithTagValues < ActiveRecord::Base self.table_name = :vector_models include PgSearchable pg_search fields: %i[id name value], cache: :search_cache, external_cache_data: :tag_values has_many :tags, as: :taggable def tag_values tags.pluck(:value) end end class DynamicModel < ActiveRecord::Base include PgSearchable pg_search fields: %i[id name value] end class DynamicModelWithTagValues < ActiveRecord::Base self.table_name = :dynamic_models include PgSearchable pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value], fields_mappings: {tag: 'tags.value'}, joins: [:tags] has_many :tags, as: :taggable end class DynamicModelWithTagAndCategories < ActiveRecord::Base self.table_name = :dynamic_models include PgSearchable pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value], fields_mappings: {tag: 'tags.value', category: 'categories.name'}, joins: [:tags, :categories] has_many :tags, as: :taggable has_many :categories, as: :categoriable end class DynamicModelWithTagValuesAndCustomAttribute < ActiveRecord::Base self.table_name = :dynamic_models include PgSearchable pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value], fields_mappings: {tag: 'tags.value', custom: 'tags.custom_attribute'}, joins: [:tags] has_many :tags, as: :taggable end class DynamicModelWithCategory < ActiveRecord::Base self.table_name = :dynamic_models include PgSearchable pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value tags.value categories.name], joins: { tags: :category } has_many :tags, as: :taggable end class DynamicModelWithSectionsTrhough < ActiveRecord::Base self.table_name = :dynamic_models include PgSearchable pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value tags.value sections.name], joins: [{ tags: :category }, :sections] has_many :tags, as: :taggable has_many :sections, through: :tags end class Tag < ActiveRecord::Base belongs_to :category has_many :sections belongs_to :taggable, polymorphic: true after_save { taggable.update_pg_search_cache if taggable.class.ts_cache_field.present? } end class Section < ActiveRecord::Base belongs_to :tag end class Category < ActiveRecord::Base has_many :tags belongs_to :categoriable, polymorphic: true end