Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/CHANGELOG.txt,v
retrieving revision 1.1.2.112.2.12
diff -u -p -r1.1.2.112.2.12 CHANGELOG.txt
--- CHANGELOG.txt	5 Nov 2009 17:24:43 -0000	1.1.2.112.2.12
+++ CHANGELOG.txt	6 Nov 2009 09:17:03 -0000
@@ -1,10 +1,12 @@
-// $Id: CHANGELOG.txt,v 1.1.2.112.2.12 2009/11/05 17:24:43 claudiucristea Exp $
+// $Id: CHANGELOG.txt,v 1.1.2.112.2.11 2009/11/05 17:17:21 claudiucristea Exp $
 
 Apache Solr Search Integration x.x-x.x, xxxx-xx-xx
 ------------------------------
 
 Apache Solr Search integration 5.x-2.x, 2009-10-23
 ------------------------------
+#576040 by robertDouglass, Use Drush to download the SolrPhpClient: drush solr phpclient.
+#570476 by robertDouglass, Add initial Drush support with commands drush solr delete index and drush solr reindex.
 #612024 by pwolanin, Add method to allow requests to additional Solr servelets.
 #614048 by claudiu.cristea, Node access not working (only for 5.x-2.x).
 #621922 by robertDouglass make the "Show more" js more robust.
Index: apachesolr.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.admin.inc,v
retrieving revision 1.1.2.32.2.7
diff -u -p -r1.1.2.32.2.7 apachesolr.admin.inc
--- apachesolr.admin.inc	23 Oct 2009 11:47:03 -0000	1.1.2.32.2.7
+++ apachesolr.admin.inc	6 Nov 2009 09:17:04 -0000
@@ -406,12 +406,20 @@ function apachesolr_delete_index_confirm
 /**
  * Utility function to delete the index and reset all index counters.
  *
+ * @param $type
+ *   a single content type to be deleted from the index.
+ *
  * @throws Exception
  */
-function apachesolr_delete_index() {
+function apachesolr_delete_index($type = NULL) {
   // Instantiate a new Solr object.
   $solr = apachesolr_get_solr();
-  $query = '*:*';
+  if ($type) {
+    $query = 'type:' . $type;
+  }
+  else {
+    $query = '*:*';
+  }
   // Allow other modules to modify the delete query.
   // For example, use the site hash so that you only delete this site's
   // content:  $query = 'hash:' . apachesolr_site_hash()
Index: apachesolr.drush.inc
===================================================================
RCS file: apachesolr.drush.inc
diff -N apachesolr.drush.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ apachesolr.drush.inc	6 Nov 2009 09:17:04 -0000
@@ -0,0 +1,151 @@
+<?php
+// $Id: apachesolr.drush.inc,v 1.1.2.4 2009/09/15 13:33:04 robertDouglass Exp $
+
+/**
+ * @file
+ *   drush integration for apachesolr.
+ */
+
+/**
+ * Implementation of hook_drush_command().
+ *
+ * In this hook, you specify which commands your
+ * drush module makes available, what it does and
+ * description.
+ *
+ * Notice how this structure closely resembles how
+ * you define menu hooks.
+ *
+ * @See drush_parse_command() for a list of recognized keys.
+ *
+ * @return
+ *   An associative array describing your command(s).
+ */
+function apachesolr_drush_command() {
+  $items = array();
+
+  // the key in the $items array is the name of the command.
+  $items['solr delete index'] = array(
+    // the name of the function implementing your command.
+    'callback' => 'apachesolr_drush_solr_delete_index',
+    // a short description of your command
+    'description' => dt('Deletes the content from the index. Can take content types as parameters.'),
+    'arguments' => array(
+      'types' => dt('Optional. A space delimited list of content types to be deleted from the index.'),
+    ),
+  );
+  $items['solr reindex'] = array(
+    // the name of the function implementing your command.
+    'callback' => 'apachesolr_drush_solr_reindex',
+    // a short description of your command
+    'description' => dt('Marks content for reindexing. Can take content types as parameters.'),
+    'arguments' => array(
+      'types' => dt('Optional. A space delimited list of content types to be marked for reindexing.'),
+    ),
+  );
+  $items['solr phpclient'] = array(
+    'callback' => 'apachesolr_drush_solr_phpclient',
+    'description' => dt('Downloads the required SolrPhpClient from googlecode.com.'),
+    'arguments' => array(
+      'path' => dt('Optional. A path to the apachesolr module. If omitted Drush will use the default location.'),
+    ),
+  );
+  $items['solr search'] = array(
+    'callback' => 'apachesolr_drush_solr_search',
+    'description' => dt('Search the site for keywords using Apache Solr'),
+    'arguments' => array(
+      'keywords' => dt('One or more keywords, separated by spaces.'),
+    ),
+  );
+  return $items;
+}
+
+/**
+ * Implementation of hook_drush_help().
+ *
+ * This function is called whenever a drush user calls
+ * 'drush help <name-of-your-command>'
+ *
+ * @param
+ *   A string with the help section (prepend with 'drush:')
+ *
+ * @return
+ *   A string with the help text for your command.
+ */
+function apachesolr_drush_help($section) {
+  switch ($section) {
+    case 'drush:solr delete index':
+      return dt("Used without parameters, this command deletes the entire Solr index. Used with parameters for content type, it deletes just the content types that are specified. After the index has been deleted, all content will be indexed again on future cron runs.");
+    case 'drush:solr reindex':
+      return dt("Used without parameters, this command marks all of the content in the Solr index for reindexing. Used with paramters for content type, it marks just the content types that are specified. Reindexing is different than deleting as the content is still searchable while it is in queue to be reindexed. Reindexing is done on future cron runs.");
+    case 'drush:solr phpclient':
+      return dt("Downloads the SolrPhpClient libraray from googlecode.com. Include the optional path to an apachesolr module installation if you have more than one, or if the module is not yet enabled.");
+    case 'drush:solr search':
+      return dt('Executes a search against the site\'s Apache Solr search index and returns the restults.');
+  }
+}
+
+/**
+ * Example drush command callback.
+ *
+ * This is where the action takes place.
+ *
+ * In this function, all of Drupals API is (usually) available, including
+ * any functions you have added in your own modules/themes.
+ *
+ * To print something to the terminal window, use drush_print().
+ *
+ */
+function apachesolr_drush_solr_delete_index() {
+  $args = func_get_args();
+  $path = drupal_get_path('module', 'apachesolr');
+  include_once($path . "/apachesolr.admin.inc");
+  if (count($args) > 0) {
+    foreach ($args as $type) {
+      apachesolr_delete_index($type);
+    }
+  }
+  else {
+    apachesolr_delete_index();
+  }
+}
+
+function apachesolr_drush_solr_reindex() {
+  $args = func_get_args();
+  if (count($args) > 0) {
+    foreach ($args as $type) {
+      apachesolr_rebuild_index_table($type);
+    }
+  }
+  else {
+    apachesolr_rebuild_index_table();
+  }
+}
+
+function apachesolr_drush_solr_phpclient() {
+  $args = func_get_args();
+  if ($args[0]) {
+    $path = $args[0];
+  }
+  else {
+    $path = drupal_get_path('module', 'apachesolr');
+  }
+  drush_op('chdir', $path);
+  if (drush_shell_exec('svn export -r6 http://solr-php-client.googlecode.com/svn/trunk/ SolrPhpClient')) {
+    drush_log(dt('SolrPhpClient has been downloaded to @path', array('@path' => $path)), 'success');
+  }
+  else {
+    drush_log(dt('Drush was unable to download the SolrPhpClient to @path', array('@path' => $path)), 'error');
+  }
+}
+
+function apachesolr_drush_solr_search() {
+  $args = func_get_args();
+  $keys = implode(' ', $args);
+  foreach(apachesolr_search_execute($keys) as $result) {
+    $output = 'node/' . $result['node']->nid . ' ' . dt('by @name (user/@uid)', array('@name' => strip_tags($result['user']), '@uid' => $result['node']->uid)) . "\n";
+    $output .= dt('title: ') .  $result['title'] . "\n";
+    $output .= preg_replace('/[\s]+/', ' ', strip_tags($result['snippet'])) . "\n\n";
+    drush_print($output);
+  }
+}
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.161.2.8
diff -u -p -r1.1.2.12.2.161.2.8 apachesolr.module
--- apachesolr.module	5 Nov 2009 17:24:43 -0000	1.1.2.12.2.161.2.8
+++ apachesolr.module	6 Nov 2009 09:17:04 -0000
@@ -279,18 +279,30 @@ function apachesolr_clear_last_index($na
  * Truncate and rebuild the apachesolr_search_node table, reset the apachesolr_index_last variable.
  * This is the most complete way to force reindexing, or to build the indexing table for the
  * first time.
+ *
+ * @param $type
+ *   A single content type to be reindexed, leaving the others unaltered.
  */
-function apachesolr_rebuild_index_table() {
-  db_query("DELETE FROM {apachesolr_search_node}");
-  // Populate table
-  db_query("INSERT INTO {apachesolr_search_node} (nid, status, changed)
-            SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed
-            FROM {node} n
-            LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid");
-   // Make sure no nodes end up with a timestamp that's in the future.
-   $time = time();
-   db_query("UPDATE {apachesolr_search_node} SET changed = %d WHERE changed > %d", $time, $time);
-   apachesolr_clear_last_index();
+function apachesolr_rebuild_index_table($type = NULL) {
+  if (isset($type)) {
+    db_query("DELETE FROM {apachesolr_search_node} WHERE nid IN (SELECT nid FROM {node} WHERE type = '%s')", $type);
+    // Populate table
+    db_query("INSERT INTO {apachesolr_search_node} (nid, status, changed)
+              SELECT n.nid, n.status, %d AS changed
+              FROM {node} n WHERE n.type = '%s'", time(), $type);
+  }
+  else {
+    db_query("DELETE FROM {apachesolr_search_node}");
+    // Populate table
+    db_query("INSERT INTO {apachesolr_search_node} (nid, status, changed)
+              SELECT n.nid, n.status, GREATEST(n.created, n.changed, c.last_comment_timestamp) AS changed
+              FROM {node} n
+              LEFT JOIN {node_comment_statistics} c ON n.nid = c.nid");
+    // Make sure no nodes end up with a timestamp that's in the future.
+    $time = time();
+    db_query("UPDATE {apachesolr_search_node} SET changed = %d WHERE changed > %d", $time, $time);
+    apachesolr_clear_last_index();
+  }
 }
 
 function _apachesolr_exclude_types($namespace) {
