本文整理匯總了PHP中Elastica\Query::setFacets方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::setFacets方法的具體用法?PHP Query::setFacets怎麽用?PHP Query::setFacets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Elastica\Query
的用法示例。
在下文中一共展示了Query::setFacets方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testQuery
/**
* @group functional
*/
public function testQuery()
{
$client = $this->_getClient();
$nodes = $client->getCluster()->getNodes();
if (!$nodes[0]->getInfo()->hasPlugin('geocluster-facet')) {
$this->markTestSkipped('geocluster-facet plugin not installed');
}
$index = $this->_createIndex();
$type = $index->getType('testQuery');
$geoField = 'location';
$type->setMapping(new Mapping($type, array($geoField => array('type' => 'geo_point', 'lat_lon' => true))));
$doc = new Document(1, array('name' => 'item1', 'location' => array(20, 20)));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'item2', 'location' => array(20, 20)));
$type->addDocument($doc);
$doc = new Document(3, array('name' => 'item3', 'location' => array(20, 20)));
$type->addDocument($doc);
$index->refresh();
$facet = new GeoCluster('clusters');
$facet->setField($geoField)->setFactor(1)->setShowIds(false);
$query = new Query();
$query->setFacets(array($facet));
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(1, count($facets['clusters']['clusters']));
$index->delete();
}
示例2: testSetFacets
/**
* @group unit
*/
public function testSetFacets()
{
$query = new Query();
$facet = new Terms('text');
$query->setFacets(array($facet));
$data = $query->toArray();
$this->assertArrayHasKey('facets', $data);
$this->assertEquals(array('text' => array('terms' => array())), $data['facets']);
$query->setFacets(array());
$this->assertArrayNotHasKey('facets', $query->toArray());
}