Sha256: f33d3fdebd2f115cd50da9f9c9c09342628e127e800d84ce3c24717d0ae96128

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "pg_search"

module Decidim
  # A Searchable Resource.
  # This is a model to a PgSearch table that indexes all searchable resources.
  # This table is used to perform textual searches.
  #
  # Main attributes are:
  # - locale: One entry per locale is required, so each resource will be indexed once per locale.
  # - content_a: The most relevant textual content.
  # - content_b: The second most relevant textual content.
  # - content_c: The third most relevant textual content.
  # - content_d: The less relevant textual content.
  # - datetime:  The timestamp that places this resource in the line of time. Used as second criteria (first is text relevance) for sorting.
  #
  class SearchableResource < ApplicationRecord
    include PgSearch

    belongs_to :organization,
               foreign_key: "decidim_organization_id",
               class_name: "Decidim::Organization"
    belongs_to :scope,
               foreign_key: "decidim_scope_id",
               class_name: "Decidim::Scope",
               optional: true
    belongs_to :resource, polymorphic: true
    belongs_to :decidim_participatory_space, polymorphic: true, optional: true

    validates :locale, uniqueness: { scope: [:decidim_organization_id, :resource_type, :resource_id] }

    pg_search_scope :global_search,
                    against: { content_a: "A", content_b: "B", content_c: "C", content_d: "D" },
                    order_within_rank: "datetime DESC"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-core-0.15.2 app/models/decidim/searchable_resource.rb
decidim-core-0.15.1 app/models/decidim/searchable_resource.rb
decidim-core-0.15.0 app/models/decidim/searchable_resource.rb
decidim-core-0.14.4 app/models/decidim/searchable_resource.rb