Index: apachesolr.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.admin.inc,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 apachesolr.admin.inc
--- apachesolr.admin.inc	6 May 2009 16:34:19 -0000	1.1.2.17
+++ apachesolr.admin.inc	6 May 2009 18:17:11 -0000
@@ -373,7 +373,7 @@ function _apachesolr_field_name_map($fie
   if (!isset($map)) {
     $map = array(
       'body' => t('Body text - the full, rendered content'),
-      'title' => t('Content title'),
+      'title' => t('Title'),
       'name' => t('Author name'),
       'path_alias' => t('Path alias'),
       'taxonomy_names' => t('All taxonomy term names'),
Index: contrib/apachesolr_mlt/apachesolr_mlt.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_mlt/apachesolr_mlt.install,v
retrieving revision 1.1.4.4
diff -u -p -r1.1.4.4 apachesolr_mlt.install
--- contrib/apachesolr_mlt/apachesolr_mlt.install	10 Feb 2009 20:25:48 -0000	1.1.4.4
+++ contrib/apachesolr_mlt/apachesolr_mlt.install	6 May 2009 18:17:12 -0000
@@ -2,50 +2,23 @@
 //$Id: apachesolr_mlt.install,v 1.1.4.4 2009/02/10 20:25:48 pwolanin Exp $
 
 function apachesolr_mlt_install() {
-  // Create tables.
-  $pass = drupal_install_schema('apachesolr_mlt');
-  if ($pass) {
-    drupal_set_message(t('Created the apachesolr_mlt table'));
-    drupal_load('module', 'apachesolr_mlt');
-    $block = array(
-      'name' => t('More like this'),
-      'num_results' => '5',
-      'mlt_fl' =>  array(
-        'title' => 'title',
-        'taxonomy_names' => 'taxonomy_names',
-      ),
-      'mlt_mintf' => '1',
-      'mlt_mindf' => '1',
-      'mlt_minwl' => '3',
-      'mlt_maxwl' => '15',
-      'mlt_maxqt' => '30',
-    );
-    apachesolr_mlt_save_block($block, NULL);
-  }
+  drupal_load('module', 'apachesolr_mlt');
+  apachesolr_mlt_save_block(array('name' => t('More like this')));
 }
 
-function apachesolr_mlt_schema() {
-  $schema['apachesolr_mlt'] = array(
-    'description' => t('Tracks custom content recommendation blocks.'),
-    'fields' => array(
-      'id' => array(
-        'description' => t('The primary identifier for a custom block.'),
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE),
-      'data' => array(
-        'description' => t('The serialized data for a block.'),
-        'type' => 'text',
-        'size' => 'big',
-        'not null' => TRUE,
-      ),
-    ),
-    'primary key' => array('id'),
-  );
-  return $schema;
+function apachesolr_mlt_uninstall() {
+  // Remove settings..
+  variable_del('apachesolr_mlt_blocks');
 }
 
-function apachesolr_mlt_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('apachesolr_mlt');
+/**
+ * Move DB data to a variable for greater simplicity.
+ */
+function apachesolr_mlt_update_6000() {
+  $result = db_query('SELECT id, data FROM {apachesolr_mlt} ORDER BY id ASC');
+  while ($row = db_fetch_array($result)) {
+    apachesolr_mlt_save_block(unserialize($row['data']), sprintf('mlt-%03d', $row['id']));
+  }
+  $ret[] = update_sql("DROP TABLE {apachesolr_mlt}");
+  return $ret;
 }
\ No newline at end of file
Index: contrib/apachesolr_mlt/apachesolr_mlt.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/contrib/apachesolr_mlt/apachesolr_mlt.module,v
retrieving revision 1.1.4.27
diff -u -p -r1.1.4.27 apachesolr_mlt.module
--- contrib/apachesolr_mlt/apachesolr_mlt.module	31 Mar 2009 16:06:37 -0000	1.1.4.27
+++ contrib/apachesolr_mlt/apachesolr_mlt.module	6 May 2009 18:17:12 -0000
@@ -7,20 +7,13 @@
 function apachesolr_mlt_menu() {
   $items = array();
 
-  $items['admin/settings/apachesolr/mlt'] = array(
-    'title' => 'More Like This',
-    'description' => 'Configure content recommendation blocks using the Apache Solr "More Like This" handler.',
-    'page callback' => 'apachesolr_mlt_settings',
-    'access arguments' => array('administer search'),
-    'type' => MENU_LOCAL_TASK,
-  );
-  $items['admin/settings/apachesolr/mlt/configure_block'] = array(
+  $items['admin/settings/apachesolr/mlt/add_block'] = array(
     'type' => MENU_CALLBACK,
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('apachesolr_mlt_block_form', 5),
+    'page arguments' => array('apachesolr_mlt_add_block_form'),
     'access arguments' => array('administer search'),
     );
-  $items['admin/settings/apachesolr/mlt/delete_block'] = array(
+  $items['admin/settings/apachesolr/mlt/delete_block/%'] = array(
     'type' => MENU_CALLBACK,
     'page callback' => 'drupal_get_form',
     'page arguments' => array('apachesolr_mlt_delete_block_form', 5),
@@ -32,56 +25,117 @@ function apachesolr_mlt_menu() {
 /**
  * Implementation of hook_block
  */
-function apachesolr_mlt_block($op = 'list', $delta = 0, $edit = array()) {
+function apachesolr_mlt_block($op = 'list', $delta = NULL, $edit = array()) {
   static $access;
 
-  if ($op == 'list') {
-    //return all of the moreLikeThis blocks that the user has created
-    $blocks = apachesolr_mlt_list_blocks();
-    return $blocks;
-  }
-  elseif ($op == 'view' && !empty($delta) && (arg(0) == 'node')) {
-    //return the content of the block, based on the delta
-    $nid = arg(1);
-    if (is_numeric($nid) && (!arg(2) || arg(2) == 'view')) {
-      // Determine whether the user can view the current node.
-      if (!isset($access)) {
-        $node = node_load($nid);
-        $access = $node && node_access('view', $node);
-      }
-      if ($access) {
-        return apachesolr_mlt_suggestions($delta, $nid);
+  switch ($op) {
+    case 'list':
+      //return all of the moreLikeThis blocks that the user has created
+      $blocks = apachesolr_mlt_list_blocks();
+      return $blocks;
+      break;
+    case 'view': 
+      if (isset($delta) && ($node = menu_get_object()) && (!arg(2) || arg(2) == 'view')) {
+        // Determine whether the user can view the current node.
+        if (!isset($access)) {
+          $access = node_access('view', $node);
+        }
+        $block = apachesolr_mlt_load_block($delta);
+        if ($access && $block) {
+          $suggestions = array();
+          $docs = apachesolr_mlt_suggestions($block, $node->nid);
+          if (!empty($docs)) {
+            $suggestions['subject'] = check_plain($block['name']);
+            $suggestions['content'] = theme('apachesolr_mlt_recommendation_block', $docs);
+            if (user_access('administer search')) {
+               $suggestions['content'] .= l(t('Configure this block'),'admin/build/block/configure/apachesolr_mlt/' . $delta, array('attributes' => array('class' => 'apachesolr-mlt-admin-link')));
+            }
+          }
+          return $suggestions;
+        }
       }
+      break;
+    case 'configure':
+      return apachesolr_mlt_block_form($delta);
+    case 'save':
+      apachesolr_mlt_save_block($edit, $delta);
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_form_[form_id]_alter
+ */
+function apachesolr_mlt_form_block_admin_display_form_alter(&$form) {
+  foreach ($form as $key => $block) {
+    if ((strpos($key, "apachesolr_mlt_") === 0) && $block['module']['#value'] == 'apachesolr_mlt') {
+      $form[$key]['delete'] = array('#value' => l(t('delete'), 'admin/settings/apachesolr/mlt/delete_block/'. $block['delta']['#value']));
     }
   }
 }
 
 /**
- * function apachesolr_mlt_suggestions()
- * This function loads a the parameters for each moreLikeThis query, performs
- * the query, and returns a list of linked node titles.
+ * Implementation of hook_form_[form_id]_alter().
  *
- * @param int $block_id A block ID for loading the suggestions
+ * This adds a link to add more mlt blocks..
+ */
+function apachesolr_mlt_form_apachesolr_settings_alter(&$form, $form_state) {
+  $blocks = variable_get('apachesolr_mlt_blocks', array());
+  $form['mlt_link'] = array(
+    '#type' => 'item',
+    '#value' => l(t('Add a new content recommendation block'), 'admin/settings/apachesolr/mlt/add_block'),
+    '#description' => format_plural(count($blocks),  'You currenly have 1 block.', 'You currenly have @count blocks.'),
+  );
+  // Move buttons down.
+  $buttons = $form['buttons'];
+  unset($form['buttons']);
+  $form['buttons'] = $buttons;
+}
+
+/**
+ * Implementation of hook_form_[form_id]_alter().
  *
- * @return array An array to be returned to hook_block
+ * Hide the core 'title' field in favor of our 'name' field..
  */
-function apachesolr_mlt_suggestions($block_id, $nid) {
+function apachesolr_mlt_form_block_admin_configure_alter(&$form, $form_state) {
+  if ($form['module']['#value'] == 'apachesolr_mlt') {
+    $form['block_settings']['title']['#access'] = FALSE;
+  }
+}
+
+/**
+ * Performs a moreLikeThis query using the settings and retrieves documents.
+ *
+ * @param $settings
+ *   An array of settings.
+ * @param $nid
+ *   The nid of the node for which you want related content.
+ *
+ * @return An array of response documents, or NULL
+ */
+function apachesolr_mlt_suggestions($settings, $nid) {
 
   try {
     $solr = apachesolr_get_solr();
-    $fields = array('mlt.mintf', 'mlt.mindf', 'mlt.minwl', 'mlt.maxwl', 'mlt.maxqt', 'mlt.boost', 'mlt.qf');
-    $block = apachesolr_mlt_load_block($block_id);
+    $fields = array(
+      'mlt_mintf' => 'mlt.mintf',
+      'mlt_mindf' => 'mlt.mindf',
+      'mlt_minwl' => 'mlt.minwl',
+      'mlt_maxwl' => 'mlt.maxwl',
+      'mlt_maxqt' => 'mlt.maxqt',
+      'mlt_boost' => 'mlt.boost',
+      'mlt_qf' => 'mlt.qf',
+    );
 
     $params = array(
-        'qt' => 'mlt',
-        'fl' => 'nid,title,url',
-        'mlt.fl' => implode(',', $block['mlt_fl']),
+      'qt' => 'mlt',
+      'fl' => 'nid,title,path,url',
+      'mlt.fl' => implode(',', $settings['mlt_fl']),
     );
 
-    foreach ($fields as $field) {
-      $drupal_fieldname = str_replace('.', '_', $field);
-      if (!empty($block[$drupal_fieldname])) {
-        $params[$field] = check_plain($block[$drupal_fieldname]);
+    foreach ($fields as $form_key => $name) {
+      if (!empty($settings[$form_key])) {
+        $params[$name] = $settings[$form_key];
       }
     }
     $query = apachesolr_drupal_query('id:' . apachesolr_document_id($nid));
@@ -92,19 +146,12 @@ function apachesolr_mlt_suggestions($blo
       return;
     }
 
-    $response = $solr->search($query->get_query_basic(), 0, $block['num_results'], $params);
-    $suggestions = array();
+    $response = $solr->search($query->get_query_basic(), 0, $settings['num_results'], $params);
+
     if ($response->response) {
       $docs = (array) end($response->response);
-      if (!empty($docs)) {
-        $suggestions['subject'] = check_plain($block['name']);
-        $suggestions['content'] = theme('apachesolr_mlt_recommendation_block', $docs);
-        if (user_access('administer search')) {
-           $suggestions['content'] .= l(t('Configure this block'),'admin/settings/apachesolr/mlt/configure_block/' . $delta, array('attributes' => array('class' => 'apachesolr-mlt-admin-link')));
-        }
-      }
+      return $docs;
     }
-    return $suggestions;
   } 
   catch ( Exception $e ) {
     watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR );
@@ -123,37 +170,32 @@ function theme_apachesolr_mlt_recommenda
   $links = array();
   foreach ($docs as $result) {
     // Suitable for single-site mode.
-    $links[] = l($result->title, 'node/' . $result->nid);
+    $links[] = l($result->title, $result->path);
   }
   return theme('item_list', $links);
 }
 
-/**
- * function apachesolr_mlt_settings()
- * Returns the settings page.
- */
-function apachesolr_mlt_settings() {
-  $query = "SELECT * FROM {apachesolr_mlt}";
-  $results = db_query($query);
-  $rows = array();
-  while ($block = db_fetch_object($results)) {
-    $block->data = unserialize($block->data);
-    $rows[] = array(
-      $block->id,
-      check_plain($block->data['name']),
-      l(t('Edit'), 'admin/settings/apachesolr/mlt/configure_block/' . $block->id) .' | ' . l('Delete', 'admin/settings/apachesolr/mlt/delete_block/' . $block->id),
-    );
-  }
-  $header = array(t('Id'), t('Name'), t('Options'));
-  $output = l(t('Add block'), 'admin/settings/apachesolr/mlt/configure_block');
-  $output .= theme('table', $header, $rows);
-  return $output;
+
+function apachesolr_mlt_add_block_form() {
+  $form = apachesolr_mlt_block_form();
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => '5',
+  );
+  return $form;
+}
+
+function apachesolr_mlt_add_block_form_submit($form, &$form_state) {
+  apachesolr_mlt_save_block($form_state['values']);
+  drupal_set_message('New block created.');
+  $form_state['redirect'] = 'admin/build/block';
 }
 
 /**
- * function apachesolr_mlt_block_form()
- * Allows users to create and edit moreLikeThis Blocks.
- * @param int $block_id If editing, the id of the block to edit.
+ * Form to edit moreLikeThis block settings.
+ *
+ * @param int $delta If editing, the id of the block to edit.
  *
  * @return array The form used for editing.
  * TODO:
@@ -162,15 +204,15 @@ function apachesolr_mlt_settings() {
  *     on the node id.
  *
  */
-function apachesolr_mlt_block_form(&$form_state, $block_id = NULL) {
-  $block = array();
-  // If editing, load the current settings for the block.
-  if ($block_id && is_numeric($block_id)) {
-    $block = apachesolr_mlt_load_block($block_id);
-    $form['block_id'] = array(
-      '#type' => 'value',
-      '#value' => $block_id,
-    );
+function apachesolr_mlt_block_form($delta = NULL) {
+  if (isset($delta)) {
+    $block = apachesolr_mlt_load_block($delta);
+    if (!$block) {
+      return array();
+    }
+  }
+  else{
+    $block = apachesolr_mlt_block_defaults();
   }
 
   $form['name'] = array(
@@ -178,31 +220,23 @@ function apachesolr_mlt_block_form(&$for
     '#title' => t('Block Name'),
     '#description' => t('The block name displayed to site users.'),
     '#required' => TRUE,
-    '#default_value' => isset($block['name']) ? $block['name'] : '',
+    '#default_value' => $block['name'],
     '#weight' => '-2',
   );
   $form['num_results'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Maximum number of results'),
-    '#default_value' => isset($block['num_results']) ? $block['num_results'] : 5,
+    '#type' => 'select',
+    '#title' => t('Maximum number of related items to display'),
+    '#default_value' => $block['num_results'],
+    '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)),
     '#weight' => -1,
     );
-
-  $form['comparison'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Comparison fields'),
-    '#weight' => 0,
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-    );
-  $form['comparison']['mlt_fl'] = array(
+  $form['mlt_fl'] = array(
     '#type' => 'checkboxes',
-    '#title' => t('Fields for comparison'),
-    '#description' => t('Select fields to be used in calculating similarity. The default combination of "taxonomy_names" and "title" will provide relevant results for typical sites.'),
+    '#title' => t('Fields for finding related content'),
+    '#description' => t('Choose the fields to be used in calculating similarity. The default combination of %taxonomy_names and %title will provide relevant results for typical sites.', array("%taxonomy_names" => apachesolr_field_name_map("taxonomy_names"), "%title" => apachesolr_field_name_map("title"))),
     '#options' => apachesolr_mlt_get_fields(),
-    '#default_value' => isset($block['mlt_fl']) ? $block['mlt_fl'] : array('title', 'taxonomy_names'),
+    '#default_value' =>  $block['mlt_fl'],
   );
-
   $form['advanced'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced Configuration'),
@@ -210,85 +244,68 @@ function apachesolr_mlt_block_form(&$for
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
+  $options = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7));
   $form['advanced']['mlt_mintf'] = array(
-    '#type' => 'textfield',
+    '#type' => 'select',
     '#title' => t('Minimum Term Frequency'),
     '#description' => t('A word must appear this many times in any given document before the document is considered relevant for comparison.'),
-    '#default_value' => isset($block['mlt_mintf']) ? (int) $block['mlt_mintf'] : 1,
+    '#default_value' => $block['mlt_mintf'],
+    '#options' => $options,
   );
   $form['advanced']['mlt_mindf'] = array(
-    '#type' => 'textfield',
+    '#type' => 'select',
     '#title' => t('Minimum Document Frequency'),
     '#description' => t('A word must occur in at least this many documents before it will be used for similarity comparison.'),
-    '#default_value' => isset($block['mlt_mindf']) ? (int) $block['mlt_mindf'] : 1,
+    '#default_value' => $block['mlt_mindf'],
+    '#options' => $options,
   );
   $form['advanced']['mlt_minwl'] = array(
-    '#type' => 'textfield',
+    '#type' => 'select',
     '#title' => t('Minimum Word Length'),
     '#description' => 'You can use this to eliminate short words such as "the" and "it" from similarity comparisons. Words must be at least this number of characters or they will be ignored.',
-    '#default_value' => isset($block['mlt_minwl']) ? (int) $block['mlt_minwl'] : 3,
+    '#default_value' => $block['mlt_minwl'],
+    '#options' => $options,
   );
   $form['advanced']['mlt_maxwl'] = array(
-    '#type' => 'textfield',
+    '#type' => 'select',
     '#title' => t('Maximum World Length'),
     '#description' => t('You can use this to eliminate very long words from similarity comparisons. Words of more than this number of characters will be ignored.'),
-    '#default_value' => isset($block['mlt_maxwl']) ? (int) $block['mlt_maxwl'] : 15,
+    '#default_value' => $block['mlt_maxwl'],
+    '#options' => drupal_map_assoc(array(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
   );
   $form['advanced']['mlt_maxqt'] = array(
-    '#type' => 'textfield',
+    '#type' => 'select',
     '#title' => t('Maximum number of query terms'),
     '#description' => t('The maximum number of query terms that will be included in any query. Lower numbers will result in fewer recommendations but will get results faster. If a content recommendation is not returning any recommendations, you can either check more "Comparison fields" checkboxes or increase the maximum number of query terms here.'),
-    '#default_value' => isset($block['mlt_maxqt']) ? (int) $block['mlt_maxqt'] : 30,
+    '#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50)),
+    '#default_value' => $block['mlt_maxqt'],
   );
 
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-    '#weight' => '5',
-  );
-
-  $form['#redirect'] = 'admin/settings/apachesolr/mlt';
-
   return $form;
 }
 
 /**
- * function apachesolr_mlt_block_validate()
- *
- * Perform basic form field validation on the morelikethis fields.
- *
- * @param string $form_id the form ID
- * @param array $form_values an array of from values
+ * Merge supplied settings with the standard defaults..
  */
-function apachesolr_mlt_block_form_validate($form, &$form_state) {
-  if ($form_state['values']['form_id'] == 'apachesolr_mlt_block_form') {
-    foreach ($form_state['values'] as $key => $value) {
-      //make sure the user inputed a number, accept for the field list
-      if (strpos($key, 'mlt_') === 0 && $key != 'mlt_fl') {
-        if (!empty($value) && !is_numeric($value)) {
-          form_set_error($key, t("This field must contain a whole number."));
-        }
-      }
-    }
-  }
-}
-
-/**
- * function apachesolr_mlt_block_submit()
- * @param string $form_id the form ID
- * @param array $form_values an array of from values
- */
-function apachesolr_mlt_block_form_submit($form, &$form_state) {
-  if ($form_state['values']['form_id'] == 'apachesolr_mlt_block_form') {
-    $form_state['values']['mlt_fl'] = array_diff($form_state['values']['mlt_fl'], array(0));
-    apachesolr_mlt_save_block($form_state['values'], isset($form_state['values']['block_id']) ? $form_state['values']['block_id'] : NULL);
-  }
+function apachesolr_mlt_block_defaults($block = array()) {
+  return $block + array(
+    'name' => '',
+    'num_results' => '5',
+    'mlt_fl' =>  array(
+      'title' => 'title',
+      'taxonomy_names' => 'taxonomy_names',
+    ),
+    'mlt_mintf' => '1',
+    'mlt_mindf' => '1',
+    'mlt_minwl' => '3',
+    'mlt_maxwl' => '15',
+    'mlt_maxqt' => '30',
+  );
 }
 
-
 /**
- * function apachesolr_mlt_get_fields()
- * A list of field names used on the settings form.
+ * Constructs a list of field names used on the settings form.
+ *
  * @return array An array containing a the fields in the solr instance.
  */
 function apachesolr_mlt_get_fields() {
@@ -297,54 +314,40 @@ function apachesolr_mlt_get_fields() {
   $rows = array();
   foreach ($fields as $field_name => $field) {
     if ($field->schema{4} == 'V')
-    $rows[$field_name] = $field_name;
+    $rows[$field_name] = apachesolr_field_name_map($field_name);
   }
-
+  ksort($rows);
   return $rows;
 }
 
 /**
- * function apachesolr_mlt_load_block()
- * A loader function for the apachesolr more like this module. If the function
- * is passed a proper block id, the function will return the settings for the
- * moreLikeThis request. If the block id is invalid the function returns an
- * empty array.
+ * A helper function to save block data.
  *
- * @param int $block_id the id of the block you wish to load
- *
- * @return array Either the array of settings to perform the moreLikeThis request
- * or an empty array if the block id is invalid.
- */
-function apachesolr_mlt_load_block($block_id = 0) {
-  if (is_numeric($block_id)) {
-    $query_results = db_result(db_query('SELECT data FROM {apachesolr_mlt} WHERE id = %d', $block_id));
-    if (strlen($query_results)) {
-      return unserialize($query_results);
-    }
-  }
-  else {
-    return array();
-  }
-}
-
-/**
- * function apachesolr_mlt_save_block()
- * A helper function save the block data to the database.  If passed a valid
- * block id, the function will update block settings in the database. If it is
- * not passed a block id, the function will create a new block.
+ * If passed a block delta, the function will update block settings. If it is
+ * not passed a block delta, the function will create a new block.
  *
  * @param array $block_settings An array containing the settings required to form
  * a moreLikeThis request.
  *
- * @param int $block_id The id of the block you wish to update.
+ * @param int $delta The id of the block you wish to update.
  */
-function apachesolr_mlt_save_block($block_settings = array(), $block_id = 0) {
-  if (is_numeric($block_id) && $block_id > 0) {
-    db_query("UPDATE {apachesolr_mlt} SET data = '%s' WHERE id = %d", serialize($block_settings), $block_id);
-  }
-  else {
-    db_query("INSERT INTO {apachesolr_mlt} (data) VALUES ('%s')", serialize($block_settings));
+function apachesolr_mlt_save_block($block_settings = array(), $delta = NULL) {
+  $blocks = variable_get('apachesolr_mlt_blocks', array());
+  if (is_null($delta)) {
+    $count = 0;
+    ksort($blocks);
+    // Construct a new array key.
+    if (end($blocks)) {
+      list(, $count) = explode('-', key($blocks));
+    }
+    $delta = sprintf('mlt-%03d', 1 + $count);
   }
+  $defaults = apachesolr_mlt_block_defaults();
+  // Remove stray form values.
+  $blocks[$delta] = array_intersect_key($block_settings, $defaults) + $defaults;
+  // Eliminate non-selectied fields.
+  $blocks[$delta]['mlt_fl'] = array_filter($blocks[$delta]['mlt_fl']);
+  variable_set('apachesolr_mlt_blocks', $blocks);
 }
 
 /**
@@ -352,31 +355,37 @@ function apachesolr_mlt_save_block($bloc
  * Returns a list of blocks. Used by hook_block
  */
 function apachesolr_mlt_list_blocks() {
-  $block_results = db_query("SELECT * FROM {apachesolr_mlt}");
-  $blocks = array();
-  while ($block = db_fetch_object($block_results)) {
-    $block->data = unserialize($block->data);
-    $blocks[$block->id] = array('info' => t('Apache Solr recommendations: !name', array('!name' => $block->data['name'])) , 'cache' => BLOCK_CACHE_PER_PAGE);
+  $blocks = variable_get('apachesolr_mlt_blocks', array());
+  foreach ($blocks as $delta => $settings) {
+    $blocks[$delta] += array('info' => t('Apache Solr recommendations: !name', array('!name' => $settings['name'])) , 'cache' => BLOCK_CACHE_PER_PAGE);
   }
   return $blocks;
 }
 
-function apachesolr_mlt_delete_block_form(&$form_values, $block_id = NULL) {
-  if (is_numeric($block_id)) {
-    $block = apachesolr_mlt_load_block($block_id);
-    $form['block_id'] = array(
+function apachesolr_mlt_load_block($delta) {
+  $blocks = variable_get('apachesolr_mlt_blocks', array());
+  return isset($blocks[$delta]) ? $blocks[$delta] : FALSE;
+}
+
+function apachesolr_mlt_delete_block_form($form_state, $delta) {
+  if ($block = apachesolr_mlt_load_block($delta)) {
+    $form['delta'] = array(
       '#type' => 'value',
-      '#value' => $block_id
+      '#value' => $delta
     );
-    $form['#redirect'] = 'admin/settings/apachesolr/mlt';
+
     return confirm_form($form,
       t('Are you sure you want to delete the Apache Solr content recommendation block %name?', array('%name' => $block['name'])),
-      'admin/settings/apachesolr/mlt',
+      'admin/build/block',
       t('The block will be deleted. This action cannot be undone.'),
       t('Delete'), t('Cancel'));
   }
 }
 
 function apachesolr_mlt_delete_block_form_submit($form, &$form_state) {
-  db_query('DELETE FROM {apachesolr_mlt} WHERE id = %d', $form_state['values']['block_id']['#value']);
+  $blocks = variable_get('apachesolr_mlt_blocks', array());
+  unset($blocks[$form_state['values']['delta']]);
+  variable_set('apachesolr_mlt_blocks', $blocks);
+  drupal_set_message(t('The block has been deleted.'));
+  $form_state['redirect'] = 'admin/build/block';
 }
