class MedItem < ActiveRecord::Base
  attr_accessible :body, :description, :published, :published_at, :title

  validates_presence_of :body

  validates_presence_of :description
  validates_length_of :description, :maximum => 1024

  validates_presence_of :published_at

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

  default_scope order('published_at DESC')
  scope :visible_to_user, lambda { where(:published => true).where('published_at <= ?', Time.now).order("published_at DESC") }

  paginates_per 5

  define_index do
    indexes title
    #indexes body
    #indexes description
    #indexes catalogue_category(:title), as: :catalogue_category
    has published
    has published_at, sortable: true
    has updated_at
    #set_property field_weights: {
    #    title: 3,
    #    description: 1,
    #    body: 1
    #}
    #TODO set_property delta: true # 'delta:boolean' column should present
  end

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

  default_sphinx_scope :sphinx_default_scope


end
