You are here

function apachesolr_get_solr in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 8 apachesolr.module \apachesolr_get_solr()
  2. 5 apachesolr.module \apachesolr_get_solr()
  3. 6.3 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 object. Structure allows for an arbitrary number of solr objects to be used based on the host, port, path combination. Get an instance like this: $solr = apachesolr_get_solr();

18 calls to apachesolr_get_solr()
apachesolr_cron in ./apachesolr.module
Implementation of hook_cron().
apachesolr_delete_index in ./apachesolr.admin.inc
Utility function to delete the index and reset all index counters.
apachesolr_delete_node_from_index in ./apachesolr.module
apachesolr_do_query in ./apachesolr.module
Execute a search based on a query object.
apachesolr_drupal_query in ./apachesolr.module
Factory function for query objects.

... See full list

File

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

Code

function apachesolr_get_solr($host = NULL, $port = NULL, $path = NULL) {
  static $solr_cache;
  if (empty($host)) {
    $host = variable_get('apachesolr_host', 'localhost');
  }
  if (empty($port)) {
    $port = variable_get('apachesolr_port', '8983');
  }
  if (empty($path)) {
    $path = variable_get('apachesolr_path', '/solr');
  }
  if (empty($solr_cache[$host][$port][$path])) {
    list($module, $filepath, $class) = variable_get('apachesolr_service_class', array(
      'apachesolr',
      'Drupal_Apache_Solr_Service.php',
      'Drupal_Apache_Solr_Service',
    ));
    include_once drupal_get_path('module', $module) . '/' . $filepath;
    $solr = new $class($host, $port, $path);

    // Set a non-default behavior.
    $solr
      ->setCollapseSingleValueArrays(FALSE);
    $solr_cache[$host][$port][$path] = $solr;
  }
  return $solr_cache[$host][$port][$path];
}