From 34d9879f2e715f65139b29239da38f583871160e Mon Sep 17 00:00:00 2001 From: Ray Thompson Date: Wed, 3 Oct 2012 22:02:55 +0000 Subject: [PATCH 1/3] Updating Pantheon Apache Solr Service class with changes to Drupal Apache Solr Service Interface class for apachesolr module rc5 --- .../Pantheon_Apache_Solr_Service.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php b/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php index f653973c6b1..49729131558 100644 --- a/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php +++ b/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php @@ -143,7 +143,7 @@ public function ping($timeout = 2) { * @return * (array) With all the system info */ - public function setSystemInfo() { + protected function setSystemInfo() { $url = $this->_constructUrl(self::SYSTEM_SERVLET, array('wt' => 'json')); if ($this->env_id) { $this->system_info_cid = $this->env_id . ":system:" . drupal_hash_base64($url); @@ -180,7 +180,12 @@ public function getSystemInfo() { */ protected function setLuke($num_terms = 0) { if (empty($this->luke[$num_terms])) { - $url = $this->_constructUrl(self::LUKE_SERVLET, array('numTerms' => "$num_terms", 'wt' => 'json')); + $params = array( + 'numTerms' => "$num_terms", + 'wt' => 'json', + 'json.nl' => self::NAMED_LIST_FORMAT, + ); + $url = $this->_constructUrl(self::LUKE_SERVLET, $params); if ($this->env_id) { $cid = $this->env_id . ":luke:" . drupal_hash_base64($url); $cache = cache_get($cid, 'cache_apachesolr'); @@ -267,25 +272,28 @@ public function getStatsSummary() { '@deletes_total' => '', '@schema_version' => '', '@core_name' => '', + '@index_size' => '', ); if (!empty($stats)) { $docs_pending_xpath = $stats->xpath('//stat[@name="docsPending"]'); - $summary['@pending_docs'] = (int) trim($docs_pending_xpath[0]); + $summary['@pending_docs'] = (int) trim(current($docs_pending_xpath)); $max_time_xpath = $stats->xpath('//stat[@name="autocommit maxTime"]'); $max_time = (int) trim(current($max_time_xpath)); // Convert to seconds. $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = format_interval($max_time / 1000); $deletes_id_xpath = $stats->xpath('//stat[@name="deletesById"]'); - $summary['@deletes_by_id'] = (int) trim($deletes_id_xpath[0]); + $summary['@deletes_by_id'] = (int) trim(current($deletes_id_xpath)); $deletes_query_xpath = $stats->xpath('//stat[@name="deletesByQuery"]'); - $summary['@deletes_by_query'] = (int) trim($deletes_query_xpath[0]); + $summary['@deletes_by_query'] = (int) trim(current($deletes_query_xpath)); $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query']; $schema = $stats->xpath('/solr/schema[1]'); $summary['@schema_version'] = trim($schema[0]);; $core = $stats->xpath('/solr/core[1]'); $summary['@core_name'] = trim($core[0]); + $size_xpath = $stats->xpath('//stat[@name="indexSize"]'); + $summary['@index_size'] = trim(current($size_xpath)); } return $summary; @@ -398,6 +406,7 @@ public function makeServletRequest($servlet, $params = array(), $options = array // Add default params. $params += array( 'wt' => 'json', + 'json.nl' => self::NAMED_LIST_FORMAT, ); $url = $this->_constructUrl($servlet, $params); @@ -812,7 +821,7 @@ public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 360 /** * Like PHP's built in http_build_query(), but uses rawurlencode() and no [] for repeated params. */ - public function httpBuildQuery(array $query, $parent = '') { + protected function httpBuildQuery(array $query, $parent = '') { $params = array(); foreach ($query as $key => $value) { From f608e830cec531c3c5b27d192173f4d155d1dcc7 Mon Sep 17 00:00:00 2001 From: Ray Thompson Date: Wed, 3 Oct 2012 22:19:27 +0000 Subject: [PATCH 2/3] Additional updates --- .../pantheon_apachesolr/Pantheon_Apache_Solr_Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php b/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php index 49729131558..bd8cfccf018 100644 --- a/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php +++ b/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php @@ -453,7 +453,7 @@ protected function _sendRawPost($url, $options = array()) { * * This is just a wrapper around drupal_http_request(). */ - protected function _makeHttpRequest($url, $options = array()) { + protected function _makeHttpRequest($url, array $options = array()) { // Hacking starts here. // $result = drupal_http_request($url, $headers, $method, $content); static $ch; From 45eecdf89c822a3d725d9d8af3bf00f359ecc529 Mon Sep 17 00:00:00 2001 From: Ray Thompson Date: Mon, 26 Nov 2012 15:32:13 -0800 Subject: [PATCH 3/3] Issue #761990 by pwolanin, jhedstrom, Nick_vh, jpmckinney | morningtime: Fixed 400 Bad Status if URL length limit exceeded. --- .../Pantheon_Apache_Solr_Service.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php b/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php index bd8cfccf018..573563cd4fb 100644 --- a/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php +++ b/modules/pantheon/pantheon_apachesolr/Pantheon_Apache_Solr_Service.php @@ -878,9 +878,15 @@ public function search($query = '', array $params = array(), $method = 'GET') { // PHP's built in http_build_query() doesn't give us the format Solr wants. $queryString = $this->httpBuildQuery($params); // Check string length of the query string, change method to POST - // if longer than 4000 characters (typical server handles 4096 max). - // @todo - make this a per-server setting. - if (strlen($queryString) > variable_get('apachesolr_search_post_threshold', 4000)) { + $len = strlen($queryString); + // Fetch our threshold to find out when to flip to POST + $max_len = apachesolr_environment_variable_get($this->env_id, 'apachesolr_search_post_threshold', 3600); + + // if longer than $max_len (default 3600) characters + // we should switch to POST (a typical server handles 4096 max). + // If this class is used independently (without environments), we switch automatically to POST at an + // limit of 1800 chars. + if (($len > 1800) && (empty($this->env_id) || ($len > $max_len))) { $method = 'POST'; }