You are here

function apachesolr_search_settings_form in Apache Solr Search 6

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

Form builder function to set query field weights.

1 string reference to 'apachesolr_search_settings_form'
apachesolr_search_settings_page in ./apachesolr_search.admin.inc
Menu callback - the settings form.

File

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

Code

function apachesolr_search_settings_form($form_state, $fields) {
  $form = array();

  // get the current weights
  $qf = variable_get('apachesolr_search_query_fields', array());
  $weights = drupal_map_assoc(array(
    '21.0',
    '13.0',
    '8.0',
    '5.0',
    '3.0',
    '2.0',
    '1.0',
    '0.8',
    '0.5',
    '0.3',
    '0.2',
    '0.1',
  ));
  $weights['0'] = t('Omit');

  // Note - we have default values set in solrconfig.xml, which will operate
  // when none are set.  That's the preferred state.
  $defaults = array(
    'body' => '1.0',
    'title' => '5.0',
    'name' => '3.0',
    'taxonomy_names' => '2.0',
    'tags_h1' => '5.0',
    'tags_h2_h3' => '3.0',
    'tags_h4_h5_h6' => '2.0',
    'tags_inline' => '1.0',
    'tags_a' => '0',
  );
  if (!$qf) {
    $qf = $defaults;
  }
  if ($fields) {
    $form['apachesolr_search_query_fields'] = array(
      '#type' => 'fieldset',
      '#title' => t('Field biases'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
      '#description' => t('Specify here which fields are more important when searching. Give a field a greater numeric value to make it more important. If you omit a field, it will not be searched.'),
    );
    foreach ($fields as $field_name => $field) {

      // Only indexed feids are searchable.
      if ($field->schema[0] == 'I') {

        // By default we only show text fields.  Use hook_form_alter to change.
        $form['apachesolr_search_query_fields'][$field_name] = array(
          '#access' => $field->type == 'text',
          '#type' => 'select',
          '#options' => $weights,
          '#title' => apachesolr_field_name_map($field_name),
          '#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : '0',
        );
      }
    }

    // Make sure all the default fields are included, even if they have
    // no indexed content.
    foreach ($defaults as $field_name => $weight) {
      $form['apachesolr_search_query_fields'][$field_name] = array(
        '#type' => 'select',
        '#options' => $weights,
        '#title' => apachesolr_field_name_map($field_name),
        '#default_value' => isset($qf[$field_name]) ? $qf[$field_name] : $defaults[$field_name],
      );
    }
    ksort($form['apachesolr_search_query_fields']);
  }
  return system_settings_form($form);
}