本文整理汇总了PHP中Apache_Solr_Response类的典型用法代码示例。如果您正苦于以下问题:PHP Apache_Solr_Response类的具体用法?PHP Apache_Solr_Response怎么用?PHP Apache_Solr_Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Apache_Solr_Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @see Drupal_Apache_Solr_Service::_sendRawGet()
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
$id = $this->add_request_id($url);
list($cookie, $nonce) = acquia_search_auth_cookie($url, $rawPost);
$request_headers = array('Content-Type' => $contentType, 'Cookie' => $cookie, 'User-Agent' => 'acquia_search/' . ACQUIA_SEARCH_VERSION);
list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout);
$response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays);
$code = (int) $response->getHttpStatus();
if ($code != 200) {
$message = $response->getHttpStatusMessage() . "\n request ID: {$id} \n";
if ($code >= 400 && $code != 403 && $code != 404) {
// Add details, like Solr's exception message.
$message .= $response->getRawResponse();
}
throw new Exception('"' . $code . '" Status: ' . $message);
}
return $response;
}
示例2: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @see Drupal_Apache_Solr_Service::_sendRawGet()
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
if (variable_get('apachesolr_read_only', 0)) {
throw new Exception('Operating in read-only mode; updates are disabled.');
}
$id = $this->add_request_id($url);
list($cookie, $nonce) = acquia_search_auth_cookie($url, $rawPost);
if (empty($cookie)) {
throw new Exception('Invalid authentication string - subscription keys expired or missing.');
}
$request_headers = array('Content-Type' => $contentType, 'Cookie' => $cookie, 'User-Agent' => 'acquia_search/' . ACQUIA_SEARCH_VERSION);
list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout);
$response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays);
$code = (int) $response->getHttpStatus();
if ($code != 200) {
$message = $response->getHttpStatusMessage() . "\n request ID: {$id} \n";
if ($code >= 400 && $code != 403 && $code != 404) {
// Add details, like Solr's exception message.
$message .= $response->getRawResponse();
}
throw new Exception('"' . $code . '" Status: ' . $message);
}
return $response;
}
示例3: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @see Drupal_Apache_Solr_Service::_sendRawGet()
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
$this->add_request_id($url);
list($cookie, $nonce) = acquia_search_auth_cookie($url, $rawPost);
$request_headers = array('Content-Type' => $contentType, 'Cookie' => $cookie);
list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout);
$response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($response->getHttpStatus() != 200) {
throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage() . "\n<br />request ID: {$id} <br />" . $url, $response->getHttpStatus());
}
return $response;
}
示例4: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $url
* @param string $rawPost
* @param float $timeout Read timeout in seconds
* @param string $contentType
* @return Apache_Solr_Response
*
* @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
stream_context_set_option($this->_postContext, array('http' => array('method' => 'POST', 'header' => "Content-Type: {$contentType}", 'content' => $rawPost, 'timeout' => $this->_defaultTimeout)));
// set the timeout if specified
if ($timeout !== FALSE && $timeout > 0.0) {
// timeouts with file_get_contents seem to need
// to be halved to work as expected
$timeout = (double) $timeout / 2;
stream_context_set_option($this->_postContext, 'http', 'timeout', $timeout);
}
// $http_response_header will be updated by the call to file_get_contents later
// see http://us.php.net/manual/en/wrappers.http.php for documentation
// Unfortunately, it will still create a notice in analyzers if we don't set it here
$http_response_header = null;
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($response->getHttpStatus() != 200) {
throw new Apache_Solr_HttpTransportException($response);
}
return $response;
}
示例5: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $url
* @param string $rawPost
* @param float $timeout Read timeout in seconds
* @param string $contentType
* @return Apache_Solr_Response
*
* @throws Exception If a non 200 response status is returned
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
list($output, $info) = $this->_curlGetContents($url, $rawPost, $timeout, $contentType);
$response = new Apache_Solr_Response($output, $info, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($response->getHttpStatus() != 200) {
throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
}
return $response;
}
示例6: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @see Apache_Solr_Service::_sendRawGet()
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
$request_headers = array('Content-Type' => $contentType);
list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout);
$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);
}
return $response;
}
示例7: log
/**
* Logs the item and what document was created from it
*
* @param Tx_Solr_IndexQueue_Item The item that is being indexed.
* @param array An array of Solr documents created from the item's data
* @param Apache_Solr_Response The Solr response for the particular index document
*/
protected function log(Tx_Solr_IndexQueue_Item $item, array $itemDocuments, Apache_Solr_Response $response)
{
if (!$this->loggingEnabled) {
return;
}
$message = 'Index Queue indexing ' . $item->getType() . ':' . $item->getRecordUid() . ' - ';
$severity = 0;
// info
// preparing data
$documents = array();
foreach ($itemDocuments as $document) {
$documents[] = (array) $document;
}
$logData = array('item' => (array) $item, 'documents' => $documents, 'response' => (array) $response);
if ($response->getHttpStatus() == 200) {
$severity = -1;
$message .= 'Success';
} else {
$severity = 3;
$message .= 'Failure';
$logData['status'] = $response->getHttpStatus();
$logData['status message'] = $response->getHttpStatusMessage();
}
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog($message, 'solr', $severity, $logData);
}
示例8: ping
/**
* Call the /admin/ping servlet, can be used to quickly tell if a connection to the
* server is able to be made.
*
* @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
* @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
*/
public function ping($timeout = 2)
{
$start = microtime(true);
$httpTransport = $this->getHttpTransport();
$httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($solrResponse->getHttpStatus() == 200) {
return microtime(true) - $start;
} else {
return false;
}
}
示例9: searchByPost
public function searchByPost($query, $offset = 0, $limit = 10, $params = array())
{
if (!is_array($params)) {
$params = array();
}
// construct our full parameters
// sending the version is important in case the format changes
$params['version'] = self::SOLR_VERSION;
// common parameters in this interface
$params['wt'] = self::SOLR_WRITER;
$params['json.nl'] = $this->_namedListTreatment;
$params['q'] = $query;
$params['start'] = $offset;
$params['rows'] = $limit;
//$params['qt'] = 'standard';
// use http_build_query to encode our arguments because its faster
// than urlencoding all the parts ourselves in a loop
$queryString = http_build_query($params, null, $this->_queryStringDelimiter);
// because http_build_query treats arrays differently than we want to, correct the query
// string by changing foo[#]=bar (# being an actual number) parameter strings to just
// multiple foo=bar strings. This regex should always work since '=' will be urlencoded
// anywhere else the regex isn't expecting it
$queryString = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
$postdata = $queryString;
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
//$result = file_get_contents('http://example.com/submit.php', false, $context);
$response = new Apache_Solr_Response(@file_get_contents($this->_searchUrl, false, $context), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($response->getHttpStatus() != 200) {
throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
}
return $response;
}
示例10: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $sUrl The URL to be requested
* @param string $sRawPost Workload to be delivered
* @param float $iTimeLimit Read timeout in seconds
* @param string $sContentType The content type to be included in the http-header
* @return Apache_Solr_Response
*
* @throws Exception If a non 200 response status is returned by cURL
*/
protected function _sendRawPost($sUrl, $sRawPost, $iTimeLimit = false, $sContentType = 'text/xml; charset=UTF-8')
{
wfProfileIn('BS::' . __METHOD__);
try {
if ($iTimeLimit === false) {
$iTimeLimit = 20;
}
$ch = $this->getCurlHandle();
curl_setopt($ch, CURLOPT_URL, $sUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sRawPost);
curl_setopt($ch, CURLOPT_TIMEOUT, $iTimeLimit);
// maximal exectuion time in seconds
$data = curl_exec($ch);
$this->curlConnectionCounter++;
$data = str_replace("\r\n", "\n", $data);
$responseParts = explode("\n\n", $data);
$http_response_header = explode("\n", $responseParts[0]);
$responseData = isset($responseParts[1]) ? $responseParts[1] : '';
$response = new Apache_Solr_Response($responseData, $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
} catch (Exception $e) {
wfDebugLog('ExtendedSearch', __METHOD__ . ' Error in _sendRawPost ' . $e->getMessage());
wfProfileOut('BS::' . __METHOD__);
return new Apache_Solr_Response('');
}
if ($response->getHttpStatus() != 200) {
wfDebugLog('ExtendedSearch', __METHOD__ . ' Error in _sendRawPost ' . var_export($response, 1));
wfProfileOut('BS::' . __METHOD__);
throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
}
wfProfileOut('BS::' . __METHOD__);
return $response;
}
开发者ID:hfroese,项目名称:mediawiki-extensions-BlueSpiceExtensions,代码行数:44,代码来源:SolrServiceAdapter.class.php
示例11: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $url
* @param string $rawPost
* @param float $timeout Read timeout in seconds
* @param string $contentType
* @return Apache_Solr_Response
*
* @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
*/
protected function _sendRawPost($url, $rawPost, $timeout = false, $contentType = 'text/xml; charset=UTF-8')
{
$httpTransport = $this->getHttpTransport();
$httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($solrResponse->getHttpStatus() != 200) {
throw new Apache_Solr_HttpTransportException($solrResponse);
}
return $solrResponse;
}
示例12: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $url
* @param string $rawPost
* @param float $timeout Read timeout in seconds
* @param string $contentType
* @return Apache_Solr_Response
*
* @throws Exception If a non 200 response status is returned
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
//set up the stream context for posting with file_get_contents
$context = stream_context_create(
array(
'http' => array(
// set HTTP method
'method' => 'POST',
// Add our posted content type
'header' => "Content-Type: $contentType",
// the posted content
'content' => $rawPost
)
)
);
// set the timeout if specified, without this I assume
// that the default_socket_timeout ini setting is used
if ($timeout !== FALSE && $timeout > 0.0)
{
// timeouts with file_get_contents seem to need
// to be halved to work as expected
$timeout = (float) $timeout / 2;
stream_context_set_option($context, 'http', 'timeout', $timeout);
}
//$http_response_header is set by file_get_contents
$response = new Apache_Solr_Response(@file_get_contents($url, false, $context), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
if ($response->getHttpStatus() != 200)
{
throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
}
return $response;
}
示例13: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $url
* @param string $rawPost
* @param string $contentType
* @return Apache_Solr_Response
*
* @throws Exception If a non 200 response status is returned
*/
private function _sendRawPost($url, $rawPost, $contentType = 'text/xml; charset=UTF-8')
{
//ensure content type is correct
stream_context_set_option($this->_postContext, 'http', 'header', 'Content-Type: ' . $contentType . "\r\n");
//set the content
stream_context_set_option($this->_postContext, 'http', 'content', $rawPost);
//$http_response_header is set by file_get_contents
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header);
if ($response->getHttpStatus() != 200) {
throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage());
}
return $response;
}
示例14: _sendRawPost
/**
* Central method for making a post operation against this Solr Server
*
* @param string $url
* @param string $rawPost
* @param float $timeout Read timeout in seconds
* @param string $contentType
* @return Apache_Solr_Response
* @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
*/
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
{
stream_context_set_option($this->_postContext, array('http' => array('method' => 'POST', 'header' => "Content-Type: {$contentType}", 'content' => $rawPost, 'timeout' => $this->_defaultTimeout)));
// set the timeout if specified
if ($timeout !== FALSE && $timeout > 0.0) {
// timeouts with file_get_contents seem to need
// to be halved to work as expected
$timeout = (double) $timeout / 2;
stream_context_set_option($this->_postContext, 'http', 'timeout', $timeout);
}
// Proxy settings
if ($proxyServer = parse_url($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
if ($proxyServer['host'] && $proxyServer['port']) {
stream_context_set_option($this->_postContext, 'http', 'proxy', $proxyServer['host'] . ":" . $proxyServer['port'] . "/");
stream_context_set_option($this->_postContext, 'http', 'request_fulluri', true);
}
}
// $http_response_header will be updated by the call to file_get_contents later
// see http://us.php.net/manual/en/wrappers.http.php for documentation
// Unfortunately, it will still create a notice in analyzers if we don't set it here
$http_response_header = null;
//$url = $url . "?commit=true -H \"Content-Type: text/xml\" --data-binary '". $rawPost . "'";
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
//var_dump("Response:" . file_get_contents($url, false, $this->_postContext));
//exit;
if ($response->getHttpStatus() != 200) {
throw new Apache_Solr_HttpTransportException($response);
}
return $response;
}
示例15: reloadCore
/**
* Reloads a single Solr core.
*
* @param SolrService $solrServer A Solr server connection
* @param string $coreName Name of the core to reload
* @return bool TRUE if reloading the core was successful, FALSE otherwise
*/
protected function reloadCore(SolrService $solrServer, $coreName)
{
$coreReloaded = FALSE;
$path = $solrServer->getPath();
$pathElements = explode('/', trim($path, '/'));
$coreAdminReloadUrl = $solrServer->getScheme() . '://' . $solrServer->getHost() . ':' . $solrServer->getPort() . '/' . $pathElements[0] . '/' . 'admin/cores?action=reload&core=' . $coreName;
$httpTransport = $solrServer->getHttpTransport();
$httpResponse = $httpTransport->performGetRequest($coreAdminReloadUrl);
$solrResponse = new \Apache_Solr_Response($httpResponse, $solrServer->getCreateDocuments(), $solrServer->getCollapseSingleValueArrays());
if ($solrResponse->getHttpStatus() == 200) {
$coreReloaded = TRUE;
}
return $coreReloaded;
}