1

On the Apache Solr settings page admin/config/search/apachesolr/enabled-filters you can control which filters are enabled on your site's search interface.

These settings are not stored in regular Drupal variables, hence, you cannot export these settings in a Feature like you would do with another variables. I am interested in making these settings persistent by storing them in Features.

This would allow to effortlessly switch from a produduction Solr instance to a local instance without having to manually re-apply all these settings by reverting the relevant Feature.

What would be best way to store these settings in Features?

2

This code resolved my need to backport production enabled-facet settings into localhost. Features are not used. tfk_search is the name of my module, substitute this for your own.

/**
 * Implement hook_form_FORM_ID_alter().
 *
 * Alter apachesolr_enabled_facets_form(), add an additional submit handler
 * that helps us export enabled facet settings via Features.
 */
function tfk_search_form_apachesolr_enabled_facets_form_alter(&$form, &$form_state, $form_id) {
  $form['#submit'][] = 'tfk_search_enabled_facets_form_submit';
}

/**
 * An additional submit handler for the active facets form.
 *
 * Save current settings into default server. Allows backporting
 * production settings into localhost. No Feature revert needed.
 *
 * @see apachesolr_enabled_facets_form
 */
function tfk_search_enabled_facets_form_submit($form, &$form_state) {
  $enabled = array();
  foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
    $enabled[$module] = array_filter($facets);
  }

  // We hardcode 'solr' here because apachesolr_default_server() resolves to something
  // else in production.
  apachesolr_save_enabled_facets('solr', $enabled);
}

After importing the database from production into local, while your default Solr instance is still the same as the one in production, go the enabled-facet settings page, and save it (even if you make no changes on it). Then switch the default Solr instance to the local one (solr). It should automatically pick up the facet settings for production.

Note that this solution is good for backporting settings, but not for exporting them á la Features. It would not work if you wanted to automatically push these settings into various sites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.