You are here

function apachesolr_facetcount_form in Apache Solr Search 6.2

Same name and namespace in other branches
  1. 5.2 apachesolr.module \apachesolr_facetcount_form()
  2. 5 apachesolr.module \apachesolr_facetcount_form()
  3. 6 apachesolr.module \apachesolr_facetcount_form()

Used by the 'configure' $op of hook_block so that modules can generically set facet limits on their blocks.

2 calls to apachesolr_facetcount_form()
apachesolr_date_block in contrib/apachesolr_date/apachesolr_date.module
Implementation of hook_block().
apachesolr_search_block in ./apachesolr_search.module
Implementation of hook_block().

File

./apachesolr.module, line 1402
Integration with the Apache Solr search application.

Code

function apachesolr_facetcount_form($module, $delta) {
  $initial = variable_get('apachesolr_facet_query_initial_limits', array());
  $limits = variable_get('apachesolr_facet_query_limits', array());
  $sorts = variable_get('apachesolr_facet_query_sorts', array());
  $children = variable_get('apachesolr_facet_show_children', array());
  $facet_missing = variable_get('apachesolr_facet_missing', array());
  $limit = drupal_map_assoc(array(
    50,
    40,
    30,
    20,
    15,
    10,
    5,
    3,
  ));
  $form['apachesolr_facet_query_initial_limit'] = array(
    '#type' => 'select',
    '#title' => t('Initial filter links'),
    '#options' => $limit,
    '#description' => t('The initial number of filter links to show in this block.'),
    '#default_value' => isset($initial[$module][$delta]) ? $initial[$module][$delta] : variable_get('apachesolr_facet_query_initial_limit_default', 10),
  );
  $limit = drupal_map_assoc(array(
    100,
    75,
    50,
    40,
    30,
    20,
    15,
    10,
    5,
    3,
  ));
  $form['apachesolr_facet_query_limit'] = array(
    '#type' => 'select',
    '#title' => t('Maximum filter links'),
    '#options' => $limit,
    '#description' => t('The maximum number of filter links to show in this block.'),
    '#default_value' => isset($limits[$module][$delta]) ? $limits[$module][$delta] : variable_get('apachesolr_facet_query_limit_default', 20),
  );

  // TODO: Generalize how we know what type a facet block is by putting field
  // type into the facet definition. 'created' and 'changed' are date blocks.
  if ($delta != 'created' && $delta != 'changed') {
    $form['apachesolr_facet_query_sort'] = array(
      '#type' => 'radios',
      '#title' => t('Sort order of facet links'),
      '#options' => array(
        'count' => t('Count'),
        'index asc' => t('Alphabetical, ascending'),
        'index desc' => t('Alphabetical, descending'),
        'index numeric asc' => t('Numeric, ascending'),
        'index numeric desc' => t('Numeric, descending'),
        'index key asc' => t('Key sort, ascending'),
        'index key desc' => t('Key sort, descending'),
      ),
      '#description' => t('The sort order of facet links in this block. %Count, which is the default, will show facets with the most results first. %Alphabetical will sort alphabetically, and %Numeric numerically, either ascending or descending.', array(
        '%Count' => t('Count'),
        '%Alphabetical' => t('Alphanumeric'),
        '%Numeric' => t('Numeric'),
      )),
      '#default_value' => isset($sorts[$module][$delta]) ? $sorts[$module][$delta] : 'count',
    );
  }
  $form['apachesolr_facet_show_children'] = array(
    '#type' => 'radios',
    '#title' => t('Always show child facets'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#description' => t('Show the child facets even if the parent facet is not selected.'),
    '#default_value' => isset($children[$module][$delta]) ? $children[$module][$delta] : 0,
  );
  $form['apachesolr_facet_missing'] = array(
    '#type' => 'radios',
    '#title' => t('Include a facet for missing'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#description' => t('A facet can be generated corresponding to all documents entirely missing this field.'),
    '#default_value' => isset($facet_missing[$module][$delta]) ? $facet_missing[$module][$delta] : 0,
  );
  return $form;
}