refactors the way debate searches are done
This commit is contained in:
@@ -6,6 +6,7 @@ class Debate < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
include PgSearch
|
||||
include SearchCache
|
||||
include Filterable
|
||||
|
||||
apply_simple_captcha
|
||||
@@ -41,21 +42,23 @@ class Debate < ActiveRecord::Base
|
||||
visitable # Ahoy will automatically assign visit_id on create
|
||||
|
||||
pg_search_scope :pg_search, {
|
||||
against: {
|
||||
title: 'A',
|
||||
description: 'B'
|
||||
},
|
||||
associated_against: {
|
||||
tags: :name
|
||||
},
|
||||
against: :ignored, # not used since the using: option has a tsvector_column
|
||||
using: {
|
||||
tsearch: { dictionary: "spanish" },
|
||||
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',
|
||||
tag_list.join(' ') => 'B',
|
||||
description => 'D'
|
||||
}
|
||||
end
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
|
||||
13
db/migrate/20160204134022_add_tsvector_to_debates.rb
Normal file
13
db/migrate/20160204134022_add_tsvector_to_debates.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class AddTsvectorToDebates < ActiveRecord::Migration
|
||||
|
||||
def up
|
||||
add_column :debates, :tsv, :tsvector
|
||||
add_index :debates, :tsv, using: "gin"
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :debates, :tsv
|
||||
remove_column :debates, :tsv
|
||||
end
|
||||
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
ActiveRecord::Schema.define(version: 20160204134022) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -120,6 +120,7 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
t.integer "confidence_score", default: 0
|
||||
t.string "external_link", limit: 100
|
||||
t.integer "geozone_id"
|
||||
t.tsvector "tsv"
|
||||
end
|
||||
|
||||
add_index "debates", ["author_id", "hidden_at"], name: "index_debates_on_author_id_and_hidden_at", using: :btree
|
||||
@@ -134,6 +135,7 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
|
||||
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
|
||||
add_index "debates", ["title"], name: "index_debates_on_title", using: :btree
|
||||
add_index "debates", ["tsv"], name: "index_debates_on_tsv", using: :gin
|
||||
|
||||
create_table "delayed_jobs", force: :cascade do |t|
|
||||
t.integer "priority", default: 0, null: false
|
||||
|
||||
Reference in New Issue
Block a user