diff --git a/lib/Elastica/Facet/DateHistogram.php b/lib/Elastica/Facet/DateHistogram.php index 696d2d20ba..97089b183f 100644 --- a/lib/Elastica/Facet/DateHistogram.php +++ b/lib/Elastica/Facet/DateHistogram.php @@ -24,6 +24,17 @@ public function setTimezone($tzOffset) return $this->setParam('time_zone', $tzOffset); } + /** + * Set the factor parameter + * + * @param integer $factor + * @return $this + */ + public function setFactor($factor) + { + return $this->setParam('factor', $factor); + } + /** * Creates the full facet definition, which includes the basic * facet definition of the parent. diff --git a/test/lib/Elastica/Test/Facet/DateHistogramTest.php b/test/lib/Elastica/Test/Facet/DateHistogramTest.php index e65db9dd85..ed60a469aa 100644 --- a/test/lib/Elastica/Test/Facet/DateHistogramTest.php +++ b/test/lib/Elastica/Test/Facet/DateHistogramTest.php @@ -19,7 +19,7 @@ public function testClassHierarchy() unset($facet); } - public function testTest() + public function testQuery() { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -56,4 +56,43 @@ public function testTest() $this->assertEquals(4, $response->getTotalHits()); $this->assertEquals(2, count($facets['dateHist1']['entries'])); } + + 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'])); + } }