当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::getData方法代码示例

本文整理汇总了PHP中Elastica\Response::getData方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getData方法的具体用法?PHP Response::getData怎么用?PHP Response::getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Response的用法示例。


在下文中一共展示了Response::getData方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildResults

 /**
  * Builds individual result objects.
  *
  * @param Response $response
  *
  * @return Result[]
  */
 private function buildResults(Response $response)
 {
     $data = $response->getData();
     $results = [];
     if (!isset($data['hits']['hits'])) {
         return $results;
     }
     foreach ($data['hits']['hits'] as $hit) {
         $results[] = new Result($hit);
     }
     return $results;
 }
开发者ID:ruflin,项目名称:elastica,代码行数:19,代码来源:DefaultBuilder.php

示例2: _log

 /**
  * logging.
  *
  * @deprecated Overwriting Client->_log is deprecated. Handle logging functionality by using a custom LoggerInterface.
  *
  * @param mixed $context
  */
 protected function _log($context)
 {
     if ($context instanceof ConnectionException) {
         $this->_logger->error('Elastica Request Failure', ['exception' => $context, 'request' => $context->getRequest()->toArray(), 'retry' => $this->hasConnection()]);
         return;
     }
     if ($context instanceof Request) {
         $this->_logger->debug('Elastica Request', ['request' => $context->toArray(), 'response' => $this->_lastResponse ? $this->_lastResponse->getData() : null, 'responseStatus' => $this->_lastResponse ? $this->_lastResponse->getStatus() : null]);
         return;
     }
     $this->_logger->debug('Elastica Request', ['message' => $context]);
 }
开发者ID:ruflin,项目名称:elastica,代码行数:19,代码来源:Client.php

示例3: _init

 /**
  * Loads all data into the results object (initialisation)
  *
  * @param \Elastica\Response $response Response object
  */
 protected function _init(Response $response)
 {
     $this->_response = $response;
     $result = $response->getData();
     $this->_totalHits = isset($result['hits']['total']) ? $result['hits']['total'] : 0;
     $this->_maxScore = isset($result['hits']['max_score']) ? $result['hits']['max_score'] : 0;
     $this->_took = isset($result['took']) ? $result['took'] : 0;
     $this->_timedOut = !empty($result['timed_out']);
     if (isset($result['hits']['hits'])) {
         foreach ($result['hits']['hits'] as $hit) {
             $this->_results[] = new Result($hit);
         }
     }
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:19,代码来源:ResultSet.php

示例4: buildResultSets

 /**
  * @param Response     $response
  * @param BaseSearch[] $searches
  *
  * @return \Elastica\ResultSet[]
  */
 private function buildResultSets(Response $response, $searches)
 {
     $data = $response->getData();
     if (!isset($data['responses']) || !is_array($data['responses'])) {
         return [];
     }
     $resultSets = [];
     reset($searches);
     foreach ($data['responses'] as $responseData) {
         list($key, $search) = each($searches);
         $resultSets[$key] = $this->buildResultSet(new Response($responseData), $search);
     }
     return $resultSets;
 }
开发者ID:ruflin,项目名称:elastica,代码行数:20,代码来源:MultiBuilder.php

示例5: _init

 /**
  * @param  \Elastica\Response                   $response
  * @param  array|\Elastica\Search[]             $searches
  * @throws \Elastica\Exception\InvalidException
  */
 protected function _init(Response $response, array $searches)
 {
     $this->_response = $response;
     $responseData = $response->getData();
     if (isset($responseData['responses']) && is_array($responseData['responses'])) {
         foreach ($responseData['responses'] as $key => $responseData) {
             if (!isset($searches[$key])) {
                 throw new InvalidException('No result found for search #' . $key);
             } elseif (!$searches[$key] instanceof BaseSearch) {
                 throw new InvalidException('Invalid object for search #' . $key . ' provided. Should be Elastica\\Search');
             }
             $search = $searches[$key];
             $query = $search->getQuery();
             $response = new Response($responseData);
             $this->_resultSets[] = new BaseResultSet($response, $query);
         }
     }
 }
开发者ID:kskod,项目名称:Elastica,代码行数:23,代码来源:ResultSet.php

示例6: _init

 /**
  * Loads all data into the results object (initialisation)
  *
  * @param \Elastica\Response $response Response object
  */
 protected function _init(Response $response)
 {
     $this->_response = $response;
     $result = $response->getData();
     $this->_totalHits = isset($result['hits']['total']) ? $result['hits']['total'] : 0;
     $this->_maxScore = isset($result['hits']['max_score']) ? $result['hits']['max_score'] : 0;
     $this->_took = isset($result['took']) ? $result['took'] : 0;
     $this->_timedOut = !empty($result['timed_out']);
     if (isset($result['hits']['hits'])) {
         foreach ($result['hits']['hits'] as $hit) {
             $this->_results[] = new Result($hit);
         }
     }
     foreach ($result as $key => $value) {
         if ($key != '_shards') {
             if (isset($value[0]['options']) && count($value[0]['options']) > 0) {
                 $this->_suggests[$key] = $value[0];
             }
         }
     }
 }
开发者ID:raadhuis,项目名称:modx-basic,代码行数:26,代码来源:ResultSet.php

示例7: _processResponse

 /**
  * @param \Elastica\Response $response
  *
  * @throws \Elastica\Exception\Bulk\ResponseException
  * @throws \Elastica\Exception\InvalidException
  *
  * @return \Elastica\Bulk\ResponseSet
  */
 protected function _processResponse(Response $response)
 {
     $responseData = $response->getData();
     $actions = $this->getActions();
     $bulkResponses = array();
     if (isset($responseData['items']) && is_array($responseData['items'])) {
         foreach ($responseData['items'] as $key => $item) {
             if (!isset($actions[$key])) {
                 throw new InvalidException('No response found for action #' . $key);
             }
             $action = $actions[$key];
             $opType = key($item);
             $bulkResponseData = reset($item);
             if ($action instanceof AbstractDocumentAction) {
                 $data = $action->getData();
                 if ($data instanceof Document && $data->isAutoPopulate() || $this->_client->getConfigValue(array('document', 'autoPopulate'), false)) {
                     if (!$data->hasId() && isset($bulkResponseData['_id'])) {
                         $data->setId($bulkResponseData['_id']);
                     }
                     if (isset($bulkResponseData['_version'])) {
                         $data->setVersion($bulkResponseData['_version']);
                     }
                 }
             }
             $bulkResponses[] = new BulkResponse($bulkResponseData, $action, $opType);
         }
     }
     $bulkResponseSet = new ResponseSet($response, $bulkResponses);
     if ($bulkResponseSet->hasError()) {
         throw new BulkResponseException($bulkResponseSet);
     }
     return $bulkResponseSet;
 }
开发者ID:levijackson,项目名称:Elastica,代码行数:41,代码来源:Bulk.php

示例8: _populateDocumentFieldsFromResponse

 /**
  * @param \Elastica\Response $response
  * @param \Elastica\Document $document
  * @param string             $fields   Array of field names to be populated or '_source' if whole document data should be updated
  */
 protected function _populateDocumentFieldsFromResponse(Response $response, Document $document, $fields)
 {
     $responseData = $response->getData();
     if ('_source' == $fields) {
         if (isset($responseData['get']['_source']) && is_array($responseData['get']['_source'])) {
             $document->setData($responseData['get']['_source']);
         }
     } else {
         $keys = explode(',', $fields);
         $data = $document->getData();
         foreach ($keys as $key) {
             if (isset($responseData['get']['fields'][$key])) {
                 $data[$key] = $responseData['get']['fields'][$key];
             } elseif (isset($data[$key])) {
                 unset($data[$key]);
             }
         }
         $document->setData($data);
     }
 }
开发者ID:backplane,项目名称:elastica,代码行数:25,代码来源:Client.php

示例9: postProcessSuggest

 /**
  * merge top level multi-queries and resolve returned pageIds into Title objects.
  *
  * WARNING: experimental API
  *
  * @param string $query the user query
  * @param \Elastica\Response $response Response from elasticsearch _suggest api
  * @param array $profile the suggestion profile
  * @param int $limit Maximum suggestions to return, -1 for unlimited
  * @return Title[] List of suggested titles
  */
 protected function postProcessSuggest($query, \Elastica\Response $response, $profile, $limit = -1)
 {
     $this->logContext['elasticTookMs'] = intval($response->getQueryTime() * 1000);
     $data = $response->getData();
     unset($data['_shards']);
     $suggestions = array();
     foreach ($data as $name => $results) {
         $discount = $profile[$name]['discount'];
         foreach ($results as $suggested) {
             foreach ($suggested['options'] as $suggest) {
                 $output = explode(':', $suggest['text'], 3);
                 if (sizeof($output) < 2) {
                     // Ignore broken output
                     continue;
                 }
                 $pageId = $output[0];
                 $type = $output[1];
                 $score = $discount * $suggest['score'];
                 if (!isset($suggestions[$pageId]) || $score > $suggestions[$pageId]['score']) {
                     $suggestion = array('score' => $score, 'pageId' => $pageId);
                     // If it's a title suggestion we have the text
                     if ($type === 't' && sizeof($output) == 3) {
                         $suggestion['text'] = $output[2];
                     }
                     $suggestions[$pageId] = $suggestion;
                 }
             }
         }
     }
     // simply sort by existing scores
     uasort($suggestions, function ($a, $b) {
         return $b['score'] - $a['score'];
     });
     $this->logContext['hitsTotal'] = count($suggestions);
     if ($limit > 0) {
         $suggestions = array_slice($suggestions, 0, $limit, true);
     }
     $this->logContext['hitsReturned'] = count($suggestions);
     $this->logContext['hitsOffset'] = 0;
     // we must fetch redirect data for redirect suggestions
     $missingText = array();
     foreach ($suggestions as $id => $suggestion) {
         if (!isset($suggestion['text'])) {
             $missingText[] = $id;
         }
     }
     if (!empty($missingText)) {
         // Experimental.
         //
         // Second pass query to fetch redirects.
         // It's not clear if it's the best option, this will slowdown the whole query
         // when we hit a redirect suggestion.
         // Other option would be to encode redirects as a payload resulting in a
         // very big index...
         // XXX: we support only the content index
         $type = $this->connection->getPageType($this->indexBaseName, Connection::CONTENT_INDEX_TYPE);
         // NOTE: we are already in a poolCounterWork
         // Multi get is not supported by elastica
         $redirResponse = null;
         try {
             $redirResponse = $type->request('_mget', 'GET', array('ids' => $missingText), array('_source_include' => 'redirect'));
             if ($redirResponse->isOk()) {
                 $this->logContext['elasticTook2PassMs'] = intval($redirResponse->getQueryTime() * 1000);
                 $docs = $redirResponse->getData();
                 $docs = $docs['docs'];
                 foreach ($docs as $doc) {
                     $id = $doc['_id'];
                     if (!isset($doc['_source']['redirect']) || empty($doc['_source']['redirect'])) {
                         continue;
                     }
                     $text = Util::chooseBestRedirect($query, $doc['_source']['redirect']);
                     $suggestions[$id]['text'] = $text;
                 }
             } else {
                 LoggerFactory::getInstance('CirrusSearch')->warning('Unable to fetch redirects for suggestion {query} with results {ids} : {error}', array('query' => $query, 'ids' => serialize($missingText), 'error' => $redirResponse->getError()));
             }
         } catch (\Elastica\Exception\ExceptionInterface $e) {
             LoggerFactory::getInstance('CirrusSearch')->warning('Unable to fetch redirects for suggestion {query} with results {ids} : {error}', array('query' => $query, 'ids' => serialize($missingText), 'error' => $this->extractMessage($e)));
         }
     }
     $retval = array();
     foreach ($suggestions as $suggestion) {
         if (!isset($suggestion['text'])) {
             // We were unable to find a text to display
             // Maybe a page with redirects when we built the suggester index
             // but now without redirects?
             continue;
         }
         $retval[] = array('title' => Title::makeTitle(0, $suggestion['text']), 'pageId' => $suggestion['pageId'], 'score' => $suggestion['score']);
//.........这里部分代码省略.........
开发者ID:jamesmontalvo3,项目名称:mediawiki-extensions-CirrusSearch,代码行数:101,代码来源:Searcher.php

示例10: testDecodeResponseWithBigIntSetToTrue

 /**
  * @group unit
  */
 public function testDecodeResponseWithBigIntSetToTrue()
 {
     $response = new Response(json_encode(array('took' => 213, 'items' => array(array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)), array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 200))))));
     $response->setJsonBigintConversion(true);
     $this->assertTrue(is_array($response->getData()));
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:9,代码来源:ResponseTest.php

示例11: __construct

 /**
  * @param \Elastica\Response        $response
  * @param \Elastica\Bulk\Response[] $bulkResponses
  */
 public function __construct(BaseResponse $response, array $bulkResponses)
 {
     parent::__construct($response->getData());
     $this->_bulkResponses = $bulkResponses;
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:9,代码来源:ResponseSet.php

示例12: getCreatedDocId

 /**
  * Return last created document id from ES response
  * 
  * @param Response $response
  *        	Elastica Response object
  * @return string|null
  */
 protected function getCreatedDocId(Response $response)
 {
     $data = $response->getData();
     if (!empty($data['items'][0]['create']['_id'])) {
         return $data['items'][0]['create']['_id'];
     }
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:14,代码来源:ElasticSearchHandlerTest.php

示例13: postProcessSuggest

 /**
  * merge top level multi-queries and resolve returned pageIds into Title objects.
  *
  * WARNING: experimental API
  *
  * @param string $query the user query
  * @param \Elastica\Response $response Response from elasticsearch _suggest api
  * @param array $profiles the suggestion profiles
  * @param int $limit Maximum suggestions to return, -1 for unlimited
  * @return SearchSuggestionSet a set of Suggestions
  */
 protected function postProcessSuggest(\Elastica\Response $response, $profiles, $limit = -1)
 {
     $this->logContext['elasticTookMs'] = intval($response->getQueryTime() * 1000);
     $data = $response->getData();
     unset($data['_shards']);
     $suggestions = array();
     foreach ($data as $name => $results) {
         $discount = $profiles[$name]['discount'];
         foreach ($results as $suggested) {
             foreach ($suggested['options'] as $suggest) {
                 $output = SuggestBuilder::decodeOutput($suggest['text']);
                 if ($output === null) {
                     // Ignore broken output
                     continue;
                 }
                 $pageId = $output['id'];
                 $type = $output['type'];
                 $score = $discount * $suggest['score'];
                 if (!isset($suggestions[$pageId]) || $score > $suggestions[$pageId]->getScore()) {
                     $suggestion = new SearchSuggestion($score, null, null, $pageId);
                     // If it's a title suggestion we have the text
                     if ($type === SuggestBuilder::TITLE_SUGGESTION) {
                         $suggestion->setText($output['text']);
                     }
                     $suggestions[$pageId] = $suggestion;
                 }
             }
         }
     }
     // simply sort by existing scores
     uasort($suggestions, function ($a, $b) {
         return $b->getScore() - $a->getScore();
     });
     $this->logContext['hitsTotal'] = count($suggestions);
     if ($limit > 0) {
         $suggestions = array_slice($suggestions, 0, $limit, true);
     }
     $this->logContext['hitsReturned'] = count($suggestions);
     $this->logContext['hitsOffset'] = 0;
     // we must fetch redirect data for redirect suggestions
     $missingText = array();
     foreach ($suggestions as $id => $suggestion) {
         if ($suggestion->getText() === null) {
             $missingText[] = $id;
         }
     }
     if (!empty($missingText)) {
         // Experimental.
         //
         // Second pass query to fetch redirects.
         // It's not clear if it's the best option, this will slowdown the whole query
         // when we hit a redirect suggestion.
         // Other option would be to encode redirects as a payload resulting in a
         // very big index...
         // XXX: we support only the content index
         $type = $this->connection->getPageType($this->indexBaseName, Connection::CONTENT_INDEX_TYPE);
         // NOTE: we are already in a poolCounterWork
         // Multi get is not supported by elastica
         $redirResponse = null;
         try {
             $redirResponse = $type->request('_mget', 'GET', array('ids' => $missingText), array('_source_include' => 'redirect'));
             if ($redirResponse->isOk()) {
                 $this->logContext['elasticTook2PassMs'] = intval($redirResponse->getQueryTime() * 1000);
                 $docs = $redirResponse->getData();
                 foreach ($docs['docs'] as $doc) {
                     if (empty($doc['_source']['redirect'])) {
                         continue;
                     }
                     // We use the original query, we should maybe use the variant that generated this result?
                     $text = Util::chooseBestRedirect($this->term, $doc['_source']['redirect']);
                     if (!empty($suggestions[$doc['_id']])) {
                         $suggestions[$doc['_id']]->setText($text);
                     }
                 }
             } else {
                 LoggerFactory::getInstance('CirrusSearch')->warning('Unable to fetch redirects for suggestion {query} with results {ids} : {error}', array('query' => $this->term, 'ids' => serialize($missingText), 'error' => $redirResponse->getError()));
             }
         } catch (\Elastica\Exception\ExceptionInterface $e) {
             LoggerFactory::getInstance('CirrusSearch')->warning('Unable to fetch redirects for suggestion {query} with results {ids} : {error}', array('query' => $this->term, 'ids' => serialize($missingText), 'error' => $this->extractMessage($e)));
         }
     }
     return new SearchSuggestionSet(array_filter($suggestions, function ($suggestion) {
         // text should be not empty for suggestions
         return $suggestion->getText() != null;
     }));
 }
开发者ID:zoglun,项目名称:mediawiki-extensions-CirrusSearch,代码行数:97,代码来源:CompletionSuggester.php


注:本文中的Elastica\Response::getData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。