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


PHP Search::addTypes方法代码示例

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


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

示例1: reindex

 /**
  * Reindex documents from an old index to a new index.
  *
  * @link https://www.elastic.co/guide/en/elasticsearch/guide/master/reindex.html
  *
  * @param \Elastica\Index $oldIndex
  * @param \Elastica\Index $newIndex
  * @param array           $options  keys: CrossIndex::OPTION_* constants
  *
  * @return \Elastica\Index The new index object
  */
 public static function reindex(Index $oldIndex, Index $newIndex, array $options = array())
 {
     // prepare search
     $search = new Search($oldIndex->getClient());
     $options = array_merge(array(self::OPTION_TYPE => null, self::OPTION_QUERY => new MatchAll(), self::OPTION_EXPIRY_TIME => '1m', self::OPTION_SIZE_PER_SHARD => 1000), $options);
     $search->addIndex($oldIndex);
     if (isset($options[self::OPTION_TYPE])) {
         $type = $options[self::OPTION_TYPE];
         $search->addTypes(is_array($type) ? $type : array($type));
     }
     $search->setQuery($options[self::OPTION_QUERY]);
     // search on old index and bulk insert in new index
     $scanAndScroll = new ScanAndScroll($search, $options[self::OPTION_EXPIRY_TIME], $options[self::OPTION_SIZE_PER_SHARD]);
     foreach ($scanAndScroll as $resultSet) {
         $bulk = new Bulk($newIndex->getClient());
         $bulk->setIndex($newIndex);
         foreach ($resultSet as $result) {
             $action = new Bulk\Action();
             $action->setType($result->getType());
             $action->setId($result->getId());
             $action->setSource($result->getData());
             $bulk->addAction($action);
         }
         $bulk->send();
     }
     $newIndex->refresh();
     return $newIndex;
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:39,代码来源:CrossIndex.php

示例2: testAddTypes

 public function testAddTypes()
 {
     $client = $this->_getClient();
     $search = new Search($client);
     $index = $this->_createIndex();
     $types = array();
     $types[] = $index->getType('type1');
     $types[] = $index->getType('type2');
     $search->addTypes($types);
     $this->assertEquals(2, count($search->getTypes()));
 }
开发者ID:kskod,项目名称:Elastica,代码行数:11,代码来源:SearchTest.php

示例3: newSearch

 /**
  * Create a new elastica search.
  *
  * @param Client $client
  * @param Index $index
  * @param string|array $types
  * @return Search
  */
 protected function newSearch(Client $client, Index $index, $types)
 {
     if (is_string($types)) {
         $types = [$types];
     }
     $search = new Search($client);
     $search->addIndex($index);
     $search->addTypes($types);
     return $search;
 }
开发者ID:amrsoliman,项目名称:laralastica,代码行数:18,代码来源:Laralastica.php


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