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
29ec4a27
Unverified
Commit
29ec4a27
authored
6 years ago
by
Simonas Šerlinskas
Browse files
Options
Downloads
Patches
Plain Diff
added adjacency matrix aggregation
parent
ec57801f
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/AdjacencyMatrixAggregation.php
+81
-0
81 additions, 0 deletions
src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php
tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php
+134
-0
134 additions, 0 deletions
.../Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php
with
215 additions
and
0 deletions
src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php
0 → 100644
+
81
−
0
View file @
29ec4a27
<?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\ElasticsearchDSL\Aggregation\Bucketing
;
use
ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation
;
use
ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait
;
use
ONGR\ElasticsearchDSL\BuilderInterface
;
/**
* Class representing adjacency matrix aggregation.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-adjacency-matrix-aggregation.html
*/
class
AdjacencyMatrixAggregation
extends
AbstractAggregation
{
const
FILTERS
=
'filters'
;
use
BucketingTrait
;
/**
* @var BuilderInterface[]
*/
private
$filters
=
[
self
::
FILTERS
=>
[]
];
/**
* Inner aggregations container init.
*
* @param string $name
* @param BuilderInterface[] $filters
*/
public
function
__construct
(
$name
,
$filters
=
[])
{
parent
::
__construct
(
$name
);
foreach
(
$filters
as
$name
=>
$filter
)
{
$this
->
addFilter
(
$name
,
$filter
);
}
}
/**
* @param string $name
* @param BuilderInterface $filter
*
* @throws \LogicException
*
* @return self
*/
public
function
addFilter
(
$name
,
BuilderInterface
$filter
)
{
$this
->
filters
[
self
::
FILTERS
][
$name
]
=
$filter
->
toArray
();
return
$this
;
}
/**
* {@inheritdoc}
*/
public
function
getArray
()
{
return
$this
->
filters
;
}
/**
* {@inheritdoc}
*/
public
function
getType
()
{
return
'adjacency_matrix'
;
}
}
This diff is collapsed.
Click to expand it.
tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php
0 → 100644
+
134
−
0
View file @
29ec4a27
<?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\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation
;
use
ONGR\ElasticsearchDSL\Aggregation\Bucketing\AdjacencyMatrixAggregation
;
use
ONGR\ElasticsearchDSL\BuilderInterface
;
/**
* Unit test for adjacency matrix aggregation.
*/
class
AdjacencyMatrixAggregationTest
extends
\PHPUnit\Framework\TestCase
{
// /**
// * Test if exception is thrown when not anonymous filter is without name.
// *
// * @expectedException \LogicException
// * @expectedExceptionMessage In not anonymous filters filter name must be set.
// */
// public function testIfExceptionIsThrown()
// {
// $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock();
// $aggregation = new FiltersAggregation('test_agg');
// $aggregation->addFilter($mock);
// }
/**
* Test GetArray method.
*/
public
function
testFiltersAggregationGetArray
()
{
$mock
=
$this
->
getMockBuilder
(
'ONGR\ElasticsearchDSL\BuilderInterface'
)
->
getMock
();
$aggregation
=
new
AdjacencyMatrixAggregation
(
'test_agg'
);
$aggregation
->
addFilter
(
'name'
,
$mock
);
$result
=
$aggregation
->
getArray
();
$this
->
assertArrayHasKey
(
'filters'
,
$result
);
}
/**
* Tests getType method.
*/
public
function
testFiltersAggregationGetType
()
{
$aggregation
=
new
AdjacencyMatrixAggregation
(
'foo'
);
$result
=
$aggregation
->
getType
();
$this
->
assertEquals
(
'adjacency_matrix'
,
$result
);
}
/**
* Test for filter aggregation toArray() method.
*/
public
function
testToArray
()
{
$aggregation
=
new
AdjacencyMatrixAggregation
(
'test_agg'
);
$filter
=
$this
->
getMockBuilder
(
'ONGR\ElasticsearchDSL\BuilderInterface'
)
->
setMethods
([
'toArray'
,
'getType'
])
->
getMockForAbstractClass
();
$filter
->
expects
(
$this
->
any
())
->
method
(
'toArray'
)
->
willReturn
([
'test_field'
=>
[
'test_value'
=>
'test'
]]);
$aggregation
->
addFilter
(
'first'
,
$filter
);
$aggregation
->
addFilter
(
'second'
,
$filter
);
$results
=
$aggregation
->
toArray
();
$expected
=
[
'adjacency_matrix'
=>
[
'filters'
=>
[
'first'
=>
[
'test_field'
=>
[
'test_value'
=>
'test'
,
],
],
'second'
=>
[
'test_field'
=>
[
'test_value'
=>
'test'
,
],
],
],
],
];
$this
->
assertEquals
(
$expected
,
$results
);
}
/**
* Tests if filters can be passed to the constructor.
*/
public
function
testFilterConstructor
()
{
/** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */
$builderInterface1
=
$this
->
getMockForAbstractClass
(
'ONGR\ElasticsearchDSL\BuilderInterface'
);
/** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */
$builderInterface2
=
$this
->
getMockForAbstractClass
(
'ONGR\ElasticsearchDSL\BuilderInterface'
);
$aggregation
=
new
AdjacencyMatrixAggregation
(
'test'
,
[
'filter1'
=>
$builderInterface1
,
'filter2'
=>
$builderInterface2
,
]
);
$this
->
assertSame
(
[
'adjacency_matrix'
=>
[
'filters'
=>
[
'filter1'
=>
null
,
'filter2'
=>
null
,
],
],
],
$aggregation
->
toArray
()
);
$aggregation
=
new
AdjacencyMatrixAggregation
(
'test'
);
$this
->
assertSame
(
[
'adjacency_matrix'
=>
[
'filters'
=>
[],
],
],
$aggregation
->
toArray
()
);
}
}
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