adds pg_search to spending proposals
This commit is contained in:
committed by
Juanjo Bazán
parent
d3ccc71c22
commit
cb681883f8
@@ -2,6 +2,7 @@ class SpendingProposal < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Sanitizable
|
||||
include Taggable
|
||||
include Searchable
|
||||
|
||||
apply_simple_captcha
|
||||
acts_as_votable
|
||||
@@ -53,6 +54,18 @@ class SpendingProposal < ActiveRecord::Base
|
||||
results.includes(:geozone, administrator: :user, valuators: :user)
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
author.username => 'B',
|
||||
geozone.try(:name) => 'B',
|
||||
description => 'C'
|
||||
}
|
||||
end
|
||||
|
||||
def self.search(terms)
|
||||
self.pg_search(terms)
|
||||
end
|
||||
|
||||
def self.by_geozone(geozone)
|
||||
if geozone == 'all'
|
||||
where(geozone_id: nil)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddTsvectorToSpendingProposals < ActiveRecord::Migration
|
||||
|
||||
def change
|
||||
add_column :spending_proposals, :tsv, :tsvector
|
||||
add_index :spending_proposals, :tsv, using: "gin"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160329115418) do
|
||||
ActiveRecord::Schema.define(version: 20160329160106) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -313,10 +313,12 @@ ActiveRecord::Schema.define(version: 20160329115418) do
|
||||
t.string "time_scope"
|
||||
t.datetime "unfeasible_email_sent_at"
|
||||
t.integer "cached_votes_up"
|
||||
t.tsvector "tsv"
|
||||
end
|
||||
|
||||
add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree
|
||||
add_index "spending_proposals", ["geozone_id"], name: "index_spending_proposals_on_geozone_id", using: :btree
|
||||
add_index "spending_proposals", ["tsv"], name: "index_spending_proposals_on_tsv", using: :gin
|
||||
|
||||
create_table "taggings", force: :cascade do |t|
|
||||
t.integer "tag_id"
|
||||
|
||||
Reference in New Issue
Block a user