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


PHP Search::getClient方法代码示例

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


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

示例1: testSearchScrollRequest

 /**
  * @group functional
  */
 public function testSearchScrollRequest()
 {
     $client = $this->_getClient();
     $index = $this->_createIndex();
     $type = $index->getType('scrolltest');
     $docs = array();
     for ($x = 1; $x <= 10; ++$x) {
         $docs[] = new Document($x, array('id' => $x, 'testscroll' => 'jbafford'));
     }
     $type->addDocuments($docs);
     $index->refresh();
     $search = new Search($client);
     $search->addIndex($index)->addType($type);
     $result = $search->search(array(), array(Search::OPTION_SEARCH_TYPE => Search::OPTION_SEARCH_TYPE_SCAN, Search::OPTION_SCROLL => '5m', Search::OPTION_SIZE => 5));
     $this->assertFalse($result->getResponse()->hasError());
     $scrollId = $result->getResponse()->getScrollId();
     $this->assertNotEmpty($scrollId);
     //There are 10 items, and we're scrolling with a size of 5
     //So we should get two results of 5 items, and then no items
     //We should also have sent the raw scroll_id as the HTTP request body
     $search = new Search($client);
     $result = $search->search(array(), array(Search::OPTION_SCROLL => '5m', Search::OPTION_SCROLL_ID => $scrollId));
     $this->assertFalse($result->getResponse()->hasError());
     $this->assertEquals(5, count($result->getResults()));
     $this->assertArrayNotHasKey(Search::OPTION_SCROLL_ID, $search->getClient()->getLastRequest()->getQuery());
     $this->assertEquals($scrollId, $search->getClient()->getLastRequest()->getData());
     $result = $search->search(array(), array(Search::OPTION_SCROLL => '5m', Search::OPTION_SCROLL_ID => $scrollId));
     $this->assertFalse($result->getResponse()->hasError());
     $this->assertEquals(5, count($result->getResults()));
     $this->assertArrayNotHasKey(Search::OPTION_SCROLL_ID, $search->getClient()->getLastRequest()->getQuery());
     $this->assertEquals($scrollId, $search->getClient()->getLastRequest()->getData());
     $result = $search->search(array(), array(Search::OPTION_SCROLL => '5m', Search::OPTION_SCROLL_ID => $scrollId));
     $this->assertFalse($result->getResponse()->hasError());
     $this->assertEquals(0, count($result->getResults()));
     $this->assertArrayNotHasKey(Search::OPTION_SCROLL_ID, $search->getClient()->getLastRequest()->getQuery());
     $this->assertEquals($scrollId, $search->getClient()->getLastRequest()->getData());
 }
开发者ID:levijackson,项目名称:Elastica,代码行数:40,代码来源:SearchTest.php


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