Rely on ApacheSolr for loading client class

robertDouglass - February 8, 2009 - 22:33
Project:Webmail Plus
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:ApacheSolr
Description

You may have very good reasons for loading the client class directly, but if you do, I want to hear them =)

<?php
function webmail_plus_solr_cron() {
   
$_debug = variable_get('webmail_plus_solr_debug', FALSE);
   
    if(
$_debug) echo "running webmail_plus_solr_cron<br>\n";
     
   
// clear everything
   
   
db_query("TRUNCATE TABLE {webmail_plus_solr_history}");
   
db_query("TRUNCATE TABLE {webmail_plus_solr_map}");
   
db_query("TRUNCATE TABLE {webmail_plus_solr_results}");
   
db_query("TRUNCATE TABLE {webmail_plus_solr_results_headers}");
   
   
   
// fetch solr config
   
$solr_url = variable_get('webmail_plus_solr_url', NULL);
   
$solr_url_parts = parse_url($solr_url); 
   
$solr_batch_size = variable_get('webmail_plus_solr_batch_size', 10);
     
   
$solr_ignore_folders = variable_get('webmail_plus_solr_ignore_folders', NULL);
   
$solr_ignore_folders_arr = explode(',', $solr_ignore_folders);
    foreach(
$solr_ignore_folders_arr as $key=>$value) {
       
$solr_folder_blacklist[trim($value)]=trim($value);
    }
   
   
// load solr classes
 
$include_path = get_include_path();
 
$apachesolr_path = './'. drupal_get_path('module', 'apachesolr') .'/SolrPhpClient/';
 
$full_path = $include_path.':'.$apachesolr_path;
 
set_include_path($full_path);
  include_once(
'Apache/Solr/Service.php');
?>

This is what the ApacheSolr module does for you:

<?php
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);
?>

A lot of the new functionality being added relies on overriding the client class.

 
 

Drupal is a registered trademark of Dries Buytaert.