function apachesolr_get_solr in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.module \apachesolr_get_solr()
- 5.2 apachesolr.module \apachesolr_get_solr()
- 5 apachesolr.module \apachesolr_get_solr()
- 6.3 apachesolr.module \apachesolr_get_solr()
- 6 apachesolr.module \apachesolr_get_solr()
- 6.2 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); }
Parameters
string $env_id:
Return value
DrupalApacheSolrServiceInterface $solr
Throws
Exception
27 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.
1 string reference to 'apachesolr_get_solr'
- apachesolr_environments_clear_cache in ./
apachesolr.module - Clear all caches for environments.
File
- ./
apachesolr.module, line 1176 - Integration with the Apache Solr search application.
Code
function apachesolr_get_solr($env_id = NULL) {
$solr_cache =& drupal_static(__FUNCTION__);
$environments = apachesolr_load_all_environments();
if (!interface_exists('DrupalApacheSolrServiceInterface')) {
require_once dirname(__FILE__) . '/apachesolr.interface.inc';
}
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 = $environments[$env_id]['service_class'];
if (empty($solr_cache[$env_id])) {
// Use the default class if none is specified.
if (empty($class)) {
$class = variable_get('apachesolr_service_class', 'DrupalApacheSolrService');
}
// Takes advantage of auto-loading.
$solr = new $class($environments[$env_id]['url'], $env_id);
$soft_commit = apachesolr_environment_variable_get($env_id, 'apachesolr_soft_commit', FALSE);
if ($soft_commit) {
$solr
->setSoftCommit($soft_commit);
}
$solr_cache[$env_id] = $solr;
}
return $solr_cache[$env_id];
}
else {
throw new Exception('No default Apache Solr environment.');
}
}