You are here

function search_api_solr_form_search_api_index_form_alter in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 search_api_solr.module \search_api_solr_form_search_api_index_form_alter()
  2. 8.2 search_api_solr.module \search_api_solr_form_search_api_index_form_alter()
  3. 4.x search_api_solr.module \search_api_solr_form_search_api_index_form_alter()

Implements hook_form_FORM_alter.

File

./search_api_solr.module, line 171

Code

function search_api_solr_form_search_api_index_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // We need to restrict by form ID here because this function is also called
  // via hook_form_BASE_FORM_ID_alter (which is wrong, e.g. in the case of the
  // form ID search_api_field_config).
  if (in_array($form_id, [
    'search_api_index_form',
    'search_api_index_edit_form',
  ])) {
    if (isset($form['server'])) {
      $form['server']['#element_validate'][] = 'search_api_solr_form_search_api_index_form_validate_server';
    }
    $settings = [];

    /** @var \Drupal\search_api\IndexInterface $index */
    $index = $form_state
      ->getFormObject()
      ->getEntity();
    if (!$index
      ->isNew()) {
      $settings = $index
        ->getThirdPartySettings('search_api_solr');
    }
    $settings = search_api_solr_merge_default_index_third_party_settings($settings);
    $form['third_party_settings']['search_api_solr'] = [
      '#tree' => TRUE,
      '#type' => 'details',
      '#title' => t('Solr specific index options'),
      '#collapsed' => TRUE,
      '#states' => [
        'visible' => [
          ':input[name="server"]' => _search_api_solr_visibility(),
        ],
      ],
    ];
    $form['third_party_settings']['search_api_solr']['finalize'] = [
      '#type' => 'checkbox',
      '#title' => t('Finalize index before first search'),
      '#description' => t('If enabled, other modules could hook in to apply "finalizations" to the index after updates or deletions happend to index items.'),
      '#default_value' => $settings['finalize'],
    ];
    $form['third_party_settings']['search_api_solr']['commit_before_finalize'] = [
      '#type' => 'checkbox',
      '#title' => t('Wait for commit before first finalization'),
      '#description' => t('If enabled, Solr will be be forced to flush all commits before any "finalizations" will be applied.'),
      '#default_value' => $settings['commit_before_finalize'],
      '#states' => [
        'invisible' => [
          ':input[name="third_party_settings[search_api_solr][finalize]"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];
    $form['third_party_settings']['search_api_solr']['commit_after_finalize'] = [
      '#type' => 'checkbox',
      '#title' => t('Wait for commit after last finalization'),
      '#description' => t('If enabled, Solr will be be forced to flush all commits after the last "finalizations" have been applied.'),
      '#default_value' => $settings['commit_after_finalize'],
      '#states' => [
        'invisible' => [
          ':input[name="third_party_settings[search_api_solr][finalize]"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];
    $form['third_party_settings']['search_api_solr']['multilingual'] = [
      '#type' => 'details',
      '#title' => t('Multilingual'),
      '#tree' => TRUE,
    ];
    $form['third_party_settings']['search_api_solr']['multilingual']['limit_to_content_language'] = [
      '#type' => 'checkbox',
      '#title' => t('Limit to current content language.'),
      '#description' => t('Limit all search results for custom queries or search pages not managed by Views to current content language if no language is specified in the query.'),
      '#default_value' => $settings['multilingual']['limit_to_content_language'],
    ];
    $form['third_party_settings']['search_api_solr']['multilingual']['include_language_independent'] = [
      '#type' => 'checkbox',
      '#title' => t('Include language independent content in search results.'),
      '#description' => t('This option will include content without a language assigned in the results of custom queries or search pages not managed by Views. For example, if you search for English content, but have an article with languague of "undefined", you will see those results as well. If you disable this option, you will only see content that matches the language.'),
      '#default_value' => $settings['multilingual']['include_language_independent'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter'] = [
      '#tree' => TRUE,
      '#type' => 'details',
      '#title' => t('Highlighter'),
      '#collapsed' => TRUE,
      '#description' => t('If "Retrieve result data from Solr" and "Highlight retrieved data" are selected for the Solr backend on the server edit page, these highlighting settings will be used.'),
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['maxAnalyzedChars'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('maxAnalyzedChars'),
      '#description' => t('Specifies the number of characters into a document that Solr should look for suitable snippets.'),
      '#default_value' => $settings['highlighter']['maxAnalyzedChars'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['fragmenter'] = [
      '#type' => 'select',
      '#options' => [
        'gap' => 'gap',
        'regex' => 'regex',
      ],
      '#title' => t('fragmenter'),
      '#description' => t('Specifies a text snippet generator for highlighted text. The standard fragmenter is gap, which creates fixed-sized fragments with gaps for multi-valued fields. Another option is regex, which tries to create fragments that resemble a specified regular expression. This parameter accepts per-field overrdes.'),
      '#default_value' => $settings['highlighter']['fragmenter'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['regex'] = [
      '#tree' => TRUE,
      '#type' => 'details',
      '#title' => t('regex'),
      '#collapsed' => FALSE,
      '#states' => [
        'invisible' => [
          'select[name="third_party_settings[search_api_solr][highlighter][fragmenter]"]' => [
            'value' => 'gap',
          ],
        ],
      ],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['regex']['slop'] = [
      '#type' => 'number',
      '#step' => 0.1,
      '#min' => 0,
      '#title' => t('regex.slop'),
      '#description' => t('When using the regex fragmenter, this parameter defines the factor by which the fragmenter can stray from the ideal fragment size (given by fragsize) to accommodate a regular expression. For instance, a slop of 0.2 with fragsize=100 should yield fragments between 80 and 120 characters in length. It is usually good to provide a slightly smaller fragsize value when using the regex fragmenter.'),
      '#default_value' => $settings['highlighter']['regex']['slop'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['regex']['pattern'] = [
      '#type' => 'textfield',
      '#title' => t('regex.pattern'),
      '#description' => t('Specifies the regular expression for fragmenting. This could be used to extract sentences.'),
      '#default_value' => $settings['highlighter']['regex']['pattern'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['regex']['maxAnalyzedChars'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('regex.maxAnalyzedChars'),
      '#description' => t('Instructs Solr to analyze only this many characters from a field when using the regex fragmenter (after which, the fragmenter produces fixed-sized fragments). Applying a complicated regex to a huge field is computationally expensive.'),
      '#default_value' => $settings['highlighter']['regex']['maxAnalyzedChars'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['usePhraseHighlighter'] = [
      '#type' => 'checkbox',
      '#title' => t('usePhraseHighlighter'),
      '#description' => t('If set, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately. If false, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase.'),
      '#default_value' => $settings['highlighter']['usePhraseHighlighter'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['highlightMultiTerm'] = [
      '#type' => 'checkbox',
      '#title' => t('highlightMultiTerm'),
      '#description' => t('If set, Solr will highlight wildcard queries (and other MultiTermQuery subclasses). If false, they won\'t be highlighted at all.'),
      '#default_value' => $settings['highlighter']['highlightMultiTerm'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['preserveMulti'] = [
      '#type' => 'checkbox',
      '#title' => t('preserveMulti'),
      '#description' => t('If set, multi-valued fields will return all values in the order they were saved in the index. If false, only values that match the highlight request will be returned.'),
      '#default_value' => $settings['highlighter']['preserveMulti'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['highlight']['mergeContiguous'] = [
      '#type' => 'checkbox',
      '#title' => t('mergeContiguous'),
      '#description' => t('Instructs Solr to collapse contiguous fragments into a single fragment. A value of true indicates contiguous fragments will be collapsed into single fragment. This parameter accepts per-field overrides. The default value, false, is also the backward-compatible setting.'),
      '#default_value' => $settings['highlighter']['highlight']['mergeContiguous'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['highlight']['requireFieldMatch'] = [
      '#type' => 'checkbox',
      '#title' => t('requireFieldMatch'),
      '#description' => t('If set, highlights terms only if they appear in the specified field. If not set, terms are highlighted in all requested fields regardless of which field matched the query.'),
      '#default_value' => $settings['highlighter']['highlight']['requireFieldMatch'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['highlight']['snippets'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('snippets'),
      '#description' => t('Specifies maximum number of highlighted snippets to generate per field. It is possible for any number of snippets from zero to this value to be generated. This parameter accepts per-field overrides.'),
      '#default_value' => $settings['highlighter']['highlight']['snippets'],
    ];
    $form['third_party_settings']['search_api_solr']['highlighter']['highlight']['fragsize'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('fragsize'),
      '#description' => t('Specifies the size, in characters, of fragments to consider for highlighting. 0 indicates that no fragmenting should be considered and the whole field value should be used. This parameter accepts per-field overrides.'),
      '#default_value' => $settings['highlighter']['highlight']['fragsize'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt'] = [
      '#tree' => TRUE,
      '#type' => 'details',
      '#title' => t('MLT (MoreLikeThis)'),
      '#collapsed' => TRUE,
      '#description' => t('If a Search API MoreLikeThis block is configured for this index, these settings will be used.'),
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['mintf'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('mintf'),
      '#description' => t('Specifies the Minimum Term Frequency, the frequency below which terms will be ignored in the source document.'),
      '#default_value' => $settings['mlt']['mintf'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['mindf'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('mindf'),
      '#description' => t('Specifies the Minimum Document Frequency, the frequency at which words will be ignored which do not occur in at least this many documents.'),
      '#default_value' => $settings['mlt']['mindf'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['maxdf'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('maxdf'),
      '#description' => t('Specifies the Maximum Document Frequency, the frequency at which words will be ignored which occur in more than this many documents.'),
      '#default_value' => $settings['mlt']['maxdf'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['maxdfpct'] = [
      '#type' => 'number',
      '#min' => 0,
      '#max' => 100,
      '#title' => t('maxdfpct'),
      '#description' => t('Specifies the Maximum Document Frequency using a relative ratio to the number of documents in the index. The argument must be an integer between 0 and 100. For example 75 means the word will be ignored if it occurs in more than 75 percent of the documents in the index.'),
      '#default_value' => $settings['mlt']['maxdfpct'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['minwl'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('minwl'),
      '#description' => t('Sets the minimum word length below which words will be ignored.'),
      '#default_value' => $settings['mlt']['minwl'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['maxwl'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('maxwl'),
      '#description' => t('Sets the maximum word length above which words will be ignored.'),
      '#default_value' => $settings['mlt']['maxwl'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['maxqt'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('maxqt'),
      '#description' => t('Sets the maximum number of query terms that will be included in any generated query.'),
      '#default_value' => $settings['mlt']['maxqt'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['maxntp'] = [
      '#type' => 'number',
      '#min' => 0,
      '#title' => t('maxntp'),
      '#description' => t('Sets the maximum number of tokens to parse in each example document field that is not stored with TermVector support.'),
      '#default_value' => $settings['mlt']['maxntp'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['boost'] = [
      '#type' => 'checkbox',
      '#title' => t('boost'),
      '#description' => t('Specifies if the query will be boosted by the interesting term relevance.'),
      '#default_value' => $settings['mlt']['boost'],
    ];
    $form['third_party_settings']['search_api_solr']['mlt']['interestingTerms'] = [
      '#type' => 'select',
      '#options' => [
        'none' => 'none',
        'list' => 'list',
        'details' => 'details',
      ],
      '#title' => t('interestingTerms'),
      '#description' => t('Controls how the MoreLikeThis component presents the "interesting" terms (the top TF/IDF terms) for the query. Supports three settings. The setting "list" lists the terms. The setting "none" lists no terms. The setting "details" lists the terms along with the boost value used for each term. Unless mlt.boost=true, all terms will have boost=1.0.'),
      '#default_value' => $settings['mlt']['interestingTerms'],
    ];
    $form['third_party_settings']['search_api_solr']['advanced'] = [
      '#tree' => TRUE,
      '#type' => 'details',
      '#title' => t('Advanced'),
    ];
    $form['third_party_settings']['search_api_solr']['advanced']['index_prefix'] = [
      '#type' => 'textfield',
      '#title' => t('Index prefix'),
      '#description' => t("By default, the index ID in the Solr server is the same as the index's machine name in Drupal. This setting will let you specify an additional prefix. Only use alphanumeric characters and underscores. Since changing the prefix makes the currently indexed data inaccessible, you should not change this variable when no data is indexed."),
      '#default_value' => $settings['advanced']['index_prefix'],
    ];
    $form['third_party_settings']['search_api_solr']['advanced']['collection'] = [
      '#type' => 'textfield',
      '#title' => t('Collection'),
      '#description' => t("If the server uses a Solr Cloud connector, this setting overwrites the configured default collection if set."),
      '#default_value' => $settings['advanced']['collection'],
    ];
    $zones = system_time_zones(TRUE, TRUE);
    $form['third_party_settings']['search_api_solr']['advanced']['timezone'] = [
      '#type' => 'select',
      '#title' => t('Time zone'),
      '#description' => t("For correct date calculations the time zone to use is sent to the Solr server. By default the individual time zone of the current user will be used. If not available the site's default time zone will be used as fallback. But by setting a time zone here you can force a time zone for every query targeting this index."),
      '#default_value' => $settings['advanced']['timezone'],
      '#options' => $zones,
    ];
  }
}