moves search logic to a searchable module
This commit is contained in:
19
app/models/concerns/searchable.rb
Normal file
19
app/models/concerns/searchable.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Searchable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
include PgSearch
|
||||
include SearchCache
|
||||
|
||||
pg_search_scope :pg_search, {
|
||||
against: :ignored, # not used since using a tsvector_column
|
||||
using: {
|
||||
tsearch: { tsvector_column: 'tsv', dictionary: "spanish", prefix: true }
|
||||
},
|
||||
ignoring: :accents,
|
||||
ranked_by: '(:tsearch)',
|
||||
order_within_rank: "#{self.table_name}.cached_votes_up DESC"
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
@@ -5,8 +5,7 @@ class Debate < ActiveRecord::Base
|
||||
include Conflictable
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
include PgSearch
|
||||
include SearchCache
|
||||
include Searchable
|
||||
include Filterable
|
||||
|
||||
apply_simple_captcha
|
||||
@@ -41,16 +40,6 @@ class Debate < ActiveRecord::Base
|
||||
# Ahoy setup
|
||||
visitable # Ahoy will automatically assign visit_id on create
|
||||
|
||||
pg_search_scope :pg_search, {
|
||||
against: :ignored, # not used since the using: option has a tsvector_column
|
||||
using: {
|
||||
tsearch: { dictionary: "spanish", tsvector_column: 'tsv', prefix: true }
|
||||
},
|
||||
ignoring: :accents,
|
||||
ranked_by: '(:tsearch)',
|
||||
order_within_rank: "debates.cached_votes_up DESC"
|
||||
}
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
author.username => 'B',
|
||||
|
||||
@@ -4,8 +4,7 @@ class Proposal < ActiveRecord::Base
|
||||
include Conflictable
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
include PgSearch
|
||||
include SearchCache
|
||||
include Searchable
|
||||
include Filterable
|
||||
|
||||
apply_simple_captcha
|
||||
@@ -44,16 +43,6 @@ class Proposal < ActiveRecord::Base
|
||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
|
||||
pg_search_scope :pg_search, {
|
||||
against: :ignored, # not used since the using: option has a tsvector_column
|
||||
using: {
|
||||
tsearch: { dictionary: "spanish", tsvector_column: 'tsv', prefix: true }
|
||||
},
|
||||
ignoring: :accents,
|
||||
ranked_by: '(:tsearch)',
|
||||
order_within_rank: "proposals.cached_votes_up DESC"
|
||||
}
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
question => 'B',
|
||||
|
||||
Reference in New Issue
Block a user