You are here

function facetapi_luceneapi_form_facetapi_admin_settings_form in Facet API 6

Processes facetapi_admin_settings_form form submissions.

1 string reference to 'facetapi_luceneapi_form_facetapi_admin_settings_form'
facetapi_luceneapi_form_facetapi_admin_settings_form_alter in contrib/facetapi_luceneapi/facetapi_luceneapi.module
Implementation of hook_form_FORM_ID_alter().

File

contrib/facetapi_luceneapi/facetapi_luceneapi.module, line 47
The Search Lucene API module's implementation of the the Facet API.

Code

function facetapi_luceneapi_form_facetapi_admin_settings_form(&$form, &$form_state) {
  $searcher = $form['storage']['#value']['searcher'];

  // Gets the newly enabled facets.
  $enabled_facets = array_diff_key(facetapi_enabled_facets_get($searcher, NULL, TRUE), $form['storage']['#value']['enabled']);

  // If facets have been enabled, re-populates termFreqs cache.
  if (!empty($enabled_facets)) {
    $batch = array(
      'operations' => array(),
      'title' => t('Rebuilding termFreqs cache'),
      'init_message' => t('Populating ...'),
      'progress_message' => t('Batch @current out of @total'),
      'error_message' => t('An error occurred populating the cache.'),
    );

    // Iterates over facets, adds batch process to populate termFreqs cache.
    foreach ($enabled_facets as $facet) {
      $variable = 'facetapi:termfreqs_cached:' . $searcher . ':::' . $facet['field'];
      variable_set($variable, TRUE);
      $batch['operations'][] = array(
        'facetapi_luceneapi_termfreqs_populate',
        array(
          $searcher,
          $facet['field'],
        ),
      );
    }

    // Let the batch begin!
    batch_set($batch);
    drupal_set_message(t('The termFreqs cache has been rebuilt.'));
  }
}