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
1824e778
Commit
1824e778
authored
10 years ago
by
Mantas Jonušas
Browse files
Options
Downloads
Patches
Plain Diff
Added missing aggregations
parent
36864231
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Aggregation/DateRangeAggregation.php
+98
-0
98 additions, 0 deletions
Aggregation/DateRangeAggregation.php
Aggregation/MissingAggregation.php
+42
-0
42 additions, 0 deletions
Aggregation/MissingAggregation.php
with
140 additions
and
0 deletions
Aggregation/DateRangeAggregation.php
0 → 100644
+
98
−
0
View file @
1824e778
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
ONGR\ElasticsearchBundle\DSL\Aggregation
;
use
ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait
;
/**
* Class representing date range aggregation.
*/
class
DateRangeAggregation
extends
AbstractAggregation
{
use
BucketingTrait
;
/**
* @var string
*/
private
$format
;
/**
* @return string
*/
public
function
getFormat
()
{
return
$this
->
format
;
}
/**
* @param string $format
*/
public
function
setFormat
(
$format
)
{
$this
->
format
=
$format
;
}
/**
* @var array
*/
private
$ranges
=
[];
/**
* Add range to aggregation.
*
* @param string|null $from
* @param string|null $to
*
* @return RangeAggregation
*
* @throws \LogicException
*/
public
function
addRange
(
$from
=
null
,
$to
=
null
)
{
if
(
$from
===
null
&&
$to
===
null
)
{
throw
new
\LogicException
(
'Missing range'
);
}
elseif
(
$from
===
null
)
{
$this
->
ranges
=
[[
'to'
=>
$to
]];
}
elseif
(
$to
===
null
)
{
$this
->
ranges
=
[[
'from'
=>
$from
]];
}
else
{
$this
->
ranges
=
[[
'from'
=>
$from
],
[
'to'
=>
$to
]];
}
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
getArray
()
{
if
(
$this
->
getField
()
&&
$this
->
getFormat
()
&&
$this
->
ranges
)
{
$data
=
[
'format'
=>
$this
->
getFormat
(),
'field'
=>
$this
->
getField
(),
'ranges'
=>
array_values
(
$this
->
ranges
),
];
return
$data
;
}
throw
new
\LogicException
(
'Date range aggregation must have field and format set.'
);
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'date_range'
;
}
}
This diff is collapsed.
Click to expand it.
Aggregation/MissingAggregation.php
0 → 100644
+
42
−
0
View file @
1824e778
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
ONGR\ElasticsearchBundle\DSL\Aggregation
;
use
ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait
;
use
Symfony\Component\Process\Exception\LogicException
;
/**
* Class representing missing aggregation.
*/
class
MissingAggregation
extends
AbstractAggregation
{
use
BucketingTrait
;
/**
* {@inheritdoc}
*/
public
function
getArray
()
{
if
(
$this
->
getField
())
{
return
[
'field'
=>
$this
->
getField
()];
}
throw
new
LogicException
(
'Missing aggregation must have a field set'
);
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'missing'
;
}
}
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