You are here

function apachesolr_multilingual_form_alter in Apache Solr Multilingual 6.2

Same name and namespace in other branches
  1. 6 apachesolr_multilingual.module \apachesolr_multilingual_form_alter()

Implements hook_form_alter().

By default we only show text fields. Use hook_form_alter to change.

Parameters

$form:

$state: _id

Return value

mixed

File

./apachesolr_multilingual.module, line 208
Multilingual search using Apache Solr.

Code

function apachesolr_multilingual_form_alter(&$form, $form_state, $form_id) {
  if ('apachesolr_search_settings_form' == $form_id) {
    $active_languages = locale_language_list();
    $solr = apachesolr_get_solr();
    $fields = $solr
      ->getFields();
    $form['apachesolr_search_query_fields']['#description'] .= '<br />' . t('<b>Note:</b> If you are missing some language specific fields here you have to index some corresponding content first.');
    $qf = variable_get('apachesolr_search_query_fields', array());

    // 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;
    }
    foreach ($fields as $field_name => $field) {

      // Only indexed fields are searchable.
      if ($field->schema[0] == 'I') {
        if ('text' != $field->type && strpos($field->type, 'text') === 0 && strpos($field->type, 'textSpell') !== 0) {

          // search for language identifier at last or second position
          $tmp = explode('_', $field_name);
          $lang = array_pop($tmp);
          if (empty($active_languages[$lang])) {
            $tmp[] = $lang;
            if (!empty($active_languages[$tmp[1]])) {
              $lang = $tmp[1];
              unset($tmp[1]);
            }
          }
          if (!empty($active_languages[$lang])) {
            $base_field_name = implode('_', $tmp);
            $form['apachesolr_search_query_fields'][$base_field_name]['#description'] = t('Recommended to "Omit". Use language specific fields instead.');
            $form['apachesolr_search_query_fields'][$field_name]['#access'] = TRUE;
            if (!array_key_exists($field_name, $qf)) {
              $form['apachesolr_search_query_fields'][$field_name]['#default_value'] = isset($qf[$base_field_name]) ? $qf[$base_field_name] : '0';
            }
          }
        }
      }
    }
  }
}