Skip to content
GitLab
Explore
Sign in
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
ac9a2d0a
Commit
ac9a2d0a
authored
9 years ago
by
Simonas Šerlinskas
Browse files
Options
Downloads
Patches
Plain Diff
fixed top hits aggregation creation
parent
1d795a53
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/TopHitsAggregation.php
+3
-18
3 additions, 18 deletions
src/Aggregation/TopHitsAggregation.php
tests/Aggregation/TopHitsAggregationTest.php
+32
-7
32 additions, 7 deletions
tests/Aggregation/TopHitsAggregationTest.php
with
35 additions
and
25 deletions
src/Aggregation/TopHitsAggregation.php
+
3
−
18
View file @
ac9a2d0a
...
...
@@ -124,27 +124,10 @@ class TopHitsAggregation extends AbstractAggregation
* {@inheritdoc}
*/
public
function
getArray
()
{
$data
=
new
\stdClass
();
$filteredData
=
$this
->
getFilteredData
();
foreach
(
$filteredData
as
$key
=>
$value
)
{
$data
->
{
$key
}
=
$value
;
}
return
$data
;
}
/**
* Filters the data.
*
* @return array
*/
private
function
getFilteredData
()
{
$output
=
array_filter
(
[
'sort'
=>
$this
->
getSort
()
?
$this
->
getSort
()
->
toArray
()
:
[]
,
'sort'
=>
$this
->
getSort
()
?
$this
->
getSort
()
->
toArray
()
:
null
,
'size'
=>
$this
->
getSize
(),
'from'
=>
$this
->
getFrom
(),
],
...
...
@@ -153,6 +136,8 @@ class TopHitsAggregation extends AbstractAggregation
}
);
$output
=
$this
->
processArray
(
$output
);
return
$output
;
}
}
This diff is collapsed.
Click to expand it.
tests/Aggregation/TopHitsAggregationTest.php
+
32
−
7
View file @
ac9a2d0a
...
...
@@ -26,18 +26,43 @@ class TopHitsAggregationTest extends \PHPUnit_Framework_TestCase
public
function
testToArray
()
{
$sort
=
new
FieldSort
(
'acme'
);
$aggregation
=
new
TopHitsAggregation
(
'acme'
,
0
,
1
,
$sort
);
$aggregation
=
new
TopHitsAggregation
(
'acme'
,
1
,
1
,
$sort
);
$expectedAgg
=
new
\stdClass
();
$expectedAgg
->
size
=
0
;
$expectedAgg
->
from
=
1
;
$expectedAgg
->
sort
=
$sort
->
toArray
();
$expected
=
[
'acme'
=>
[
'top_hits'
=>
$expectedAgg
,
'top_hits'
=>
[
'sort'
=>
[
'acme'
=>
[],
],
'size'
=>
1
,
'from'
=>
1
,
],
],
];
$this
->
assertEquals
(
$expected
,
$aggregation
->
toArray
());
$this
->
assertSame
(
$expected
,
$aggregation
->
toArray
());
}
/**
* Check if parameters can be set to agg.
*/
public
function
testParametersAddition
()
{
$aggregation
=
new
TopHitsAggregation
(
'acme'
,
0
,
1
);
$aggregation
->
addParameter
(
'_source'
,
[
'include'
=>
[
'title'
]]);
$expected
=
[
'acme'
=>
[
'top_hits'
=>
[
'size'
=>
0
,
'from'
=>
1
,
'_source'
=>
[
'include'
=>
[
'title'
],
]
],
],
];
$this
->
assertSame
(
$expected
,
$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