You are here

function apachesolr_get_solr in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr.module \apachesolr_get_solr()
  2. 5.2 apachesolr.module \apachesolr_get_solr()
  3. 5 apachesolr.module \apachesolr_get_solr()
  4. 6 apachesolr.module \apachesolr_get_solr()
  5. 6.2 apachesolr.module \apachesolr_get_solr()
  6. 7 apachesolr.module \apachesolr_get_solr()

Factory method for solr singleton objects. Structure allows for an arbitrary number of solr objects to be used based on a name whie maps to the host, port, path combination. Get an instance like this: try { $solr = apachesolr_get_solr(); } catch (Exception $e) { watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); }

Throws

Exception

26 calls to apachesolr_get_solr()
AbstractDrupalSolrOnlineWebTestCase::setUpSolr in tests/solr_index_and_search.test
ApacheSolrFacetapiNumericRange::build in plugins/facetapi/query_type_numeric_range.inc
Initializes the facet's build array.
apachesolr_clear_cache in ./apachesolr.module
A wrapper for cache_clear_all to be used as a submit handler on forms that require clearing Luke cache etc.
apachesolr_config_file in ./apachesolr.admin.inc
Page callback to show one conf file.
apachesolr_config_files_overview in ./apachesolr.admin.inc
Page callback to show available conf files.

... See full list

File

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

Code

function apachesolr_get_solr($env_id = NULL, $reset = FALSE) {
  static $solr_cache;
  if ($reset) {
    $solr_cache = array();
    return;
  }
  $environments = apachesolr_load_all_environments();
  if (empty($env_id)) {
    $env_id = apachesolr_default_environment();
  }
  elseif (empty($environments[$env_id])) {
    throw new Exception(t('Invalid Apache Solr environment: @env_id.', array(
      '@env_id' => $env_id,
    )));
  }
  if (isset($environments[$env_id])) {
    $class_info = array();
    $class = NULL;
    if ($environments[$env_id]['service_class']) {
      $class_info = isset($environments[$env_id]['conf']['service_class_info']) ? $environments[$env_id]['conf']['service_class_info'] : NULL;
      $class = $environments[$env_id]['service_class'];
    }
    $class = apachesolr_load_service_class($class, $class_info);
    if (empty($solr_cache[$env_id])) {
      $solr = new $class($environments[$env_id]['url'], $env_id);
      $solr_cache[$env_id] = $solr;
    }
    return $solr_cache[$env_id];
  }
  else {
    throw new Exception('No default Apache Solr environment.');
  }
}