diff --git a/INSTALL.txt b/INSTALL.txt index ec437cf..4e4897b 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -14,10 +14,10 @@ still supported, but this might change in the future.) [1] http://code.google.com/p/solr-php-client/downloads/list -Afterwards, unpack this archive to drupal's libraries folder, so the directory +Afterwards, unpack this archive to Drupal's libraries folder, so the directory tree looks like this: -/path/to/drupal/sites/all/libraries/ +DRUPAL_ROOT/sites/all/libraries/ |- SolrPhpClient |- Apache/ |- ChangeLog @@ -25,15 +25,24 @@ tree looks like this: The library should then be found by the module. +Note: If you have the Libraries API [2] module installed, you can also place the +library into any other directory recognized by the Libraries API, e.g. +(depending on the module version): +- DRUPAL_ROOT/libraries +- DRUPAL_ROOT/profiles/PROFILE/libraries +- DRUPAL_ROOT/sites/CONF_DIR/libraries + +[2] http://drupal.org/project/libraries + Setting up Solr --------------- In order for this module to work, you will first need to set up a Solr server. Download the latest stable version of Solr (1.4.1 at the time of this writing) -from [2] and unpack the archive somewhere outside of your web server's document +from [3] and unpack the archive somewhere outside of your web server's document tree. -[2] http://www.apache.org/dyn/closer.cgi/lucene/solr/ +[3] http://www.apache.org/dyn/closer.cgi/lucene/solr/ For small websites, using the example application, located in $SOLR/example/, usually suffices. In any case, you can use it for developing andd testing. The @@ -49,9 +58,9 @@ issue the following command (assuming Java is correctly installed): java -jar start.jar -Afterwards, go to [3] in your web browser to ensure Solr is running correctly. +Afterwards, go to [4] in your web browser to ensure Solr is running correctly. -[3] http://localhost:8983/solr/admin/ +[4] http://localhost:8983/solr/admin/ You can then enable this module and create a new server, using the "Solr search" service class. Enter the hostname, port and path corresponding to your Solr diff --git a/search_api_solr.module b/search_api_solr.module index 02730ea..68bd5f2 100644 --- a/search_api_solr.module +++ b/search_api_solr.module @@ -12,26 +12,47 @@ function search_api_solr_init() { } /** + * Return path to SolrPhpClient library path, or FALSE if not found. + */ +function _search_api_solr_solrphpclient_path() { + static $path = NULL; + + if (!isset($path)) { + $path = FALSE; + // If Libraries API is installed, we first use that to try and find the + // library. Otherwise we manually check a few locations. + if (!function_exists('libraries_get_path') || !($path = libraries_get_path('SolrPhpClient'))) { + $search_dir = array(); + $search_dir[] = 'sites/all/libraries'; + $search_dir[] = drupal_get_path('module', 'search_api_solr'); + foreach ($search_dir as $dir) { + $dir = DRUPAL_ROOT . '/' . $dir . '/SolrPhpClient'; + if (is_dir($dir)) { + $path = $dir; + break; + } + } + } + } + if ($path == FALSE) { + throw new Exception('SolrPhpClient library not found! Please follow the instructions in search_api_solr/INSTALL.txt for installing the Solr search module.'); + } + + return $path; +} + +/** * Autoloader for the SolrPhpClient classes. */ function _search_api_solr_autoload($name) { - static $path, $lookup_cache = array(); + static $lookup_cache = array(); if (isset($lookup_cache[$name])) { return $lookup_cache[$name]; } elseif (substr($name, 0, 11) == 'Apache_Solr') { - if (!isset($path)) { - foreach (array(dirname(__FILE__), DRUPAL_ROOT . '/sites/all/libraries', NULL) as $path) { - if (!$path || is_dir($path .= '/SolrPhpClient/')) { - break; - } - } - if (!$path) { - throw new Exception('SolrPhpClient library not found! Please follow the instructions in search_api_solr/INSTALL.txt for installing the Solr search module.'); - } - } - if (file_exists($file_path = $path . str_replace('_', '/', $name) . '.php')) { + $path = _search_api_solr_solrphpclient_path(); + if (file_exists($file_path = $path . '/' . str_replace('_', '/', $name) . '.php')) { require_once $file_path; $lookup_cache[$name] = TRUE; return TRUE;