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
552d8518
Commit
552d8518
authored
10 years ago
by
Mantas Jonušas
Browse files
Options
Downloads
Patches
Plain Diff
Added geo distance aggregation
parent
5ea9af01
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Aggregation/GeoDistanceAggregation.php
+158
-0
158 additions, 0 deletions
Aggregation/GeoDistanceAggregation.php
with
158 additions
and
0 deletions
Aggregation/GeoDistanceAggregation.php
0 → 100644
+
158
−
0
View file @
552d8518
<?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 geo distance aggregation.
*/
class
GeoDistanceAggregation
extends
AbstractAggregation
{
use
BucketingTrait
;
/**
* @var mixed
*/
private
$origin
;
/**
* @var string
*/
private
$distanceType
;
/**
* @var string
*/
private
$unit
;
/**
* @var array
*/
private
$ranges
=
[];
/**
* @return string
*/
public
function
getOrigin
()
{
return
$this
->
origin
;
}
/**
* @param mixed $origin
*/
public
function
setOrigin
(
$origin
)
{
$this
->
origin
=
$origin
;
}
/**
* @return string
*/
public
function
getDistanceType
()
{
return
$this
->
distanceType
;
}
/**
* @param string $distanceType
*/
public
function
setDistanceType
(
$distanceType
)
{
$this
->
distanceType
=
$distanceType
;
}
/**
* @return string
*/
public
function
getUnit
()
{
return
$this
->
unit
;
}
/**
* @param string $unit
*/
public
function
setUnit
(
$unit
)
{
$this
->
unit
=
$unit
;
}
/**
* Add range to aggregation.
*
* @param int|float|null $from
* @param int|float|null $to
*
* @throws \LogicException
*
* @return GeoDistanceAggregation
*/
public
function
addRange
(
$from
=
null
,
$to
=
null
)
{
$range
=
array_filter
(
[
'from'
=>
$from
,
'to'
=>
$to
,
]
);
if
(
empty
(
$range
))
{
throw
new
\LogicException
(
'Either from or to must be set. Both cannot be null.'
);
}
$this
->
ranges
[]
=
$range
;
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
getArray
()
{
$data
=
[];
if
(
$this
->
getField
())
{
$data
[
'field'
]
=
$this
->
getField
();
}
else
{
throw
new
\LogicException
(
'Geo distance aggregation must have a field set.'
);
}
if
(
$this
->
getOrigin
())
{
$data
[
'origin'
]
=
$this
->
getOrigin
();
}
else
{
throw
new
\LogicException
(
'Geo distance aggregation must have an origin set.'
);
}
if
(
$this
->
getUnit
())
{
$data
[
'unit'
]
=
$this
->
getUnit
();
}
if
(
$this
->
getDistanceType
())
{
$data
[
'distance_type'
]
=
$this
->
getDistanceType
();
}
$data
[
'ranges'
]
=
$this
->
ranges
;
return
$data
;
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'geo_distance'
;
}
}
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