當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。