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