diff --git a/README.txt b/README.txt index 25fbf82..cbc7c93 100644 --- a/README.txt +++ b/README.txt @@ -95,6 +95,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. + +The default is the SearchApiSolrConnection class in solr_connection.inc, which +should be used as the base class for custom modifications. + Developers ---------- diff --git a/search_api_solr.install b/search_api_solr.install index 60270c5..5c35455 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'); variable_del('search_api_solr_autocomplete_max_occurrences'); } diff --git a/service.inc b/service.inc index 9047b08..98a7259 100644 --- a/service.inc +++ b/service.inc @@ -270,7 +270,13 @@ 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'); + + if ( !class_exists( $class ) ) { + $class = 'SearchApiSolrConnection'; + } + + $this->solr = new $class($this->options); } } @@ -564,7 +570,8 @@ class SearchApiSolrService extends SearchApiAbstractService { } } $mlt_params['mlt.fl'] = implode(',', $mlt_fl); - $keys = 'id:' . SearchApiSolrConnection::phrase($this->createId($index->machine_name, $mlt['id'])); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $keys = 'id:' . call_user_func(array($class, 'phrase'), $this->createId($index->machine_name, $mlt['id'])); } // Set defaults @@ -881,7 +888,8 @@ class SearchApiSolrService extends SearchApiAbstractService { } else { $key = trim($key); - $key = SearchApiSolrConnection::phrase($key); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $key = call_user_func(array($class, 'phrase'), $key); $k[] = $key; } } @@ -951,7 +959,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 = call_user_func(array($class, 'escapeFieldName'), $field); if ($value === NULL) { return ($operator == '=' ? '-' : '') . "$field:[* TO *]"; } @@ -990,8 +999,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 call_user_func(array($class, 'phrase'), $value); + } /** * Helper method for creating the facet field parameters. @@ -1015,7 +1025,8 @@ 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']]); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); + $escaped = call_user_func(array($class, 'escapeFieldName'), $fields[$info['field']]); $taggedFields[$escaped] = "{!tag=$escaped}"; // Add the facet field. $facet_params['facet.field'][] = "{!ex=$escaped}$field"; @@ -1440,8 +1451,9 @@ class SearchApiSolrService extends SearchApiAbstractService { // Restrict search to searched indexes. $index_filter = array(); + $class = variable_get('search_api_solr_connection_class', 'SearchApiSolrConnection'); foreach ($query->getIndexes() as $index_id => $index) { - $index_filter[] = 'index_id:' . SearchApiSolrConnection::phrase($index_id); + $index_filter[] = 'index_id:' . call_user_func(array($class, 'phrase'), $index_id); } $fq[] = implode(' OR ', $index_filter);