Skip to content

Commit 5bb2c40

Browse files
committed
Update DateHistogramTest with separate testFactor
1 parent 3a9ded0 commit 5bb2c40

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/lib/Elastica/Test/Facet/DateHistogramTest.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,45 @@ public function testClassHierarchy()
1919
unset($facet);
2020
}
2121

22-
public function testTest()
22+
public function testQuery()
23+
{
24+
$client = $this->_getClient();
25+
$index = $client->getIndex('test');
26+
$index->create(array(), true);
27+
$type = $index->getType('helloworld');
28+
29+
$mapping = new Mapping($type, array(
30+
'name' => array('type' => 'string', 'store' => 'no'),
31+
'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss'),
32+
));
33+
$type->setMapping($mapping);
34+
35+
$doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
36+
$type->addDocument($doc);
37+
$doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
38+
$type->addDocument($doc);
39+
$doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
40+
$type->addDocument($doc);
41+
$doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
42+
$type->addDocument($doc);
43+
44+
$facet = new DateHistogram('dateHist1');
45+
$facet->setInterval("day");
46+
$facet->setField("dtmPosted");
47+
48+
$query = new Query();
49+
$query->addFacet($facet);
50+
$query->setQuery(new MatchAll());
51+
$index->refresh();
52+
53+
$response = $type->search($query);
54+
$facets = $response->getFacets();
55+
56+
$this->assertEquals(4, $response->getTotalHits());
57+
$this->assertEquals(2, count($facets['dateHist1']['entries']));
58+
}
59+
60+
public function testFactor()
2361
{
2462
$client = $this->_getClient();
2563
$index = $client->getIndex('test');

0 commit comments

Comments
 (0)