Skip to content

Commit 42306e3

Browse files
authored
Merge pull request #133 from apisearch-io/feature/added-extra-configuration-on-result-aggregation
Added metadata logic inside result Aggregation
2 parents a7cbcfc + adbbae5 commit 42306e3

File tree

8 files changed

+76
-83
lines changed

8 files changed

+76
-83
lines changed

.circleci/config.yml

+27-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,41 @@ version: 2
22

33
jobs:
44

5-
php74:
5+
php72:
66
docker:
7-
- image: circleci/php:7.4-cli
7+
- image: circleci/php:7.2-cli
88

99
working_directory: ~/project
1010
steps:
1111
- checkout
1212
- run:
13-
name: Run tests / Symfony 4^3
13+
name: Run tests - minimum
1414
command: |
15-
composer update -n --prefer-dist --prefer-stable
15+
composer update -n --prefer-dist --prefer-lowest
1616
php vendor/bin/phpunit
1717
18+
php73:
19+
docker:
20+
- image: circleci/php:7.3-cli
21+
22+
working_directory: ~/project
23+
steps:
24+
- checkout
1825
- run:
19-
name: Run tests / Symfony 5^0
26+
name: Run tests - minimum
27+
command: |
28+
composer update -n --prefer-dist --prefer-lowest
29+
php vendor/bin/phpunit
30+
31+
php74:
32+
docker:
33+
- image: circleci/php:7.4-cli
34+
35+
working_directory: ~/project
36+
steps:
37+
- checkout
38+
- run:
39+
name: Run tests
2040
command: |
2141
composer update -n --prefer-dist
2242
php vendor/bin/phpunit
@@ -38,5 +58,7 @@ workflows:
3858
version: 2
3959
test:
4060
jobs:
61+
- php72
62+
- php73
4163
- php74
4264
- php80

.phpunit.result.cache

+1
Large diffs are not rendered by default.

Query/Aggregation.php

-26
Original file line numberDiff line numberDiff line change
@@ -25,91 +25,65 @@ class Aggregation implements HttpTransportable
2525
{
2626
/**
2727
* @var array
28-
*
29-
* Sort aggregation by count asc
3028
*/
3129
const SORT_BY_COUNT_ASC = ['_count', 'asc'];
3230

3331
/**
3432
* @var array
35-
*
36-
* Sort aggregation by count desc
3733
*/
3834
const SORT_BY_COUNT_DESC = ['_count', 'desc'];
3935

4036
/**
4137
* @var array
42-
*
43-
* Sort aggregation by name asc
4438
*/
4539
const SORT_BY_NAME_ASC = ['_term', 'asc'];
4640

4741
/**
4842
* @var array
49-
*
50-
* Sort aggregation by name desc
5143
*/
5244
const SORT_BY_NAME_DESC = ['_term', 'desc'];
5345

5446
/**
5547
* @var int
56-
*
57-
* No limit
5848
*/
5949
const NO_LIMIT = 0;
6050

6151
/**
6252
* @var string
63-
*
64-
* Name
6553
*/
6654
private $name;
6755

6856
/**
6957
* @var string
70-
*
71-
* Field
7258
*/
7359
private $field;
7460

7561
/**
7662
* @var int
77-
*
78-
* Type
7963
*/
8064
private $applicationType;
8165

8266
/**
8367
* @var int
84-
*
85-
* Filter type
8668
*/
8769
private $filterType;
8870

8971
/**
9072
* @var string[]
91-
*
92-
* Subgroup
9373
*/
9474
private $subgroup = [];
9575

9676
/**
9777
* @var array
98-
*
99-
* Aggregation sort
10078
*/
10179
private $sort;
10280

10381
/**
10482
* @var int
105-
*
106-
* Limit
10783
*/
10884
private $limit;
10985

11086
/**
111-
* Aggregation constructor.
112-
*
11387
* @param string $name
11488
* @param string $field
11589
* @param int $applicationType

Query/Filter.php

+10-30
Original file line numberDiff line numberDiff line change
@@ -25,106 +25,86 @@ class Filter implements HttpTransportable
2525
{
2626
/**
2727
* @var int
28-
*
29-
* Filter by all of them
3028
*/
3129
const MUST_ALL = 4;
3230

3331
/**
3432
* @var int
35-
*
36-
* Filter by all of them, with levels
3733
*/
3834
const MUST_ALL_WITH_LEVELS = 5;
3935

4036
/**
4137
* @var int
42-
*
43-
* Filter by, at least, one
4438
*/
4539
const AT_LEAST_ONE = 8;
4640

4741
/**
4842
* @var int
49-
*
50-
* Exclude all of them
5143
*/
5244
const EXCLUDE = 16;
5345

5446
/**
5547
* @var int
56-
*
57-
* Promote all of them
5848
*/
5949
const PROMOTE = 32;
6050

6151
/**
6252
* @var string
63-
*
64-
* Filter type field
6553
*/
6654
const TYPE_FIELD = 'field';
6755

6856
/**
6957
* @var string
70-
*
71-
* Filter type field
7258
*/
7359
const TYPE_RANGE = 'range';
7460

7561
/**
7662
* @var string
77-
*
78-
* Filter type field
7963
*/
8064
const TYPE_DATE_RANGE = 'date_range';
8165

8266
/**
8367
* @var string
84-
*
85-
* Filter type field
68+
*/
69+
const TYPE_RANGE_WITH_MIN_MAX = 'range_min_max';
70+
71+
/**
72+
* @var string
73+
*/
74+
const TYPE_DATE_RANGE_WITH_MIN_MAX = 'date_range_min_max';
75+
76+
/**
77+
* @var string
8678
*/
8779
const TYPE_GEO = 'geo';
8880

8981
/**
9082
* @var string
91-
*
92-
* Filter type query
9383
*/
9484
const TYPE_QUERY = 'query';
9585

9686
/**
9787
* @var string
98-
*
99-
* Field
10088
*/
10189
private $field;
10290

10391
/**
10492
* @var array
105-
*
106-
* Values
10793
*/
10894
private $values;
10995

11096
/**
11197
* @var int
112-
*
113-
* Type
11498
*/
11599
private $applicationType;
116100

117101
/**
118102
* @var string
119-
*
120-
* Filter type
121103
*/
122104
private $filterType;
123105

124106
/**
125107
* @var array
126-
*
127-
* Terms to filter
128108
*/
129109
private $filterTerms;
130110

Query/Query.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ public function aggregateBy(
801801
* @param string $field
802802
* @param array $options
803803
* @param int $applicationType
804-
* @param string $rangeType
804+
* @param string $filterType
805805
* @param array $aggregationSort
806806
* @param int $limit
807807
*
@@ -812,7 +812,7 @@ public function aggregateByRange(
812812
string $field,
813813
array $options,
814814
int $applicationType,
815-
string $rangeType = Filter::TYPE_RANGE,
815+
string $filterType = Filter::TYPE_RANGE,
816816
array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC,
817817
int $limit = Aggregation::NO_LIMIT
818818
): self {
@@ -824,7 +824,7 @@ public function aggregateByRange(
824824
$filterName,
825825
Item::getPathByField($field),
826826
$applicationType,
827-
$rangeType,
827+
$filterType,
828828
$options,
829829
$aggregationSort,
830830
$limit

Result/Aggregation.php

+19-13
Original file line numberDiff line numberDiff line change
@@ -28,59 +28,54 @@ class Aggregation implements IteratorAggregate, HttpTransportable
2828
{
2929
/**
3030
* @var string
31-
*
32-
* Name
3331
*/
3432
private $name;
3533

3634
/**
3735
* @var Counter[]
38-
*
39-
* Counters
4036
*/
4137
private $counters = [];
4238

4339
/**
4440
* @var int
45-
*
46-
* Application type
4741
*/
4842
private $applicationType;
4943

5044
/**
5145
* @var int
52-
*
53-
* Total elements
5446
*/
5547
private $totalElements;
5648

5749
/**
5850
* @var array
59-
*
60-
* Active elements
6151
*/
6252
private $activeElements;
6353

6454
/**
6555
* @var int
66-
*
67-
* Highest active level
6856
*/
6957
private $highestActiveLevel = 0;
7058

59+
/**
60+
* @var array
61+
*/
62+
private $metadata;
63+
7164
/**
7265
* Aggregation constructor.
7366
*
7467
* @param string $name
7568
* @param int $applicationType
7669
* @param int $totalElements
7770
* @param array $activeElements
71+
* @param array $metadata
7872
*/
7973
public function __construct(
8074
string $name,
8175
int $applicationType,
8276
int $totalElements,
83-
array $activeElements
77+
array $activeElements,
78+
array $metadata = []
8479
) {
8580
$this->name = $name;
8681
$this->applicationType = $applicationType;
@@ -89,6 +84,7 @@ public function __construct(
8984
array_values($activeElements),
9085
array_values($activeElements)
9186
);
87+
$this->metadata = $metadata;
9288
}
9389

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

188+
/**
189+
* @return array
190+
*/
191+
public function getMetadata(): array
192+
{
193+
return $this->metadata;
194+
}
195+
192196
/**
193197
* Get all elements.
194198
*
@@ -310,6 +314,7 @@ public function toArray(): array
310314
'highest_active_level' => 0 === $this->highestActiveLevel
311315
? null
312316
: $this->highestActiveLevel,
317+
'metadata' => $this->metadata
313318
], function ($element) {
314319
return
315320
!(
@@ -350,6 +355,7 @@ public static function createFromArray(array $array): self
350355
}
351356

352357
$aggregation->highestActiveLevel = $array['highest_active_level'] ?? 0;
358+
$aggregation->metadata = $array['metadata'] ?? [];
353359

354360
return $aggregation;
355361
}

0 commit comments

Comments
 (0)