Sha256: 53a9a92d5e75ccd9d08fd86a755b6ed6fac2f3caf6362e9b7250e8ec9d29e813

Contents?: true

Size: 1.56 KB

Versions: 64

Compression:

Stored size: 1.56 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::Model

    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" },
                    using: {
                      tsearch: { prefix: true }
                    },
                    order_within_rank: "datetime DESC"
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/models/decidim/searchable_resource.rb
decidim-core-0.28.4 app/models/decidim/searchable_resource.rb
decidim-core-0.27.9 app/models/decidim/searchable_resource.rb
decidim-core-0.29.0 app/models/decidim/searchable_resource.rb
decidim-core-0.28.3 app/models/decidim/searchable_resource.rb
decidim-core-0.27.8 app/models/decidim/searchable_resource.rb
decidim-core-0.29.0.rc4 app/models/decidim/searchable_resource.rb
decidim-core-0.29.0.rc3 app/models/decidim/searchable_resource.rb
decidim-core-0.29.0.rc2 app/models/decidim/searchable_resource.rb
decidim-core-0.29.0.rc1 app/models/decidim/searchable_resource.rb
decidim-core-0.28.2 app/models/decidim/searchable_resource.rb
decidim-core-0.27.7 app/models/decidim/searchable_resource.rb
decidim-core-0.28.1 app/models/decidim/searchable_resource.rb
decidim-core-0.27.6 app/models/decidim/searchable_resource.rb
decidim-core-0.26.10 app/models/decidim/searchable_resource.rb
decidim-core-0.26.9 app/models/decidim/searchable_resource.rb
decidim-core-0.28.0 app/models/decidim/searchable_resource.rb
decidim-core-0.27.5 app/models/decidim/searchable_resource.rb
decidim-core-0.28.0.rc5 app/models/decidim/searchable_resource.rb
decidim-core-0.28.0.rc4 app/models/decidim/searchable_resource.rb