Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Elastica\Facet\DateHistogram::setFactor() #806

Merged
merged 2 commits into from
Apr 3, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/Elastica/Facet/DateHistogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions test/lib/Elastica/Test/Facet/DateHistogramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ public function testTest()

$mapping = new Mapping($type, array(
'name' => array('type' => 'string', 'store' => 'no'),
'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss'),
'dtmPosted' => array('type' => 'long', 'store' => 'no'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to keep this test as it is and add a new one? Liek this we now that both options work. Or what is the reason you modified this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I'll keep the original test and add a new one instead to check that factor works.

));
$type->setMapping($mapping);

$doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
$doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => 1308865980));
$type->addDocument($doc);
$doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
$doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => 1308822780));
$type->addDocument($doc);
$doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
$doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => 1310115180));
$type->addDocument($doc);
$doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
$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);
Expand Down