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


PHP SearchResult::getHit方法代码示例

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


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

示例1: cleanupElasticsearch

 /**
  * Find documents in Elasticsearch which don't exist in Elgg anymore
  *
  * @return void
  */
 protected static function cleanupElasticsearch()
 {
     $client = elasticsearch_get_client();
     if (empty($client)) {
         return;
     }
     // this could take a while
     set_time_limit(0);
     // prepare a search for all documents
     $search_params = ['index' => $client->getIndex(), 'search_type' => 'scan', 'scroll' => '2m', 'body' => ['query' => ['match_all' => []]]];
     try {
         $scroll_setup = $client->search($search_params);
     } catch (\Exception $e) {
         return;
     }
     // now scroll through all results
     $scroll_params = ['scroll_id' => elgg_extract('_scroll_id', $scroll_setup), 'scroll' => '2m'];
     // ignore Elgg access
     $ia = elgg_set_ignore_access(true);
     try {
         while ($result = $client->scroll($scroll_params)) {
             $search_result = new SearchResult($result, $search_params);
             $elasticsearch_guids = $search_result->toGuids();
             if (empty($elasticsearch_guids)) {
                 break;
             }
             $elgg_guids = elgg_get_entities(['guids' => $elasticsearch_guids, 'limit' => false, 'callback' => function ($row) {
                 return (int) $row->guid;
             }]);
             $guids_not_in_elgg = array_diff($elasticsearch_guids, $elgg_guids);
             if (empty($guids_not_in_elgg)) {
                 continue;
             }
             // remove all left over documents
             foreach ($guids_not_in_elgg as $guid) {
                 // need to get the hist from Elasticsearch to get the type, since it's not in Elgg anymore
                 $hit = $search_result->getHit($guid);
                 elasticsearch_add_document_for_deletion($guid, ['_index' => $client->getIndex(), '_type' => elgg_extract('_type', $hit), '_id' => $guid]);
             }
         }
     } catch (\Exception $e) {
         // probably reached the end of the scroll
         // elgg_log('Elasticsearch cleanup: ' . $e->getMessage(), 'ERROR');
     }
     // restore access
     elgg_set_ignore_access($ia);
     // clear scroll
     try {
         $client->clearScroll($scroll_params);
     } catch (\Exception $e) {
         // unable to clean, could be because we came to the end of the scroll
     }
 }
开发者ID:ColdTrick,项目名称:elasticsearch,代码行数:58,代码来源:Cron.php

示例2: inspect

 /**
  * Inspect a GUID in Elasticsearch
  *
  * @param int $guid the GUID to inspect
  *
  * @return false|array
  */
 public function inspect($guid)
 {
     $guid = (int) $guid;
     if ($guid < 1) {
         return false;
     }
     $search_params = ['index' => $this->getIndex(), 'body' => ['query' => ['filtered' => ['filter' => ['term' => ['guid' => $guid]]]]]];
     try {
         $search_result = $this->search($search_params);
         $s = new SearchResult($search_result, $search_params);
         $hit = $s->getHit($guid);
         if (empty($hit)) {
             return false;
         }
         return elgg_extract('_source', $hit);
     } catch (\Exception $e) {
         // somethig went wrong
     }
     return false;
 }
开发者ID:ColdTrick,项目名称:elasticsearch,代码行数:27,代码来源:Client.php


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