summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Facet/GeoClusterTest.php
blob: f771ac3213bd739d1845a68e07bd927ec7f0cb06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Elastica\Test\Facet;

use Elastica\Document;
use Elastica\Facet\GeoCluster;
use Elastica\Query;
use Elastica\Test\Base as BaseTest;
use Elastica\Type\Mapping;

class GeoClusterTest extends BaseTest
{
    /**
     * @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();
    }
}