Skip to content

Added metadata logic inside result Aggregation #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,41 @@ version: 2

jobs:

php74:
php72:
docker:
- image: circleci/php:7.4-cli
- image: circleci/php:7.2-cli

working_directory: ~/project
steps:
- checkout
- run:
name: Run tests / Symfony 4^3
name: Run tests - minimum
command: |
composer update -n --prefer-dist --prefer-stable
composer update -n --prefer-dist --prefer-lowest
php vendor/bin/phpunit

php73:
docker:
- image: circleci/php:7.3-cli

working_directory: ~/project
steps:
- checkout
- run:
name: Run tests / Symfony 5^0
name: Run tests - minimum
command: |
composer update -n --prefer-dist --prefer-lowest
php vendor/bin/phpunit

php74:
docker:
- image: circleci/php:7.4-cli

working_directory: ~/project
steps:
- checkout
- run:
name: Run tests
command: |
composer update -n --prefer-dist
php vendor/bin/phpunit
Expand All @@ -38,5 +58,7 @@ workflows:
version: 2
test:
jobs:
- php72
- php73
- php74
- php80
1 change: 1 addition & 0 deletions .phpunit.result.cache

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions Query/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,91 +25,65 @@ class Aggregation implements HttpTransportable
{
/**
* @var array
*
* Sort aggregation by count asc
*/
const SORT_BY_COUNT_ASC = ['_count', 'asc'];

/**
* @var array
*
* Sort aggregation by count desc
*/
const SORT_BY_COUNT_DESC = ['_count', 'desc'];

/**
* @var array
*
* Sort aggregation by name asc
*/
const SORT_BY_NAME_ASC = ['_term', 'asc'];

/**
* @var array
*
* Sort aggregation by name desc
*/
const SORT_BY_NAME_DESC = ['_term', 'desc'];

/**
* @var int
*
* No limit
*/
const NO_LIMIT = 0;

/**
* @var string
*
* Name
*/
private $name;

/**
* @var string
*
* Field
*/
private $field;

/**
* @var int
*
* Type
*/
private $applicationType;

/**
* @var int
*
* Filter type
*/
private $filterType;

/**
* @var string[]
*
* Subgroup
*/
private $subgroup = [];

/**
* @var array
*
* Aggregation sort
*/
private $sort;

/**
* @var int
*
* Limit
*/
private $limit;

/**
* Aggregation constructor.
*
* @param string $name
* @param string $field
* @param int $applicationType
Expand Down
40 changes: 10 additions & 30 deletions Query/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,106 +25,86 @@ class Filter implements HttpTransportable
{
/**
* @var int
*
* Filter by all of them
*/
const MUST_ALL = 4;

/**
* @var int
*
* Filter by all of them, with levels
*/
const MUST_ALL_WITH_LEVELS = 5;

/**
* @var int
*
* Filter by, at least, one
*/
const AT_LEAST_ONE = 8;

/**
* @var int
*
* Exclude all of them
*/
const EXCLUDE = 16;

/**
* @var int
*
* Promote all of them
*/
const PROMOTE = 32;

/**
* @var string
*
* Filter type field
*/
const TYPE_FIELD = 'field';

/**
* @var string
*
* Filter type field
*/
const TYPE_RANGE = 'range';

/**
* @var string
*
* Filter type field
*/
const TYPE_DATE_RANGE = 'date_range';

/**
* @var string
*
* Filter type field
*/
const TYPE_RANGE_WITH_MIN_MAX = 'range_min_max';

/**
* @var string
*/
const TYPE_DATE_RANGE_WITH_MIN_MAX = 'date_range_min_max';

/**
* @var string
*/
const TYPE_GEO = 'geo';

/**
* @var string
*
* Filter type query
*/
const TYPE_QUERY = 'query';

/**
* @var string
*
* Field
*/
private $field;

/**
* @var array
*
* Values
*/
private $values;

/**
* @var int
*
* Type
*/
private $applicationType;

/**
* @var string
*
* Filter type
*/
private $filterType;

/**
* @var array
*
* Terms to filter
*/
private $filterTerms;

Expand Down
6 changes: 3 additions & 3 deletions Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public function aggregateBy(
* @param string $field
* @param array $options
* @param int $applicationType
* @param string $rangeType
* @param string $filterType
* @param array $aggregationSort
* @param int $limit
*
Expand All @@ -812,7 +812,7 @@ public function aggregateByRange(
string $field,
array $options,
int $applicationType,
string $rangeType = Filter::TYPE_RANGE,
string $filterType = Filter::TYPE_RANGE,
array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC,
int $limit = Aggregation::NO_LIMIT
): self {
Expand All @@ -824,7 +824,7 @@ public function aggregateByRange(
$filterName,
Item::getPathByField($field),
$applicationType,
$rangeType,
$filterType,
$options,
$aggregationSort,
$limit
Expand Down
32 changes: 19 additions & 13 deletions Result/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,54 @@ class Aggregation implements IteratorAggregate, HttpTransportable
{
/**
* @var string
*
* Name
*/
private $name;

/**
* @var Counter[]
*
* Counters
*/
private $counters = [];

/**
* @var int
*
* Application type
*/
private $applicationType;

/**
* @var int
*
* Total elements
*/
private $totalElements;

/**
* @var array
*
* Active elements
*/
private $activeElements;

/**
* @var int
*
* Highest active level
*/
private $highestActiveLevel = 0;

/**
* @var array
*/
private $metadata;

/**
* Aggregation constructor.
*
* @param string $name
* @param int $applicationType
* @param int $totalElements
* @param array $activeElements
* @param array $metadata
*/
public function __construct(
string $name,
int $applicationType,
int $totalElements,
array $activeElements
array $activeElements,
array $metadata = []
) {
$this->name = $name;
$this->applicationType = $applicationType;
Expand All @@ -89,6 +84,7 @@ public function __construct(
array_values($activeElements),
array_values($activeElements)
);
$this->metadata = $metadata;
}

/**
Expand Down Expand Up @@ -189,6 +185,14 @@ public function getCounter(string $name): ? Counter
return $this->counters[$name] ?? null;
}

/**
* @return array
*/
public function getMetadata(): array
{
return $this->metadata;
}

/**
* Get all elements.
*
Expand Down Expand Up @@ -310,6 +314,7 @@ public function toArray(): array
'highest_active_level' => 0 === $this->highestActiveLevel
? null
: $this->highestActiveLevel,
'metadata' => $this->metadata
], function ($element) {
return
!(
Expand Down Expand Up @@ -350,6 +355,7 @@ public static function createFromArray(array $array): self
}

$aggregation->highestActiveLevel = $array['highest_active_level'] ?? 0;
$aggregation->metadata = $array['metadata'] ?? [];

return $aggregation;
}
Expand Down
Loading