Sha256: 0982af31a667eddbfcd80595961626f20d1ab9c6b3dd142cfad7cec1282a3902
Contents?: true
Size: 1.29 KB
Versions: 20
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true module Decidim module Proposals # Class used to retrieve similar proposals. class SimilarProposals < Rectify::Query include Decidim::TranslationsHelper # Syntactic sugar to initialize the class and return the queried objects. # # components - Decidim::CurrentComponent # proposal - Decidim::Proposals::Proposal def self.for(components, proposal) new(components, proposal).query end # Initializes the class. # # components - Decidim::CurrentComponent # proposal - Decidim::Proposals::Proposal def initialize(components, proposal) @components = components @proposal = proposal end # Retrieves similar proposals def query Decidim::Proposals::Proposal .where(component: @components) .published .where( "GREATEST(#{title_similarity}, #{body_similarity}) >= ?", @proposal.title, @proposal.body, Decidim::Proposals.similarity_threshold ) .limit(Decidim::Proposals.similarity_limit) end private def title_similarity "similarity(title, ?)" end def body_similarity "similarity(body, ?)" end end end end
Version data entries
20 entries across 20 versions & 1 rubygems