You are here

function apachesolr_search_mlt_block_form in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr_search.admin.inc \apachesolr_search_mlt_block_form()
  2. 6.3 apachesolr_search.admin.inc \apachesolr_search_mlt_block_form()

Form to edit moreLikeThis block settings.

@todo Add term boost settings. @todo Enable the user to specify a query, rather then forcing suggestions based on the node id.

Parameters

int $delta If editing, the id of the block to edit.:

Return value

array The form used for editing.

2 calls to apachesolr_search_mlt_block_form()
apachesolr_search_block_configure in ./apachesolr_search.module
Implements hook_block_configure().
apachesolr_search_mlt_add_block_form in ./apachesolr_search.admin.inc
MoreLikeThis administration and utility functions.

File

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

Code

function apachesolr_search_mlt_block_form($block_id = NULL) {
  if (!empty($block_id)) {
    $block = apachesolr_search_mlt_block_load($block_id);
    if (!$block) {
      return array();
    }
  }
  else {
    $block = apachesolr_search_mlt_block_defaults();
  }
  $form['delta'] = array(
    '#type' => 'value',
    '#default_value' => isset($block['delta']) ? $block['delta'] : '',
    '#weight' => '-2',
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Block name'),
    '#description' => t('The block name displayed to site users.'),
    '#required' => TRUE,
    '#default_value' => isset($block['name']) ? $block['name'] : '',
    '#weight' => '-2',
  );
  $environments = apachesolr_load_all_environments();
  $options = array(
    '' => t('<Disabled>'),
  );
  foreach ($environments as $id => $environment) {
    $options[$id] = $environment['name'];
  }
  $form['mlt_env_id'] = array(
    '#title' => t('Search environment'),
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => isset($block['mlt_env_id']) ? $block['mlt_env_id'] : apachesolr_default_environment(),
  );
  $form['num_results'] = array(
    '#type' => 'select',
    '#title' => t('Maximum number of related items to display'),
    '#default_value' => isset($block['num_results']) ? $block['num_results'] : '',
    '#options' => drupal_map_assoc(array(
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      11,
      12,
      13,
      14,
      15,
    )),
    '#weight' => -1,
  );
  $form['mlt_fl'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Fields for finding related content'),
    '#description' => t('Choose the fields to be used in calculating similarity. The default combination of %taxonomy_names and %title will provide relevant results for typical sites.', array(
      "%taxonomy_names" => apachesolr_field_name_map("taxonomy_names"),
      "%title" => apachesolr_field_name_map("label"),
    )),
    '#options' => apachesolr_search_mlt_get_fields(),
    '#required' => TRUE,
    '#default_value' => isset($block['mlt_fl']) ? $block['mlt_fl'] : '',
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced configuration'),
    '#weight' => '1',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $options = drupal_map_assoc(array(
    1,
    2,
    3,
    4,
    5,
    6,
    7,
  ));
  $form['advanced']['mlt_mintf'] = array(
    '#type' => 'select',
    '#title' => t('Minimum term frequency'),
    '#description' => t('A word must appear this many times in any given document before the document is considered relevant for comparison.'),
    '#default_value' => isset($block['mlt_mintf']) ? $block['mlt_mintf'] : '',
    '#options' => $options,
  );
  $form['advanced']['mlt_mindf'] = array(
    '#type' => 'select',
    '#title' => t('Minimum document frequency'),
    '#description' => t('A word must occur in at least this many documents before it will be used for similarity comparison.'),
    '#default_value' => isset($block['mlt_mindf']) ? $block['mlt_mindf'] : '',
    '#options' => $options,
  );
  $form['advanced']['mlt_minwl'] = array(
    '#type' => 'select',
    '#title' => t('Minimum word length'),
    '#description' => 'You can use this to eliminate short words such as "the" and "it" from similarity comparisons. Words must be at least this number of characters or they will be ignored.',
    '#default_value' => isset($block['mlt_minwl']) ? $block['mlt_minwl'] : '',
    '#options' => $options,
  );
  $form['advanced']['mlt_maxwl'] = array(
    '#type' => 'select',
    '#title' => t('Maximum word length'),
    '#description' => t('You can use this to eliminate very long words from similarity comparisons. Words of more than this number of characters will be ignored.'),
    '#default_value' => isset($block['mlt_maxwl']) ? $block['mlt_maxwl'] : '',
    '#options' => drupal_map_assoc(array(
      8,
      9,
      10,
      11,
      12,
      13,
      14,
      15,
      16,
      17,
      18,
      19,
      20,
    )),
  );
  $form['advanced']['mlt_maxqt'] = array(
    '#type' => 'select',
    '#title' => t('Maximum number of query terms'),
    '#description' => t('The maximum number of query terms that will be included in any query. Lower numbers will result in fewer recommendations but will get results faster. If a content recommendation is not returning any recommendations, you can either check more "Comparison fields" checkboxes or increase the maximum number of query terms here.'),
    '#options' => drupal_map_assoc(array(
      3,
      5,
      7,
      10,
      12,
      15,
      20,
      25,
      30,
      35,
      40,
    )),
    '#default_value' => isset($block['mlt_maxqt']) ? $block['mlt_maxqt'] : '',
  );
  $form['restrictions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filters'),
    '#weight' => '1',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $type_options = array();
  foreach (node_type_get_types() as $key => $type) {
    $type_options[$key] = $type->name;
  }
  $form['restrictions']['mlt_type_filters'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Content Types'),
    '#default_value' => is_array($block['mlt_type_filters']) ? $block['mlt_type_filters'] : array(),
    '#options' => $type_options,
    '#description' => t('Select the content types that similarity suggestions should be restricted to. Multiple types are joined with an OR query, so selecting more types results in more recommendations. If none are selected, no filter will be applied.'),
    '#weight' => '-2',
  );
  $form['restrictions']['mlt_custom_filters'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional Query'),
    '#description' => t("A query, in Lucene syntax, which will further filter the similarity suggestions. For example, 'label:strategy' will filter related content further to only those with strategy in the title. Here are some more examples:") . '<ul>
                            <li>ss_language:fr</li>
                            <li>tid:(5 OR 7)</li>
                            <li>ds_created:[2009-05-01T23:59:59Z TO 2009-07-28T12:30:00Z]</li>
                            <li>-is_uid:0, -is_uid:1</li>
                        </ul>',
    '#required' => FALSE,
    '#default_value' => isset($block['mlt_custom_filters']) ? $block['mlt_custom_filters'] : '',
    '#weight' => '-1',
  );
  return $form;
}