本文整理汇总了PHP中Elastica\Search::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::count方法的具体用法?PHP Search::count怎么用?PHP Search::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Search
的用法示例。
在下文中一共展示了Search::count方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getElasticaCount
/**
* Get Query Count
*
* @param string $index
* @param string $type
*
* @return number
*/
public function getElasticaCount($index = false, $type = false)
{
$elastica_query = new Query();
$elastica_client = $this->getElasticaClient();
// If you want to restrict your search to a particular index then get
// that
$elastica_index = $index ? $elastica_client->getIndex($index) : false;
// If you want to restrict your search to a particular type then get
// that
$elastica_type = $elastica_index && $type ? $elastica_index->getType($type) : false;
$elastica_search = new Search($elastica_client);
if ($elastica_index) {
$elastica_search->addIndex($elastica_index);
}
if ($elastica_type) {
$elastica_search->addType($elastica_type);
}
return $elastica_search->count($elastica_query);
}
示例2: searchAction
public function searchAction()
{
//WIP, todo: export to repository and use it in Search Playlists
$elasticaClient = new Client();
$playListIndex = $elasticaClient->getIndex('playlist');
$trackType = $playListIndex->getType('track');
$search = new Search($elasticaClient);
$search->addIndex($playListIndex)->addType($trackType);
$query = new Query();
$query->setSize(5)->setSort(['name' => 'asc'])->setFields(['name', 'ids', 'id', 'composer'])->setExplain(true)->setVersion(true)->setHighlight(['fields' => 'composer']);
$query->setQuery(new MatchAll());
// $query->addAggregation(new \Elastica\Aggregation\Range('name'));
// $term = new \Elastica\Suggest\Term('name', 'field');
// $term->setText('aaaaa');
// $query->setSuggest(new \Elastica\Suggest($term));
// $query->setFacets([new \Elastica\Facet\Range('name')]);
$search->setQuery($query);
$resultSet = $search->search();
$numberOfEntries = $search->count();
$results = $resultSet->getResults();
$totalResults = $resultSet->getTotalHits();
return $this->render('PlayWithElasticSearchBundle:Elastica:search.html.twig', ['query' => $query, 'numberOfEntries' => $numberOfEntries, 'resultSet' => $resultSet, 'results' => $results, 'totalResults' => $totalResults]);
}
示例3: testCount
/**
* @group functional
*/
public function testCount()
{
$index = $this->_createIndex();
$search = new Search($index->getClient());
$type = $index->getType('test');
$doc = new Document(1, array('id' => 1, 'username' => 'ruflin'));
$type->addDocument($doc);
$index->refresh();
$search->addIndex($index);
$search->addType($type);
$result1 = $search->count(new \Elastica\Query\MatchAll());
$this->assertEquals(1, $result1);
$result2 = $search->count(new \Elastica\Query\MatchAll(), true);
$this->assertInstanceOf('\\Elastica\\ResultSet', $result2);
$this->assertEquals(1, $result2->getTotalHits());
}
示例4: getItemCount
/**
* {@inheritDoc}
*
* @api
*/
public function getItemCount()
{
return $this->search->count();
}
示例5: count
/**
* Invoke Elasticsearch count.
*
* @param Query $query
* @param string $index
* @param string $type
* @param array $options
*
* @return \Elastica\ResultSet
*/
public function count($query, $type, $index = 'activehire', $options = [])
{
$search = new Search($this->client);
$search->addType($type);
$search->addIndex($index);
$search->setOptions($options);
$result = $search->count($query);
return $result;
}
示例6: getCount
function getCount()
{
$search = new Search($this->client);
$count = $search->count($this->query->toArray());
return $count->count();
}
示例7: testCountRequest
public function testCountRequest()
{
$client = $this->_getClient();
$search = new Search($client);
$index = $client->getIndex('zero');
$index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
$docs = array();
$docs[] = new Document(1, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(2, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(3, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(4, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(5, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(6, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(7, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(8, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(9, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(10, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$docs[] = new Document(11, array('id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley'));
$type = $index->getType('zeroType');
$type->addDocuments($docs);
$index->refresh();
$search->addIndex($index)->addType($type);
$count = $search->count('farrelley');
$this->assertEquals(11, $count);
}