diff --git a/README.txt b/README.txt index fc5ee84..a6a1c0c 100644 --- a/README.txt +++ b/README.txt @@ -85,6 +85,17 @@ directory, not directly the ones provided with this module. You'll have to restart your Solr server after making such changes, for them to take effect. +Hidden Configuration +---------- + +The variable search_api_solr_connection_class is used to define the connection information +that will be used to connect to solr. This was abstracted into a variable to allow services +that automatically setup solr for a particular site to override the default connection class. + +To see an example of how a connection class can be defined, check out the Pantheon Search +implementation: https://github.com/pantheon-systems/drops-7/blob/master/modules/pantheon/ +pantheon_apachesolr/Pantheon_Search_Api_Solr_Service.php. + Developers ---------- diff --git a/search_api_solr.install b/search_api_solr.install index 3b88e86..14fdccb 100644 --- a/search_api_solr.install +++ b/search_api_solr.install @@ -108,6 +108,7 @@ function search_api_solr_uninstall() { ->execute(); } variable_del('search_api_solr_last_optimize'); + variable_del('search_api_solr_connection_class'); } /** diff --git a/service.inc b/service.inc index 8bc1e4b..ed2d7a5 100644 --- a/service.inc +++ b/service.inc @@ -230,7 +230,8 @@ class SearchApiSolrService extends SearchApiAbstractService { if (!class_exists('Apache_Solr_Service')) { throw new Exception(t('SolrPhpClient library not found! Please follow the instructions in search_api_solr/INSTALL.txt for installing the Solr search module.')); } - $this->solr = new SearchApiSolrConnection($this->options); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $this->solr = new $class($this->options); } } @@ -845,7 +846,9 @@ class SearchApiSolrService extends SearchApiAbstractService { } else { $key = trim($key); - $key = SearchApiSolrConnection::phrase($key); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $key = $class::phrase($key); + $k[] = $key; } } @@ -923,7 +926,8 @@ class SearchApiSolrService extends SearchApiAbstractService { * and operator. */ protected function createFilterQuery($field, $value, $operator, $field_info) { - $field = SearchApiSolrConnection::escapeFieldName($field); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $field = $class::escapeFieldName($field); if ($value === NULL) { return ($operator == '=' ? '-' : '') . "$field:[* TO *]"; } @@ -962,8 +966,9 @@ class SearchApiSolrService extends SearchApiAbstractService { $value = format_date($value, 'custom', self::SOLR_DATE_FORMAT, 'UTC'); break; } - return SearchApiSolrConnection::phrase($value); - } + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + return $class::phrase($value); + } /** * Helper method for creating the facet field parameters. @@ -987,11 +992,12 @@ class SearchApiSolrService extends SearchApiAbstractService { // Check for the "or" operator. if (isset($info['operator']) && $info['operator'] === 'or') { // Remember that filters for this field should be tagged. - $escaped = SearchApiSolrConnection::escapeFieldName($fields[$info['field']]); - $taggedFields[$escaped] = "{!tag=$escaped}"; + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $escaped = $class::escapeFieldName($fields[$info['field']]); + $taggedFields[$escaped] = "{!tag=$escaped}"; // Add the facet field. $facet_params['facet.field'][] = "{!ex=$escaped}$field"; - } + } else { // Add the facet field. $facet_params['facet.field'][] = $field; @@ -1054,7 +1060,9 @@ class SearchApiSolrService extends SearchApiAbstractService { $k = $keys; $fields = $params['qf']; unset($params['qf']); - $keys = implode(":($k) OR ", array_map(array('SearchApiSolrConnection', 'escapeFieldName'), $fields)) . ":($k)"; + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $keys = implode(":($k) OR ", array_map(array($class, 'escapeFieldName'), $fields)) . ":($k)"; + return TRUE; } return FALSE;