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


PHP Search::setOption方法代碼示例

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


在下文中一共展示了Search::setOption方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildQuery

 protected function buildQuery(array $classes)
 {
     $searchQuery = new Search($this->client);
     $searchQuery->setOption(Search::OPTION_VERSION, true);
     foreach ($classes as $class) {
         if ($class->index) {
             $indexObject = $this->getIndex($class->index);
             $searchQuery->addIndex($indexObject);
             if ($class->type) {
                 $searchQuery->addType($indexObject->getType($class->type));
             }
         }
     }
     return $searchQuery;
 }
開發者ID:akleiber,項目名稱:search,代碼行數:15,代碼來源:Client.php

示例2: testQueryCacheOption

 /**
  * @group functional
  */
 public function testQueryCacheOption()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('zero');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $type = $index->getType('zeroType');
     $type->addDocuments(array(new Document(1, array('id' => 1, 'username' => 'farrelley')), new Document(2, array('id' => 2, 'username' => 'bunny'))));
     $index->refresh();
     $aggregation = new Aggregation\Terms('username');
     $aggregation->setField('username');
     $query = new Query();
     $query->addAggregation($aggregation);
     $search = new Search($client);
     $search->addIndex($index);
     $search->setQuery($query);
     $search->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_COUNT);
     $search->setOption(Search::OPTION_QUERY_CACHE, true);
     // before search query cache should be empty
     $statsData = $index->getStats()->getData();
     $queryCache = $statsData['_all']['primaries']['query_cache'];
     $this->assertEquals(0, $queryCache['memory_size_in_bytes']);
     $this->assertEquals(0, $queryCache['evictions']);
     $this->assertEquals(0, $queryCache['hit_count']);
     $this->assertEquals(0, $queryCache['miss_count']);
     // first search should result in cache miss and save data to cache
     $search->search();
     $index->getStats()->refresh();
     $statsData = $index->getStats()->getData();
     $queryCache = $statsData['_all']['primaries']['query_cache'];
     $this->assertNotEquals(0, $queryCache['memory_size_in_bytes']);
     $this->assertEquals(0, $queryCache['evictions']);
     $this->assertEquals(0, $queryCache['hit_count']);
     $this->assertEquals(1, $queryCache['miss_count']);
     // next search should result in cache hit
     $search->search();
     $index->getStats()->refresh();
     $statsData = $index->getStats()->getData();
     $queryCache = $statsData['_all']['primaries']['query_cache'];
     $this->assertNotEquals(0, $queryCache['memory_size_in_bytes']);
     $this->assertEquals(0, $queryCache['evictions']);
     $this->assertEquals(1, $queryCache['hit_count']);
     $this->assertEquals(1, $queryCache['miss_count']);
 }
開發者ID:nadeem-khan,項目名稱:Elastica,代碼行數:46,代碼來源:SearchTest.php

示例3: buildCount

 /**
  * Build a Search that will count all pages that link to $titles.
  * @param string $titles title in prefixedDBKey form
  * @return Search that counts all pages that link to $titles
  */
 private function buildCount($titles)
 {
     $filter = new Terms('outgoing_link', $titles);
     $filter->setCached(false);
     // We're not going to be redoing this any time soon.
     $type = $this->connection->getPageType(wfWikiId());
     $search = new Search($type->getIndex()->getClient());
     $search->addIndex($type->getIndex());
     $search->addType($type);
     $search->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_COUNT);
     $matchAll = new MatchAll();
     $search->setQuery(new Filtered($matchAll, $filter));
     $search->getQuery()->addParam('stats', 'link_count');
     return $search;
 }
開發者ID:zoglun,項目名稱:mediawiki-extensions-CirrusSearch,代碼行數:20,代碼來源:RedirectsAndIncomingLinks.php


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