-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from ongr-io/master
v0.10.2 release
- Loading branch information
Showing
9 changed files
with
84 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,162 +12,15 @@ | |
namespace ONGR\ElasticsearchBundle\DSL\Aggregation; | ||
|
||
use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait; | ||
use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait; | ||
|
||
/** | ||
* Class representing TermsAggregation. | ||
*/ | ||
class TermsAggregation extends AbstractAggregation | ||
{ | ||
use BucketingTrait; | ||
|
||
const MODE_COUNT = '_count'; | ||
const MODE_TERM = '_term'; | ||
const DIRECTION_ASC = 'asc'; | ||
const DIRECTION_DESC = 'desc'; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $size; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $orderMode; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $orderDirection; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $minDocumentCount; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $include; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $includeFlags; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $exclude; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $excludeFlags; | ||
|
||
/** | ||
* Sets buckets max count. | ||
* | ||
* @param int $size | ||
*/ | ||
public function setSize($size) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tautrimas
Contributor
|
||
{ | ||
$this->size = $size; | ||
} | ||
|
||
/** | ||
* Sets buckets ordering. | ||
* | ||
* @param string $mode | ||
* @param string $direction | ||
*/ | ||
public function setOrder($mode, $direction = self::DIRECTION_ASC) | ||
{ | ||
$this->orderMode = $mode; | ||
$this->orderDirection = $direction; | ||
} | ||
|
||
/** | ||
* Sets minimum hits to consider as term. | ||
* | ||
* @param int $count | ||
*/ | ||
public function setMinDocumentCount($count) | ||
{ | ||
$this->minDocumentCount = $count; | ||
} | ||
|
||
/** | ||
* Sets include field. | ||
* | ||
* @param string $include Include field. | ||
* @param string $flags Possible flags: | ||
* - CANON_EQ | ||
* - CASE_INSENSITIVE | ||
* - COMMENTS | ||
* - DOTALL | ||
* - LITERAL | ||
* - MULTILINE | ||
* - UNICODE | ||
* - UNICODE_CASE | ||
* - UNICODE_CHARACTER_CLASS | ||
* - UNIX_LINES | ||
* Usage example: | ||
* 'CASE_INSENSITIVE|MULTILINE'. | ||
*/ | ||
public function setInclude($include, $flags = '') | ||
{ | ||
$this->include = $include; | ||
$this->includeFlags = $flags; | ||
} | ||
|
||
/** | ||
* Sets include field. | ||
* | ||
* @param string $exclude | ||
* @param string $flags | ||
* | ||
* @see Terms::setInclude() | ||
*/ | ||
public function setExclude($exclude, $flags = '') | ||
{ | ||
$this->exclude = $exclude; | ||
$this->excludeFlags = $flags; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getArray() | ||
{ | ||
$data = ['field' => $this->getField()]; | ||
|
||
if ($this->orderMode && $this->orderDirection) { | ||
$data['order'] = [ | ||
$this->orderMode => $this->orderDirection, | ||
]; | ||
} | ||
|
||
if ($this->size !== null) { | ||
$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; | ||
} | ||
|
||
return $data; | ||
} | ||
use ScriptAwareTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
|
@@ -178,26 +31,17 @@ public function getType() | |
} | ||
|
||
/** | ||
* Constructs include/exclude search values. | ||
* | ||
* @param string $pattern | ||
* @param string $flags | ||
* | ||
* @return string|array|null | ||
* {@inheritdoc} | ||
*/ | ||
protected function getIncludeExclude($pattern, $flags) | ||
public function getArray() | ||
{ | ||
if ($pattern) { | ||
if (empty($flags)) { | ||
return $pattern; | ||
} else { | ||
return [ | ||
'pattern' => $pattern, | ||
'flags' => $flags, | ||
]; | ||
} | ||
} | ||
$data = array_filter( | ||
[ | ||
'field' => $this->getField(), | ||
'script' => $this->getScript(), | ||
] | ||
); | ||
|
||
return null; | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Public methods removed at minor release?
It would be nice to mark methods as deprecated before removing them.