本文整理汇总了PHP中Elastica\Query::addFacet方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::addFacet方法的具体用法?PHP Query::addFacet怎么用?PHP Query::addFacet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Query
的用法示例。
在下文中一共展示了Query::addFacet方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTest
public function testTest()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$mapping = new Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss')));
$type->setMapping($mapping);
$doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
$type->addDocument($doc);
$doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
$type->addDocument($doc);
$doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
$type->addDocument($doc);
$facet = new DateHistogram('dateHist1');
$facet->setInterval("day");
$facet->setField("dtmPosted");
$query = new Query();
$query->addFacet($facet);
$query->setQuery(new MatchAll());
$index->refresh();
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(4, $response->getTotalHits());
$this->assertEquals(2, count($facets['dateHist1']['entries']));
}
示例2: testFactor
/**
* @group functional
*/
public function testFactor()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$mapping = new Mapping($type, array('name' => array('type' => 'string', 'store' => 'no'), 'dtmPosted' => array('type' => 'long', 'store' => 'no')));
$type->setMapping($mapping);
$doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => 1308865980));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => 1308822780));
$type->addDocument($doc);
$doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => 1310115180));
$type->addDocument($doc);
$doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => 1310089980));
$type->addDocument($doc);
$facet = new DateHistogram('dateHist1');
$facet->setInterval('day');
$facet->setField('dtmPosted');
$facet->setFactor(1000);
$query = new Query();
$query->addFacet($facet);
$query->setQuery(new MatchAll());
$index->refresh();
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(4, $response->getTotalHits());
$this->assertEquals(2, count($facets['dateHist1']['entries']));
}
示例3: testFilter
/**
* @group functional
*/
public function testFilter()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$type->addDocument(new Document(1, array('color' => 'red')));
$type->addDocument(new Document(2, array('color' => 'green')));
$type->addDocument(new Document(3, array('color' => 'blue')));
$index->refresh();
$filter = new Term(array('color' => 'red'));
$facet = new Filter('test');
$facet->setFilter($filter);
$query = new Query();
$query->addFacet($facet);
$resultSet = $type->search($query);
$facets = $resultSet->getFacets();
$this->assertEquals(1, $facets['test']['count']);
}
示例4: addFacets
/**
*
* Add facets on top of Elastica query
* @param \Elastica\Query $query
* @param array $options
* @param \Elastica\Filter\Bool $mainFilter
*/
public function addFacets(\Elastica\Query $query, $options, \Elastica\Filter\Bool $mainFilter)
{
// only add additional facets if a specific module is selected
if (!$this->isOptionsModuleFilterValid($options)) {
return;
}
$module = array_shift($options['moduleFilter']);
$facetDefs = $this->loadFacetDefs($module);
foreach ($facetDefs as $field => $facetDef) {
if ($facet = FacetFactory::get($facetDef['type'])) {
// set options from facet definition
$facet->setOptions($facetDef['options']);
// get Elastica facet object and assign it to the query
if ($eFacet = $facet->getFacet($field, $mainFilter)) {
$query->addFacet($eFacet);
}
}
}
}
示例5: testFacetScript
/**
* @group functional
*/
public function testFacetScript()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$doc = new Document(1, array('name' => 'rodolfo', 'last_name' => 'moraes'));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'jose', 'last_name' => 'honjoya'));
$type->addDocument($doc);
$facet = new Terms('test');
$facet->setField('name');
$facet->setScript('term + " "+doc["last_name"].value');
$query = new Query();
$query->addFacet($facet);
$query->setQuery(new MatchAll());
$index->refresh();
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(2, count($facets['test']['terms']));
}
示例6: testQuery
public function testQuery()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$doc = new Document(1, array('name' => 'nicolas ruflin'));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'ruflin test'));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'nicolas helloworld'));
$type->addDocument($doc);
$facet = new Terms('test');
$facet->setField('name');
$query = new Query();
$query->addFacet($facet);
$query->setQuery(new MatchAll());
$index->refresh();
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(3, count($facets['test']['terms']));
}
示例7: testQuery
public function testQuery()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$doc = new Document(1, array('name' => 'tom', 'paid' => 7));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'tom', 'paid' => 2));
$type->addDocument($doc);
$doc = new Document(3, array('name' => 'tom', 'paid' => 5));
$type->addDocument($doc);
$doc = new Document(4, array('name' => 'mike', 'paid' => 13));
$type->addDocument($doc);
$doc = new Document(5, array('name' => 'mike', 'paid' => 1));
$type->addDocument($doc);
$doc = new Document(6, array('name' => 'mike', 'paid' => 15));
$type->addDocument($doc);
$facet = new TermsStats('test');
$facet->setKeyField('name');
$facet->setValueField('paid');
$query = new Query();
$query->addFacet($facet);
$query->setQuery(new MatchAll());
$index->refresh();
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(2, count($facets['test']['terms']));
foreach ($facets['test']['terms'] as $facet) {
if ($facet['term'] === 'tom') {
$this->assertEquals(14, $facet['total']);
}
if ($facet['term'] === 'mike') {
$this->assertEquals(29, $facet['total']);
}
}
}
示例8: testStatisticalWithSetFields
/**
* @group functional
*/
public function testStatisticalWithSetFields()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('helloworld');
$doc = new Document(1, array('price' => 10, 'price2' => 20));
$type->addDocument($doc);
$doc = new Document(2, array('price' => 35, 'price2' => 70));
$type->addDocument($doc);
$doc = new Document(2, array('price' => 45, 'price2' => 90));
$type->addDocument($doc);
$facet = new Statistical('stats');
$facet->setFields(array('price', 'price2'));
$query = new Query();
$query->addFacet($facet);
$query->setQuery(new MatchAll());
$index->refresh();
$response = $type->search($query);
$facets = $response->getFacets();
$this->assertEquals(165, $facets['stats']['total']);
$this->assertEquals(10, $facets['stats']['min']);
$this->assertEquals(90, $facets['stats']['max']);
}
示例9: testAddFacetToArrayCast
/**
* @group unit
*/
public function testAddFacetToArrayCast()
{
$query = new Query();
$facet = new Terms('text');
$query->addFacet($facet);
$facet->setName('another text');
$anotherQuery = new Query();
$anotherQuery->addFacet($facet);
$this->assertNotEquals($query->toArray(), $anotherQuery->toArray());
}
示例10: addFacets
/**
*
* Add facets on elastic query object
* @param \Elastica\Query $query
* @param array $options
* @param \Elastica\Filter\AbstractFilter $mainFilter
*/
protected function addFacets(\Elastica\Query $query, $options = array(), \Elastica\Filter\AbstractFilter $mainFilter = null)
{
// module facet (note: would be less confusing to give another name instead of _type)
if (!empty($options['apply_module_facet'])) {
$typeFacet = new \Elastica\Facet\Terms('_type');
$typeFacet->setField('_type');
// need to add filter for facet too
if (isset($mainFilter)) {
$typeFacet->setFilter($mainFilter);
}
$query->addFacet($typeFacet);
}
// handle secondary facets
$this->facetHandler->addFacets($query, $options, $mainFilter);
}