本文整理汇总了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());
}