當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Index::createSearch方法代碼示例

本文整理匯總了PHP中Elastica\Index::createSearch方法的典型用法代碼示例。如果您正苦於以下問題:PHP Index::createSearch方法的具體用法?PHP Index::createSearch怎麽用?PHP Index::createSearch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Elastica\Index的用法示例。


在下文中一共展示了Index::createSearch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 = [])
 {
     // prepare search
     $search = $oldIndex->createSearch();
     $options = array_merge([self::OPTION_TYPE => null, self::OPTION_QUERY => new MatchAll(), self::OPTION_EXPIRY_TIME => '1m', self::OPTION_SIZE_PER_SHARD => 1000], $options);
     if (isset($options[self::OPTION_TYPE])) {
         $type = $options[self::OPTION_TYPE];
         $search->addTypes(is_array($type) ? $type : [$type]);
     }
     $search->setQuery($options[self::OPTION_QUERY]);
     // search on old index and bulk insert in new index
     $scroll = new Scroll($search, $options[self::OPTION_EXPIRY_TIME]);
     foreach ($scroll 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:ruflin,項目名稱:elastica,代碼行數:38,代碼來源:CrossIndex.php

示例2: testCreateSearch

 /**
  * @group functional
  */
 public function testCreateSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $query = new QueryString('test');
     $options = 5;
     $search = $index->createSearch($query, $options);
     $expected = array('query' => array('query_string' => array('query' => 'test')), 'size' => 5);
     $this->assertEquals($expected, $search->getQuery()->toArray());
     $this->assertEquals(array('test'), $search->getIndices());
     $this->assertTrue($search->hasIndices());
     $this->assertTrue($search->hasIndex('test'));
     $this->assertTrue($search->hasIndex($index));
     $this->assertEquals(array(), $search->getTypes());
     $this->assertFalse($search->hasTypes());
     $this->assertFalse($search->hasType('test_type'));
     $type = new Type($index, 'test_type2');
     $this->assertFalse($search->hasType($type));
 }
開發者ID:MediaWiki-stable,項目名稱:1.26.0,代碼行數:22,代碼來源:IndexTest.php


注:本文中的Elastica\Index::createSearch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。