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
ee124db6
Commit
ee124db6
authored
9 years ago
by
Simonas Šerlinskas
Browse files
Options
Downloads
Patches
Plain Diff
introduce 2nd argument for FieldSort for ordering
parent
b581a8d1
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
src/Sort/FieldSort.php
+13
-2
13 additions, 2 deletions
src/Sort/FieldSort.php
tests/Aggregation/TopHitsAggregationTest.php
+1
-2
1 addition, 2 deletions
tests/Aggregation/TopHitsAggregationTest.php
with
14 additions
and
4 deletions
src/Sort/FieldSort.php
+
13
−
2
View file @
ee124db6
...
@@ -22,10 +22,15 @@ class FieldSort implements BuilderInterface
...
@@ -22,10 +22,15 @@ class FieldSort implements BuilderInterface
const
DESC
=
'desc'
;
const
DESC
=
'desc'
;
/**
/**
* @var string
.
* @var string
*/
*/
private
$field
;
private
$field
;
/**
* @var string
*/
private
$order
;
/**
/**
* @var array
* @var array
*/
*/
...
@@ -38,11 +43,13 @@ class FieldSort implements BuilderInterface
...
@@ -38,11 +43,13 @@ class FieldSort implements BuilderInterface
/**
/**
* @param string $field Field name.
* @param string $field Field name.
* @param string $order Order direction.
* @param array $params Params that can be set to field sort.
* @param array $params Params that can be set to field sort.
*/
*/
public
function
__construct
(
$field
,
$params
=
[])
public
function
__construct
(
$field
,
$order
=
null
,
$params
=
[])
{
{
$this
->
field
=
$field
;
$this
->
field
=
$field
;
$this
->
order
=
$order
;
$this
->
params
=
$params
;
$this
->
params
=
$params
;
}
}
...
@@ -77,6 +84,10 @@ class FieldSort implements BuilderInterface
...
@@ -77,6 +84,10 @@ class FieldSort implements BuilderInterface
*/
*/
public
function
toArray
()
public
function
toArray
()
{
{
if
(
$this
->
order
)
{
$this
->
params
[
'order'
]
=
$this
->
order
;
}
if
(
$this
->
nestedFilter
)
{
if
(
$this
->
nestedFilter
)
{
$fieldValues
=
array_merge
(
$fieldValues
=
array_merge
(
$this
->
params
,
$this
->
params
,
...
...
This diff is collapsed.
Click to expand it.
tests/Aggregation/TopHitsAggregationTest.php
+
1
−
2
View file @
ee124db6
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
namespace
ONGR\ElasticsearchDSL\Tests\Unit\DSL\Aggregation
;
namespace
ONGR\ElasticsearchDSL\Tests\Unit\DSL\Aggregation
;
use
ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation
;
use
ONGR\ElasticsearchDSL\Aggregation\TopHitsAggregation
;
use
ONGR\ElasticsearchDSL\Aggregation\TopHitsAggregation
;
use
ONGR\ElasticsearchDSL\Sort\FieldSort
;
use
ONGR\ElasticsearchDSL\Sort\FieldSort
;
...
@@ -25,7 +24,7 @@ class TopHitsAggregationTest extends \PHPUnit_Framework_TestCase
...
@@ -25,7 +24,7 @@ class TopHitsAggregationTest extends \PHPUnit_Framework_TestCase
*/
*/
public
function
testToArray
()
public
function
testToArray
()
{
{
$sort
=
new
FieldSort
(
'acme'
,
[
'order'
=>
'asc'
]
);
$sort
=
new
FieldSort
(
'acme'
,
FieldSort
::
ASC
);
$aggregation
=
new
TopHitsAggregation
(
'acme'
,
1
,
1
,
$sort
);
$aggregation
=
new
TopHitsAggregation
(
'acme'
,
1
,
1
,
$sort
);
$expected
=
[
$expected
=
[
...
...
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