diff --git a/solr_connection.inc b/solr_connection.inc index 770a7b6..df20faa 100644 --- a/solr_connection.inc +++ b/solr_connection.inc @@ -122,6 +122,55 @@ class SearchApiSolrConnection extends Apache_Solr_Service { /** + * Allow extended queries + * + */ + public function sendHttpRequest($uri = array(),$method='GET', $headers = array(), $content= '', $timeout = FALSE) { + if (!array_key_exists('Content-Type',$headers)) { + $headers['Content-Type'] = 'text/xml; charset=UTF-8'; + } + $url = 'http://' . $this->_host . ':' . $this->_port . $this->_path . $uri; + list($data, $headers) = $this->_makeHttpRequest($url, $method, $headers, $content, $timeout); + if ($this->newClient) { + $status = 0; + $contentType = false; + //iterate through headers for real status, type, and encoding + if (is_array($headers) && count($headers) > 0) { + while (isset($headers[0]) && substr($headers[0], 0, 4) == 'HTTP') { + // we can do a intval on status line without the "HTTP/1.X " to get the code + $status = intval(substr($headers[0], 9)); + // remove this from the headers so we can check for more + array_shift($headers); + } + + //Look for the Content-Type response header and determine type + //and encoding from it (if possible - such as 'Content-Type: text/plain; charset=UTF-8') + foreach ($headers as $header) { + // look for the header that starts appropriately + if (strncasecmp($header, 'Content-Type:', 13) == 0) { + $contentType = substr($header, 13); + break; + } + } + } + $httpResponse = new Apache_Solr_HttpTransport_Response($status, $contentType, $data); + $response = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); + } else { + $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); + } + $code = (int) $response->getHttpStatus(); + if ($code != 200) { + $message = $response->getHttpStatusMessage(); + if ($code >= 400 && $code != 403 && $code != 404) { + // Add details, like Solr's exception message. + $message .= $response->getRawResponse(); + } + throw new Exception('"' . $code . '" Status: ' . $message. '::'.$url); + } + return $response; + } + + /** * Call the /admin/ping servlet, to test the connection to the server. * * @param $timeout