Index: sphinxsearch.pages.inc
===================================================================
--- sphinxsearch.pages.inc	(revision 594)
+++ sphinxsearch.pages.inc	(working copy)
@@ -69,15 +69,8 @@
     if (!empty($search_results['error_message'])) {
       drupal_set_message($search_results['error_message'], 'error');
     }
-    // Display no results warning and render expanded search form.
-    $output = theme('box', t('Your search yielded no results'), sphinxsearch_help('sphinxsearch#noresults', drupal_help_arg()));
-    $output .= drupal_get_form('sphinxsearch_search_form', $search_options, FALSE);
   }
   else {
-    // Render collapsed search form and search results.
-    $output = drupal_get_form('sphinxsearch_search_form', $search_options);
-    $output .= theme('box', t('Search results'), theme('sphinxsearch_search_results', $search_options, $search_results));
-
     // Register flood event for non-admins.
     if (!$admin_access) {
       flood_register_event('sphinxsearch:search');
@@ -97,6 +90,9 @@
     }
   }
 
+  // Render search page
+  $output = theme('sphinxsearch_search_page', $search_options, $search_results);
+
   return $output;
 }
 
@@ -314,6 +310,30 @@
 }
 
 /**
+ * Format the search page
+ *
+ * @param array $search_options
+ *   Search options structure.
+ * @param array $search_results
+ *   Search results structure.
+ *
+ * @ingroup themeable
+ */
+function theme_sphinxsearch_search_page($search_options, $search_results) {
+  if ($search_results['total_available'] <= 0) {
+    // Display no results warning and render expanded search form.
+    $output = theme('box', t('Your search yielded no results'), sphinxsearch_help('sphinxsearch#noresults', drupal_help_arg()));
+    $output .= drupal_get_form('sphinxsearch_search_form', $search_options, FALSE);
+  }
+  else {
+    // Render collapsed search form and search results.
+    $output = drupal_get_form('sphinxsearch_search_form', $search_options);
+    $output .= theme('box', t('Search results'), theme('sphinxsearch_search_results', $search_options, $search_results));
+  }
+  return $output;
+}
+
+/**
  * Format the results page for the given query results array.
  *
  * @param array $search_options
Index: sphinxsearch.module
===================================================================
--- sphinxsearch.module	(revision 585)
+++ sphinxsearch.module	(working copy)
@@ -44,6 +44,9 @@
  */
 function sphinxsearch_theme() {
   return array(
+    'sphinxsearch_search_page' => array(
+      'arguments' => array('search_options' => NULL, 'search_results' => NULL),
+    ),
     'sphinxsearch_search_results' => array(
       'arguments' => array('search_options' => NULL, 'search_results' => NULL),
     ),