You are here

function apachesolr_search_type_boost_form_submit in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 apachesolr_search.admin.inc \apachesolr_search_type_boost_form_submit()
  2. 6.2 apachesolr_search.admin.inc \apachesolr_search_type_boost_form_submit()

Submit callback for apachesolr_search_type_boost_form().

This is called before system_settings_form_submit().

1 string reference to 'apachesolr_search_type_boost_form_submit'
apachesolr_search_type_boost_form in ./apachesolr_search.admin.inc
Form builder function to set query type weights.

File

./apachesolr_search.admin.inc, line 231
Administrative settings for searching.

Code

function apachesolr_search_type_boost_form_submit($form_id, &$form_state) {
  $old_excluded_types = variable_get('apachesolr_search_excluded_types', array());
  $new_excluded_types = $form_state['values']['apachesolr_search_excluded_types'];

  // Check whether we are resetting the values.
  if ($form_state['clicked_button']['#value'] == t('Reset to defaults')) {
    $new_excluded_types = array();
  }
  foreach ($new_excluded_types as $type => $excluded) {

    // Remove newly omitted node types.
    // Note - we omit a check on empty($old_excluded_types[$type]) so that
    // the admin can re-submit this page if the delete operation fails.
    if (!empty($new_excluded_types[$type])) {
      try {
        $solr = apachesolr_get_solr();
        $solr
          ->deleteByQuery("type:{$type}");
        apachesolr_index_updated(time());
      } catch (Exception $e) {
        watchdog('Apache Solr', nl2br(check_plain($e
          ->getMessage())), NULL, WATCHDOG_ERROR);
        drupal_set_message(t('The Apache Solr search engine is not available. Please contact your site administrator.'), 'error');
      }
    }
  }
  foreach ($old_excluded_types as $type => $excluded) {

    // Set no longer omitted node types for reindexing.
    if (empty($new_excluded_types[$type]) && !empty($old_excluded_types[$type])) {
      db_query("UPDATE {apachesolr_search_node} SET changed = %d WHERE nid IN (SELECT nid FROM {node} WHERE type = '%s')", time(), $type);
    }
  }
}