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.3
diff -u -p -r1.3 apachesolr_mlt.module
--- contrib/apachesolr_mlt/apachesolr_mlt.module	30 Apr 2009 19:02:08 -0000	1.3
+++ contrib/apachesolr_mlt/apachesolr_mlt.module	14 May 2009 15:40:14 -0000
@@ -19,7 +19,7 @@ function apachesolr_mlt_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('apachesolr_mlt_block_form', 5),
     'access arguments' => array('administer search'),
-    );
+  );
   $items['admin/settings/apachesolr/mlt/delete_block'] = array(
     'type' => MENU_CALLBACK,
     'page callback' => 'drupal_get_form',
@@ -69,13 +69,26 @@ function apachesolr_mlt_suggestions($blo
 
   try {
     $solr = apachesolr_get_solr();
-    $fields = array('mlt.mintf', 'mlt.mindf', 'mlt.minwl', 'mlt.maxwl', 'mlt.maxqt', 'mlt.boost', 'mlt.qf');
+    $fields = array('mlt.mintf', 'mlt.mindf', 'mlt.minwl', 'mlt.maxwl', 'mlt.maxqt', 'mlt.boost', 'mlt.fq');
     $block = apachesolr_mlt_load_block($block_id);
 
+    
+    // additional fq terms
+    // fq=+popularity:[10 TO *] +section:0
+    // in our case this will be fq=mlt_fq +type:blog +type:page
+    
+    //variable to put our filtering in
+    $subfq = NULL;
+    if(!empty($block['mlt_fqtype'])){
+      $subfq = 'type:';
+      $subfq .= implode(' OR type:',$block['mlt_fqtype']);
+    }
+    
     $params = array(
         'qt' => 'mlt',
         'fl' => 'nid,title,url',
         'mlt.fl' => implode(',', $block['mlt_fl']),
+        'fq' => $block['mlt_fq'].$subfq,  
     );
 
     foreach ($fields as $field) {
@@ -84,6 +97,7 @@ function apachesolr_mlt_suggestions($blo
         $params[$field] = check_plain($block[$drupal_fieldname]);
       }
     }
+
     $query = apachesolr_drupal_query('id:' . apachesolr_document_id($nid));
 
     // This hook allows modules to modify the query and params objects.
@@ -100,12 +114,12 @@ function apachesolr_mlt_suggestions($blo
         $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')));
+          $suggestions['content'] .= l(t('Configure this block'),'admin/settings/apachesolr/mlt/configure_block/' . $delta, array('attributes' => array('class' => 'apachesolr-mlt-admin-link')));
         }
       }
     }
     return $suggestions;
-  } 
+  }
   catch ( Exception $e ) {
     watchdog('Apache Solr', $e->getMessage(), NULL, WATCHDOG_ERROR );
   }
@@ -115,7 +129,7 @@ function apachesolr_mlt_theme($existing,
   return array(
     'apachesolr_mlt_recommendation_block' => array(
       'arguments' => array('docs' => NULL),
-    ),
+  ),
   );
 }
 
@@ -139,9 +153,9 @@ function apachesolr_mlt_settings() {
   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),
+    $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'));
@@ -186,7 +200,7 @@ function apachesolr_mlt_block_form(&$for
     '#title' => t('Maximum number of results'),
     '#default_value' => isset($block['num_results']) ? $block['num_results'] : 5,
     '#weight' => -1,
-    );
+  );
 
   $form['comparison'] = array(
     '#type' => 'fieldset',
@@ -194,7 +208,7 @@ function apachesolr_mlt_block_form(&$for
     '#weight' => 0,
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
-    );
+  );
   $form['comparison']['mlt_fl'] = array(
     '#type' => 'checkboxes',
     '#title' => t('Fields for comparison'),
@@ -241,6 +255,22 @@ function apachesolr_mlt_block_form(&$for
     '#default_value' => isset($block['mlt_maxqt']) ? (int) $block['mlt_maxqt'] : 30,
   );
 
+  $types = node_get_types('names');
+  $form['advanced']['mlt_fqtype'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Subquery for selected types'),
+    '#description' => t('This can be used to filter the result set. Exampe. type:story will limit the suggestions to story nodes. Note: If the list is empty, all content types will be selected'),
+    '#options' => $types,
+    '#default_value' => isset($block['mlt_fqtype']) ? $block['mlt_fqtype'] : array(''),
+  );
+
+  $form['advanced']['mlt_fq'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Results subquery'),
+    '#description' => t('This can be used to filter the result set. Exampe. type:story will limit the suggestions to story nodes'),
+    '#default_value' => isset($block['mlt_fq']) ? check_plain($block['mlt_fq']) : '',
+  );
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -262,9 +292,10 @@ function apachesolr_mlt_block_form(&$for
  */
 function apachesolr_mlt_block_form_validate($form, &$form_state) {
   if ($form_state['values']['form_id'] == 'apachesolr_mlt_block_form') {
+    $fields = array('num_results', 'mlt_mintf', 'mlt_mindf', 'mlt_minwl', 'mlt_maxwl', 'mlt_maxqt', 'mlt_boost', 'mlt_fq');
     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 (in_array($key, $fields)) {
         if (!empty($value) && !is_numeric($value)) {
           form_set_error($key, t("This field must contain a whole number."));
         }
@@ -281,6 +312,8 @@ function apachesolr_mlt_block_form_valid
 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));
+    $form_state['values']['mlt_fqtype'] = array_diff($form_state['values']['mlt_fqtype'], array(0));
+    
     apachesolr_mlt_save_block($form_state['values'], isset($form_state['values']['block_id']) ? $form_state['values']['block_id'] : NULL);
   }
 }
@@ -370,10 +403,10 @@ function apachesolr_mlt_delete_block_for
     );
     $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'])),
+    t('Are you sure you want to delete the Apache Solr content recommendation block %name?', array('%name' => $block['name'])),
       'admin/settings/apachesolr/mlt',
-      t('The block will be deleted. This action cannot be undone.'),
-      t('Delete'), t('Cancel'));
+    t('The block will be deleted. This action cannot be undone.'),
+    t('Delete'), t('Cancel'));
   }
 }
 
