diff --git a/apachesolr.admin.inc b/apachesolr.admin.inc
index c289638..c280cae 100644
--- a/apachesolr.admin.inc
+++ b/apachesolr.admin.inc
@@ -960,13 +960,14 @@ function apachesolr_index_action_form_delete_confirm_submit($form, &$form_state)
 /**
  * Submit a batch job to index the remaining, unindexed content.
  */
-function apachesolr_index_batch_index_remaining($env_id) {
+function apachesolr_index_batch_index_remaining($env_id, $total_limit = null) {
   $batch = array(
     'operations' => array(
       array(
         'apachesolr_index_batch_index_entities',
         array(
           $env_id,
+          $total_limit,
         ),
       ),
     ),
@@ -982,8 +983,14 @@ function apachesolr_index_batch_index_remaining($env_id) {
 
 /**
  * Batch Operation Callback
+ *
+ * @param $env_id
+ *   The machine name of the environment
+ * @param $total_limit
+ *   The total number of items to index across all batches
+ * @param $context
  */
-function apachesolr_index_batch_index_entities($env_id, &$context) {
+function apachesolr_index_batch_index_entities($env_id, $total_limit = NULL, &$context) {
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
   if (empty($context['sandbox'])) {
     try {
@@ -1002,13 +1009,25 @@ function apachesolr_index_batch_index_entities($env_id, &$context) {
     $status = apachesolr_index_status($env_id);
     $context['sandbox']['progress'] = 0;
     $context['sandbox']['submitted'] = 0;
-    $context['sandbox']['max'] = $status['remaining'];
+
+    // How many items do we want to index? All or a limited set of items
+    if (empty($total_limit)) {
+      $context['sandbox']['max'] = $status['remaining'];
+    }
+    else {
+      $context['sandbox']['max'] = $total_limit;
+    }
   }
 
   // We can safely process the apachesolr_cron_limit nodes at a time without a
   // timeout or out of memory error.
   $limit = variable_get('apachesolr_cron_limit', 50);
 
+  // Reduce the limit for our final batch if we would be processing more than had been requested
+  if ($limit + $context['sandbox']['progress'] > $context['sandbox']['max']) {
+    $limit = $context['sandbox']['max'] - $context['sandbox']['progress'];
+  }
+
   if ($context['sandbox']['max'] >= $context['sandbox']['progress'] + $limit) {
     $context['sandbox']['progress'] += $limit;
   }
diff --git a/apachesolr.api.php b/apachesolr.api.php
old mode 100755
new mode 100644
diff --git a/drush/apachesolr.drush.inc b/drush/apachesolr.drush.inc
index 0c580bd..a32c932 100644
--- a/drush/apachesolr.drush.inc
+++ b/drush/apachesolr.drush.inc
@@ -20,6 +20,9 @@ function apachesolr_drush_command() {
     'arguments' => array(
       'types' => dt('Optional. A space delimited list of content types to be deleted from the index.'),
     ),
+    'options' => array(
+      'environment-id' => 'The environment ID',
+    ),
     'examples' => array(
       'drush solr-delete-index node' => 'Delete all node content from the index.',
       'drush solr-delete-index node:article' => 'Delete all content of the article content type from the index.',
@@ -32,10 +35,17 @@ function apachesolr_drush_command() {
     'arguments' => array(
       'types' => dt('Optional. A space delimited list of content types to be marked for reindexing.'),
     ),
+    'options' => array(
+      'environment-id' => 'The environment ID',
+    ),
   );
   $items['solr-index'] = array(
     'callback' => 'apachesolr_drush_solr_index',
     'description' => dt('Reindexes content marked for (re)indexing.'),
+    'options' => array(
+      'environment-id' => 'The environment ID',
+      'limit' => 'The total number of documents to index',
+    ),
   );
   $items['solr-get-last-indexed'] = array(
     'callback' => 'apachesolr_drush_solr_get_last_indexed',
@@ -198,7 +208,10 @@ function apachesolr_drush_help($section) {
 function apachesolr_drush_solr_delete_index() {
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
   $args = func_get_args();
-  $env_id = apachesolr_default_environment();
+  $env_id =  drush_get_option('environment-id');
+  if (empty($env_id)) {
+    $env_id = apachesolr_default_environment();
+  }
 
   if (count($args) > 0) {
     foreach ($args as $type) {
@@ -224,7 +237,10 @@ function apachesolr_drush_solr_delete_index() {
 function apachesolr_drush_solr_mark_for_reindex() {
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
   $args = func_get_args();
-  $env_id = apachesolr_default_environment();
+  $env_id =  drush_get_option('environment-id');
+  if (empty($env_id)) {
+    $env_id = apachesolr_default_environment();
+  }
   if (count($args) > 0) {
     foreach ($args as $type) {
       apachesolr_index_mark_for_reindex($env_id, $type);
@@ -239,8 +255,12 @@ function apachesolr_drush_solr_mark_for_reindex() {
 function apachesolr_drush_solr_index() {
   module_load_include('inc', 'apachesolr', 'apachesolr.admin');
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
-  $env_id = apachesolr_default_environment();
-  apachesolr_index_batch_index_remaining($env_id);
+  $env_id =  drush_get_option('environment-id');
+  if (empty($env_id)) {
+    $env_id = apachesolr_default_environment();
+  }
+  $total_limit = intval(drush_get_option('limit'));
+  apachesolr_index_batch_index_remaining($env_id, $total_limit);
   drush_backend_batch_process();
 }
 
diff --git a/tests/solr_index_and_search.test b/tests/solr_index_and_search.test
old mode 100755
new mode 100644
