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
ea8d7cdb
Commit
ea8d7cdb
authored
9 years ago
by
Mantas Jonušas
Browse files
Options
Downloads
Patches
Plain Diff
Updated terms aggregation
parent
77557e74
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Aggregation/TermsAggregation.php
+150
-31
150 additions, 31 deletions
Aggregation/TermsAggregation.php
with
150 additions
and
31 deletions
Aggregation/TermsAggregation.php
+
150
−
31
View file @
ea8d7cdb
...
...
@@ -12,6 +12,7 @@
namespace
ONGR\ElasticsearchBundle\DSL\Aggregation
;
use
ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait
;
use
ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait
;
/**
* Class representing TermsAggregation.
...
...
@@ -19,17 +20,37 @@ use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait;
class
TermsAggregation
extends
AbstractAggregation
{
use
BucketingTrait
;
use
ScriptAwareTrait
;
const
MODE_COUNT
=
'_count'
;
const
MODE_TERM
=
'_term'
;
const
DIRECTION_ASC
=
'asc'
;
const
DIRECTION_DESC
=
'desc'
;
const
HINT_MAP
=
'map'
;
const
HINT_GLOBAL_ORDINALS
=
'global_ordinals'
;
const
HINT_GLOBAL_ORDINALS_HASH
=
'global_ordinals_hash'
;
const
HINT_GLOBAL_ORDINALS_LOW_CARDINALITY
=
'global_ordinals_low_cardinality'
;
const
COLLECT_BREADTH_FIRST
=
'breadth_first'
;
const
COLLECT_DEPTH_FIRST
=
'depth_first'
;
/**
* @var int
*/
private
$size
;
/**
* @var int
*/
private
$shardSize
;
/**
* @var int
*/
private
$shardMinDocCount
;
/**
* @var string
*/
private
$executionHint
;
/**
* @var string
*/
...
...
@@ -43,7 +64,7 @@ class TermsAggregation extends AbstractAggregation
/**
* @var int
*/
private
$minDoc
ument
Count
;
private
$minDocCount
;
/**
* @var string
...
...
@@ -65,6 +86,67 @@ class TermsAggregation extends AbstractAggregation
*/
private
$excludeFlags
;
/**
* @var string
*/
private
$collectMode
;
/**
* @return string
*/
public
function
getCollectMode
()
{
return
$this
->
collectMode
;
}
/**
* @param string $collectMode
*/
public
function
setCollectMode
(
$collectMode
=
self
::
COLLECT_DEPTH_FIRST
)
{
$this
->
collectMode
=
$collectMode
;
}
/**
* @return int
*/
public
function
getShardSize
()
{
return
$this
->
shardSize
;
}
/**
* @param int $shardSize
*/
public
function
setShardSize
(
$shardSize
)
{
$this
->
shardSize
=
$shardSize
;
}
/**
* @return int
*/
public
function
getShardMinDocCount
()
{
return
$this
->
shardMinDocCount
;
}
/**
* @param int $shardMinDocCount
*/
public
function
setShardMinDocCount
(
$shardMinDocCount
)
{
$this
->
shardMinDocCount
=
$shardMinDocCount
;
}
/**
* @return int
*/
public
function
getSize
()
{
return
$this
->
size
;
}
/**
* Sets buckets max count.
*
...
...
@@ -75,6 +157,22 @@ class TermsAggregation extends AbstractAggregation
$this
->
size
=
$size
;
}
/**
* @return string
*/
public
function
getExecutionHint
()
{
return
$this
->
executionHint
;
}
/**
* @param string $executionHint
*/
public
function
setExecutionHint
(
$executionHint
=
self
::
HINT_MAP
)
{
$this
->
executionHint
=
$executionHint
;
}
/**
* Sets buckets ordering.
*
...
...
@@ -87,14 +185,42 @@ class TermsAggregation extends AbstractAggregation
$this
->
orderDirection
=
$direction
;
}
/**
* @return array|null
*/
public
function
getOrder
()
{
if
(
$this
->
isOrder
())
{
return
[
$this
->
orderMode
=>
$this
->
orderDirection
];
}
return
null
;
}
/**
* @return bool
*/
private
function
isOrder
()
{
return
$this
->
orderMode
&&
$this
->
orderDirection
;
}
/**
* @return int
*/
public
function
getMinDocCount
()
{
return
$this
->
minDocCount
;
}
/**
* Sets minimum hits to consider as term.
*
* @param int $
c
ount
* @param int $
minDocC
ount
*/
public
function
setMinDoc
ument
Count
(
$
c
ount
)
public
function
setMinDocCount
(
$
minDocC
ount
)
{
$this
->
minDoc
ument
Count
=
$
c
ount
;
$this
->
minDocCount
=
$
minDocC
ount
;
}
/**
...
...
@@ -140,31 +266,24 @@ class TermsAggregation extends AbstractAggregation
*/
public
function
getArray
()
{
$data
=
[
'field'
=>
$this
->
getField
()];
if
(
$this
->
orderMode
&&
$this
->
orderDirection
)
{
$data
[
'order'
]
=
[
$this
->
orderMode
=>
$this
->
orderDirection
,
];
}
if
(
$this
->
size
)
{
$data
[
'size'
]
=
$this
->
size
;
}
if
(
$this
->
minDocumentCount
!==
null
)
{
$data
[
'min_doc_count'
]
=
$this
->
minDocumentCount
;
}
$includeResult
=
$this
->
getIncludeExclude
(
$this
->
include
,
$this
->
includeFlags
);
if
(
$includeResult
)
{
$data
[
'include'
]
=
$includeResult
;
}
$excludeResult
=
$this
->
getIncludeExclude
(
$this
->
exclude
,
$this
->
excludeFlags
);
if
(
$excludeResult
)
{
$data
[
'exclude'
]
=
$excludeResult
;
}
$data
=
array_filter
(
[
'field'
=>
$this
->
getField
(),
'min_doc_count'
=>
$this
->
getMinDocCount
(),
'size'
=>
$this
->
getSize
(),
'shard_size'
=>
$this
->
getShardSize
(),
'shard_min_doc_count'
=>
$this
->
getShardMinDocCount
(),
'order'
=>
$this
->
getOrder
(),
'include'
=>
$this
->
getIncludeExclude
(
$this
->
include
,
$this
->
includeFlags
),
'exclude'
=>
$this
->
getIncludeExclude
(
$this
->
exclude
,
$this
->
excludeFlags
),
'execution_hint'
=>
$this
->
getExecutionHint
(),
'script'
=>
$this
->
getScript
(),
'collect_mode'
=>
$this
->
getCollectMode
(),
],
function
(
$value
)
{
return
(
$value
||
$value
!==
null
);
}
);
return
$data
;
}
...
...
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