class Project < ActiveRecord::Base
  attr_accessible :body, :completed_at, :customer, :description, :published, :title

  validates_length_of :customer, :maximum => 255

  validates_length_of :description, :maximum => 1024

  validates_presence_of :title
  validates_length_of :title, :maximum => 255

  default_scope order('completed_at DESC')
  scope :visible_to_user, lambda { where(:published => true) }

  define_index do
    indexes title
    #indexes description
    #indexes body
    indexes customer
    has published
    has completed_at, :sortable => true
    #TODO set_property delta: true # 'delta:boolean' column should present
    set_property field_weights: {
        title: 3,
        customer: 2,
        #description: 1,
        #body: 1
    }
  end

  sphinx_scope(:sphinx_default_scope) {
    {order: 'completed_at DESC', star: true}
  }

  default_sphinx_scope :sphinx_default_scope

end
