Skip to content

Instantly share code, notes, and snippets.

@michelson
Created September 13, 2011 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michelson/875756b52b3af05511e9 to your computer and use it in GitHub Desktop.
Save michelson/875756b52b3af05511e9 to your computer and use it in GitHub Desktop.
class Cause < ActiveRecord::Base
belongs_to :user
belongs_to :causable, :polymorphic => true
belongs_to :civil, :class_name => "Cause::Civil", :foreign_key => "causable_id"
mapping do
indexes :user, :type => 'multi_field', :fields => {
:user => { :type => "string", :analyzer => "snowball" },
:"user.exact" => { :type => "string", :index => :not_analyzed }
}
indexes :civil do
indexes :rol, :type => 'string'
indexes :tribunal, :type => 'string', :boost => 100
end
end
## elastic search build
def to_indexed_json
{
:user => user.full_name,
:civil => {
:tribunal => causable.tribunal.name,
:caratulado => causable.caratulado,
:fecha => causable.fecha,
:rol => causable.rol
}
}.to_json
end
## causes schema
create_table "causes", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.integer "causable_id"
t.string "causable_type"
t.boolean "activated"
t.integer "update_trackers_count", :default => 0
end
#causes civil schema
create_table "cause_civils", :force => true do |t|
t.string "rol"
t.string "rol_link"
t.string "fecha"
t.string "caratulado"
t.string "tribunal_id"
t.text "noko"
t.datetime "created_at"
t.datetime "updated_at"
t.text "updates"
t.date "reviewed_at"
t.integer "review_number", :default => 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment