本文整理汇总了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;
}
示例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']);
}
示例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;
}