Index: apachesolr_search.substitute.inc
===================================================================
--- apachesolr_search.substitute.inc	(revision 0)
+++ apachesolr_search.substitute.inc	(revision 0)
@@ -0,0 +1,263 @@
+<?php
+// $Id$
+
+
+function _apachesolr_search_access() {
+  return user_access('access content') && user_access('use apachesolr_search');
+}
+
+/**
+ * Implementation of hook_theme()
+ */
+function search_theme() {
+  return array(
+    'search_theme_form' => array(
+      'arguments' => array('form' => NULL),
+      'template' => 'search-theme-form',
+    ),
+    'search_block_form' => array(
+      'arguments' => array('form' => NULL),
+      'template' => 'search-block-form',
+    ),
+    'search_result' => array(
+      'arguments' => array('result' => NULL, 'type' => NULL),
+      'file' => 'search.pages.inc',
+      'template' => 'search-result',
+    ),
+    'search_results' => array(
+      'arguments' => array('results' => NULL, 'type' => NULL),
+      'file' => 'search.pages.inc',
+      'template' => 'search-results',
+    ),
+  );
+}
+
+
+/**
+ * Implementation of hook_block().
+ */
+function search_block($op = 'list', $delta = 0) {
+  if ($op == 'list') {
+    $blocks[0]['info'] = t('Search form');
+    // Not worth caching.
+    $blocks[0]['cache'] = BLOCK_NO_CACHE;
+    return $blocks;
+  }
+  else if ($op == 'view' && user_access('search content')) {
+    $block['content'] = drupal_get_form('search_block_form');
+    $block['subject'] = t('Search');
+    return $block;
+  }
+}
+
+/**
+ * Helper function for grabbing search keys.
+ */
+function search_get_keys() {
+  static $return;
+  if (!isset($return)) {
+    // Extract keys as remainder of path
+    // Note: support old GET format of searches for existing links.
+    $path = explode('/', $_GET['q'], 3);
+    $keys = empty($_REQUEST['keys']) ? '' : $_REQUEST['keys'];
+    $return = count($path) == 3 ? $path[2] : $keys;
+  }
+  return $return;
+}
+
+/**
+ * @defgroup search Search interface
+ * @{
+ * The Drupal search interface manages a global search mechanism.
+ *
+ * Modules may plug into this system to provide searches of different types of
+ * data. Most of the system is handled by search.module, so this must be enabled
+ * for all of the search features to work.
+ *
+ * There are three ways to interact with the search system:
+ * - Specifically for searching nodes, you can implement nodeapi('update index')
+ *   and nodeapi('search result'). However, note that the search system already
+ *   indexes all visible output of a node, i.e. everything displayed normally
+ *   by hook_view() and hook_nodeapi('view'). This is usually sufficient.
+ *   You should only use this mechanism if you want additional, non-visible data
+ *   to be indexed.
+ * - Implement hook_search(). This will create a search tab for your module on
+ *   the /search page with a simple keyword search form. You may optionally
+ *   implement hook_search_item() to customize the display of your results.
+ * - Implement hook_update_index(). This allows your module to use Drupal's
+ *   HTML indexing mechanism for searching full text efficiently.
+ *
+ * If your module needs to provide a more complicated search form, then you need
+ * to implement it yourself without hook_search(). In that case, you should
+ * define it as a local task (tab) under the /search page (e.g. /search/mymodule)
+ * so that users can easily find it.
+ */
+
+/**
+ * Render a search form.
+ *
+ * @param $action
+ *   Form action. Defaults to "search".
+ * @param $keys
+ *   The search string entered by the user, containing keywords for the search.
+ * @param $type
+ *   The type of search to render the node for. Must be the name of module
+ *   which implements hook_search(). Defaults to 'node'.
+ * @param $prompt
+ *   A piece of text to put before the form (e.g. "Enter your keywords")
+ * @return
+ *   An HTML string containing the search form.
+ */
+function search_form(&$form_state, $action = '', $keys = '', $type = NULL, $prompt = NULL) {
+
+  // Add CSS
+  drupal_add_css(drupal_get_path('module', 'apachesolr_search') .'/apachesolr_search.css', 'module', 'all', FALSE);
+
+  if (!$action) {
+    $action = url('search/'. $type);
+  }
+  if (is_null($prompt)) {
+    $prompt = t('Enter your keywords');
+  }
+
+  $form = array(
+    '#action' => $action,
+    '#attributes' => array('class' => 'search-form'),
+  );
+  $form['module'] = array('#type' => 'value', '#value' => $type);
+  $form['basic'] = array('#type' => 'item', '#title' => $prompt);
+  $form['basic']['inline'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
+  $form['basic']['inline']['keys'] = array(
+    '#type' => 'textfield',
+    '#title' => '',
+    '#default_value' => $keys,
+    '#size' => $prompt ? 40 : 20,
+    '#maxlength' => 255,
+  );
+  // processed_keys is used to coordinate keyword passing between other forms
+  // that hook into the basic search form.
+  $form['basic']['inline']['processed_keys'] = array('#type' => 'value', '#value' => array());
+  $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
+
+  return $form;
+}
+
+/**
+ * Form builder; Output a search form for the search block and the theme's search box.
+ *
+ * @ingroup forms
+ * @see  apachesolr_search_block_form_submit()
+ * @see theme_search_box_form()
+ */
+function apachesolr_search_block_form(&$form_state) {
+  $form['apachesolr_search_block_form'] = array(
+    '#title' => t('Search this site'),
+    '#type' => 'textfield',
+    '#size' => 15,
+    '#default_value' => '',
+    '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
+  );
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
+
+  return $form;
+}
+
+/**
+ * Process a block search form submission.
+ */
+function apachesolr_search_block_form_submit($form, &$form_state) {
+  $form_id = $form['form_id']['#value'];
+  $form_state['redirect'] = 'search/node/'. trim($form_state['values'][$form_id]);
+}
+
+
+/**
+ * Process variables for search-block-form.tpl.php.
+ *
+ * The $variables array contains the following arguments:
+ * - $form
+ *
+ * @see search-block-form.tpl.php
+ */
+function template_preprocess_search_block_form(&$variables) {
+  $variables['search'] = array();
+  $hidden = array();
+  // Provide variables named after form keys so themers can print each element independently.
+  foreach (element_children($variables['form']) as $key) {
+    $type = $variables['form'][$key]['#type'];
+    if ($type == 'hidden' || $type == 'token') {
+      $hidden[] = drupal_render($variables['form'][$key]);
+    }
+    else {
+      $variables['search'][$key] = drupal_render($variables['form'][$key]);
+    }
+  }
+  // Hidden form elements have no value to themers. No need for separation.
+  $variables['search']['hidden'] = implode($hidden);
+  // Collect all form elements to make it easier to print the whole form.
+  $variables['search_form'] = implode($variables['search']);
+}
+
+/**
+ * Perform a standard search on the given keys, and return the formatted results.
+ */
+function search_data($keys = NULL, $type = 'node') {
+
+  if (isset($keys)) {
+    if (module_hook($type, 'search')) {
+      $results = module_invoke($type, 'search', 'search', $keys);
+      if (isset($results) && is_array($results) && count($results)) {
+        if (module_hook($type, 'search_page')) {
+          return module_invoke($type, 'search_page', $results);
+        }
+        else {
+          return theme('search_results', $results, $type);
+        }
+      }
+    }
+  }
+}
+
+
+
+function search_view($type = NULL) {
+  // Search form submits with POST but redirects to GET. This way we can keep
+  // the search query URL clean as a whistle:
+  // search/type/keyword+keyword
+  if (!empty($_POST)) {
+    // Allow Form API to handle submisstion
+    return drupal_get_form('search_form', NULL, '', $type);
+  }
+
+  if (!isset($type)) {
+    // Note: search/apachesolr_search can not be a default tab because it would take on the
+    // path of its parent (search). It would prevent remembering keywords when
+    // switching tabs. This is why we drupal_goto to it from the parent instead.
+    drupal_goto('search/apachesolr_search');
+  }
+
+  $keys = search_get_keys();
+  // Only perform search if there is non-whitespace search term:
+  $results = '';
+  if (trim($keys)) {
+    // Log the search keys:
+    watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));
+
+    // Collect the search results:
+    $results = search_data($keys, $type);
+
+    if ($results) {
+      $results = theme('box', t('Search results'), $results);
+    }
+    else {
+      $results = theme('box', t('Your search yielded no results'), search_help('search#noresults', drupal_help_arg()));
+    }
+  }
+
+  // Construct the search form.
+  $output = drupal_get_form('search_form', NULL, $keys, $type);
+  $output .= $results;
+
+  return $output;
+}
+

Property changes on: apachesolr_search.substitute.inc
___________________________________________________________________
Added: svn:executable
   + *

Index: apachesolr_search.module
===================================================================
--- apachesolr_search.module	(revision 4991)
+++ apachesolr_search.module	(working copy)
@@ -29,6 +29,15 @@ function apachesolr_search_help($section) {
 }
 
 /**
+ * Implementation of hook_init().
+ */
+function apachesolr_search_init() {
+  if (!module_exists('search')) {
+    require_once(drupal_get_path('module', 'apachesolr_search') . '/apachesolr_search.substitute.inc');
+  }
+}
+
+/**
  * Implementation of hook_menu().
  */
 function apachesolr_search_menu() {
@@ -49,10 +58,44 @@ function apachesolr_search_menu() {
     'file'             => 'apachesolr_search.admin.inc',
   );
 
+  if (!module_exists('search')) {
+    $items['search'] = array(
+      'title' => 'Search',
+      'page callback' => 'search_view',
+      'access callback' => '_apachesolr_search_access',
+      'type' => MENU_CALLBACK,
+    );
+    $items['search/apachesolr_search_path/%menu_tail'] = array(
+      'title' => 'Search',
+      'page callback' => 'search_view',
+      'page arguments' => array('apachesolr_search'),
+      'access callback' => '_apachesolr_search_access',
+      'type' => MENU_LOCAL_TASK,
+    );
+  }
   return $items;
 }
 
+function apachesolr_search_perm() {
+  return array('use apachesolr_search');
+}
+
 /**
+ * Implementation of hook_cron().
+ */
+function apachesolr_search_cron() {
+  // Update word index
+  if (!module_exists('search')) {
+    foreach (module_list() as $module) {
+      // Take care of this modle and any contrib modules.
+      if (strpos($module, 'apachesolr') === 0) {
+        module_invoke($module, 'update_index');
+      }
+    }
+  }
+}
+
+/**
  * Implementation of hook_update_index().
  */
 function apachesolr_search_update_index() {
@@ -425,6 +468,10 @@ function apachesolr_search_apachesolr_facets() {
  */
 function apachesolr_search_block($op = 'list', $delta = 0, $edit = array()) {
 
+  if ($op != 'list' && $delta == 'search') {
+    return module_exists('search') ? NULL : _apachesolr_search_block_substitute();
+  }
+
   switch ($op) {
     case 'list':
       $enabled_facets = apachesolr_get_enabled_facets('apachesolr_search');
@@ -440,6 +487,9 @@ function apachesolr_search_block($op = 'list', $de
         'info' => t('Apache Solr Search: Current search'),
         'cache' => BLOCK_CACHE_PER_PAGE,
       );
+      if (!module_exists('search')) {
+        
+      }
       return $blocks;
 
     case 'view':
Index: apachesolr_search.css
===================================================================
--- apachesolr_search.css	(revision 0)
+++ apachesolr_search.css	(revision 0)
@@ -0,0 +1,22 @@
+/* $Id: search.css,v 1.3 2007/10/31 18:06:38 dries Exp $ */
+
+.search-form {
+  margin-bottom: 1em;
+}
+.search-form input {
+  margin-top: 0;
+  margin-bottom: 0;
+}
+.search-results p {
+  margin-top: 0;
+}
+.search-results dt {
+  font-size: 1.1em;
+}
+.search-results dd {
+  margin-bottom: 1em;
+}
+.search-results .search-info {
+  font-size: 0.85em;
+}
+

Property changes on: apachesolr_search.css
___________________________________________________________________
Added: svn:executable
   + *

Index: apachesolr_search.info
===================================================================
--- apachesolr_search.info	(revision 4991)
+++ apachesolr_search.info	(working copy)
@@ -1,7 +1,6 @@
 ; $Id: apachesolr_search.info,v 1.1.2.1.2.7 2009/03/20 04:11:16 pwolanin Exp $
 name = Apache Solr search
 description = Search with Solr
-dependencies[] = search
 dependencies[] = apachesolr
 package = Apache Solr
 core = "6.x"
Index: apachesolr.info
===================================================================
--- apachesolr.info	(revision 4991)
+++ apachesolr.info	(working copy)
@@ -1,7 +1,6 @@
 ; $Id: apachesolr.info,v 1.1.2.1.2.8 2009/06/04 13:33:36 robertDouglass Exp $
 name = Apache Solr framework
 description = Framework for searching with Solr
-dependencies[] = search
 package = Apache Solr
 core = "6.x"
 php = 5.1.4
