Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Elasticsearch DSL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public
Elasticsearch DSL
Commits
13a8d42a
Commit
13a8d42a
authored
5 years ago
by
pmishev
Browse files
Options
Downloads
Patches
Plain Diff
Added support for 'keyed' option to DateRangeAggregation (#283)
parent
197eedda
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Aggregation/Bucketing/DateRangeAggregation.php
+34
-11
34 additions, 11 deletions
src/Aggregation/Bucketing/DateRangeAggregation.php
tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php
+2
-0
2 additions, 0 deletions
...s/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php
with
36 additions
and
11 deletions
src/Aggregation/Bucketing/DateRangeAggregation.php
+
34
−
11
View file @
13a8d42a
...
...
@@ -29,25 +29,29 @@ class DateRangeAggregation extends AbstractAggregation
private
$format
;
/**
* @
return string
* @
var array
*/
public
function
getFormat
()
{
return
$this
->
format
;
}
private
$ranges
=
[];
/**
* @var bool
*/
private
$keyed
=
false
;
/**
* @param string $name
* @param string $field
* @param string $format
* @param array $ranges
* @param bool $keyed
*/
public
function
__construct
(
$name
,
$field
=
null
,
$format
=
null
,
array
$ranges
=
[])
public
function
__construct
(
$name
,
$field
=
null
,
$format
=
null
,
array
$ranges
=
[]
,
$keyed
=
false
)
{
parent
::
__construct
(
$name
);
$this
->
setField
(
$field
);
$this
->
setFormat
(
$format
);
$this
->
setKeyed
(
$keyed
);
foreach
(
$ranges
as
$range
)
{
$from
=
isset
(
$range
[
'from'
])
?
$range
[
'from'
]
:
null
;
$to
=
isset
(
$range
[
'to'
])
?
$range
[
'to'
]
:
null
;
...
...
@@ -57,23 +61,41 @@ class DateRangeAggregation extends AbstractAggregation
}
/**
* @param string $format
* Sets if result buckets should be keyed.
*
* @param bool $keyed
*
* @return DateRangeAggregation
*/
public
function
set
Format
(
$format
)
public
function
set
Keyed
(
$keyed
)
{
$this
->
format
=
$format
;
$this
->
keyed
=
$keyed
;
return
$this
;
}
/**
* @
var array
* @
return string
*/
private
$ranges
=
[];
public
function
getFormat
()
{
return
$this
->
format
;
}
/**
* @param string $format
*/
public
function
setFormat
(
$format
)
{
$this
->
format
=
$format
;
}
/**
* Add range to aggregation.
*
* @param string|null $from
* @param string|null $to
* @param string|null $key
*
* @return $this
*
...
...
@@ -111,6 +133,7 @@ class DateRangeAggregation extends AbstractAggregation
'format'
=>
$this
->
getFormat
(),
'field'
=>
$this
->
getField
(),
'ranges'
=>
$this
->
ranges
,
'keyed'
=>
$this
->
keyed
,
];
return
$data
;
...
...
This diff is collapsed.
Click to expand it.
tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php
+
2
−
0
View file @
13a8d42a
...
...
@@ -47,11 +47,13 @@ class DateRangeAggregationTest extends \PHPUnit\Framework\TestCase
$agg
=
new
DateRangeAggregation
(
'foo'
,
'baz'
);
$agg
->
addRange
(
10
,
20
);
$agg
->
setFormat
(
'bar'
);
$agg
->
setKeyed
(
true
);
$result
=
$agg
->
getArray
();
$expected
=
[
'format'
=>
'bar'
,
'field'
=>
'baz'
,
'ranges'
=>
[[
'from'
=>
10
,
'to'
=>
20
]],
'keyed'
=>
true
,
];
$this
->
assertEquals
(
$expected
,
$result
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment