if Server.itself?(PP2_SERVER_NAME)

  # Two definitions of index to avoid error with a big single one (occured on PP2 when close to 100 millions of pictures)
  ThinkingSphinx::Index.define(:image, name: 'image_1', with: :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta) do

    indexes :title, :subject, :instructions, :creator, :city, :country, :state
    indexes :headline, :credit, :source, :file_name, :description
    indexes :reportage, :normalized_credit
    indexes :rights, :category, :supplemental_category
    indexes :original_filename, sortable: true
    # attributes
    has :ratio, :reception_date, :created_at, :updated_at, :private_image, :content_error, :erasable
    has :fonds, :black_and_white, :flow
    has :provider_id, facet: true
    has "(((TO_DAYS(`images`.`date_created`) * 86400) + TIME_TO_SEC(`images`.`date_created`)) - (TO_DAYS('1970-01-01') * 86400) + (unix_timestamp(utc_timestamp()) - unix_timestamp()))",
        as: :date_created, type: :bigint

    where "ratio <= 1.49"
  end

  ThinkingSphinx::Index.define(:image, name: 'image_2', with: :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta) do

    indexes :title, :subject, :instructions, :creator, :city, :country, :state
    indexes :headline, :credit, :source, :file_name, :description
    indexes :reportage, :normalized_credit
    indexes :rights, :category, :supplemental_category
    indexes :original_filename, sortable: true
    # attributes
    has :ratio, :reception_date, :created_at, :updated_at, :private_image, :content_error, :erasable
    has :fonds, :black_and_white, :flow
    has :provider_id, facet: true
    has "(((TO_DAYS(`images`.`date_created`) * 86400) + TIME_TO_SEC(`images`.`date_created`)) - (TO_DAYS('1970-01-01') * 86400) + (unix_timestamp(utc_timestamp()) - unix_timestamp()))",
        as: :date_created, type: :bigint

    where "ratio > 1.49"
  end

else

  ThinkingSphinx::Index.define(:image, with: :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta) do
    indexes :title, :subject, :instructions, :creator, :city, :country, :state
    indexes :headline, :credit, :source, :file_name, :description
    indexes :reportage, :normalized_credit
    indexes :rights, :category, :supplemental_category
    indexes :original_filename, sortable: true
    # attributes
    has :ratio, :reception_date, :created_at, :updated_at, :private_image, :content_error, :erasable
    has :fonds, :black_and_white, :flow, :pp_category_id
    has :provider_id, facet: true
    has "(((TO_DAYS(`images`.`date_created`) * 86400) + TIME_TO_SEC(`images`.`date_created`)) - (TO_DAYS('1970-01-01') * 86400) + (unix_timestamp(utc_timestamp()) - unix_timestamp()))",
        as: :date_created, type: :bigint
  end

end
