Class: Decidim::SimilarEmendations

Inherits:
Rectify::Query
  • Object
show all
Includes:
TranslationsHelper
Defined in:
decidim-core/app/queries/decidim/similar_emendations.rb

Overview

Class used to retrieve similar emendations, scoped to the current component.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Constructor Details

#initialize(amendment) ⇒ SimilarEmendations

Initializes the class.

amendment - Decidim::Amendment


18
19
20
21
22
# File 'decidim-core/app/queries/decidim/similar_emendations.rb', line 18

def initialize(amendment)
  @component = amendment.amendable.component
  @emendation = amendment.emendation
  @amender = amendment.amender
end

Class Method Details

.for(amendment) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

amendment - Decidim::Amendment


11
12
13
# File 'decidim-core/app/queries/decidim/similar_emendations.rb', line 11

def self.for(amendment)
  new(amendment).query
end

Instance Method Details

#queryObject

Retrieves similar emendations


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-core/app/queries/decidim/similar_emendations.rb', line 25

def query
  emendation.class
            .where(component: component)
            .only_visible_emendations_for(amender, component)
            .published
            .not_hidden
            .where(
              "GREATEST(#{title_similarity}, #{body_similarity}) >= ?",
              translated_attribute(emendation.title),
              translated_attribute(emendation.body),
              amendable_module.similarity_threshold
            )
            .limit(amendable_module.similarity_limit)
end