diff --git a/.editorconfig b/.editorconfig
deleted file mode 100644
index cd8eb86..0000000
--- a/.editorconfig
+++ /dev/null
@@ -1,15 +0,0 @@
-; This file is for unifying the coding style for different editors and IDEs.
-; More information at http://editorconfig.org
-
-root = true
-
-[*]
-charset = utf-8
-indent_size = 4
-indent_style = space
-end_of_line = lf
-insert_final_newline = true
-trim_trailing_whitespace = true
-
-[*.md]
-trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
index 04de107..a01ae4e 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -4,10 +4,11 @@
* text=auto
# Ignore all test and documentation with "export-ignore".
+/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
-/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
-/.scrutinizer.yml export-ignore
/tests export-ignore
-/docs export-ignore
+/build export-ignore
+/phpcs.xml export-ignore
+/phpunit.xml export-ignore
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..09c0ef7
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,44 @@
+name: CI
+
+on:
+ push:
+ branches:
+ - 6.x
+ - 7.x
+
+env:
+ FORCE_COLOR: 1
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ php-version: ['8.1', '8.2']
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 0
+
+ - name: Set up PHP ${{ matrix.php-version }}
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-version }}
+ coverage: xdebug
+
+ - name: Install dependencies
+ run: |
+ composer self-update
+ composer install
+
+ - name: Tests & Style
+ run: |
+ composer test-coverage
+ composer phpcs
+
+ - name: Upload Coverage
+ if: github.repository_owner == 'gskema'
+ run: composer upload-coverage
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index 5d63b30..0000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-build:
- nodes:
- analysis:
- project_setup:
- override: true
- tests:
- override: [php-scrutinizer-run]
-
-filter:
- excluded_paths: [tests/*]
-
-checks:
- php:
- remove_extra_empty_lines: true
- remove_php_closing_tag: true
- remove_trailing_whitespace: true
- fix_use_statements:
- remove_unused: true
- preserve_multiple: false
- preserve_blanklines: true
- order_alphabetically: true
- fix_php_opening_tag: true
- fix_linefeed: true
- fix_line_ending: true
- fix_identation_4spaces: true
- fix_doc_comments: true
-
-tools:
- external_code_coverage:
- timeout: 600
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 86e5397..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-dist: trusty
-language: php
-
-php:
- - 7.0
- - 7.1
- - 7.2
-
-# This triggers builds to run on the new TravisCI infrastructure.
-# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
-sudo: false
-
-## Cache composer
-cache:
- directories:
- - $HOME/.composer/cache
-
-matrix:
- include:
- - php: 7.0
- env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
-
-before_script:
- - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
-
-script:
- - vendor/bin/phpcs --standard=psr2 src/ --exclude=Generic.Files.LineLength
- - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
-
-after_script:
- - wget https://scrutinizer-ci.com/ocular.phar
- - php ocular.phar code-coverage:upload --format=php-clover coverage.clover
-
-notifications:
- email: false
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3168ee..e96b66e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,29 @@ All notable changes to `elasticsearch-query-dsl-php` will be documented in this
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
+## [6.0.0] - 2023-10-*
+### Added
+- TermsSetMatcher
+- WrapperMatcher
+- AutoIntervalDateHistogramAggregation
+- CompositeAggregation
+- ParentAggregation
+- SignificantTextAggregation
+- MedianAbsoluteDeviationAggregation
+- WeightedAvgAggregation
+- BucketSortAggregation
+- MovingFunctionAggregation
+- `SourceFilterInterface|array|null` for simplified usage
+
+### Changed
+- Parameter, property, return types
+- Renamed `RegexMatcher` to `RegexpMatcher`
+
+### Removed
+- GeoDistanceRangeMatcher
+- IndicesMatcher
+- TemplateMatcher
+
## [5.0.1] - 2018-11-04
### Added
- Documentation for using RangeMatcher with range mapping type
diff --git a/LICENSE b/LICENSE
index 82f930b..bacc48a 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2018 Gytis Šk.
+Copyright (c) 2023 Gytis Šk.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index c04b358..ebe0366 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,8 @@
# ElasticSearch Query DSL
[![Latest Version on Packagist][ico-version]][link-packagist]
-[![Build Status][ico-travis]][link-travis]
+[![Software License][ico-license]](LICENSE.md)
+[![Build Status][ico-build]][link-build]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]
@@ -13,12 +14,14 @@ Feature complete, object oriented, composable, extendable ElasticSearch query DS
- Dependency free
- Can be used with any PHP ElasticSearch client
- Fully interfaced, ready for custom classes
-- Explicit class and property naming, fully matches produced JSON
+- Explicit class and property naming, fully matches produced JSON and ElasticSearch docs
- All configuration options are listed inside classes, links to documentation
- Classes can be easily composed, extended
- Design that is easy to test and maintain
-- Chainable methods
+- Usage of setters/getters so that everything can be inlined and chained.
- Fully working `::__clone()` methods
+- Extendable code: no usage of `private`, `final` or `readonly`
+- Basic objects created on `__construct`, no unnecessary body build logic until `jsonSerialize()` is called
## Versions
@@ -26,7 +29,8 @@ Most of the classes should be compatible with any ElasticSearch versions.
If something is not compatible or not supported, `Raw*` or custom classes can be used.
| Package version | ElasticSearch version |
-| ----------------| ----------------------|
+|-----------------|-----------------------|
+| >=6.0.0 <7.0.0 | >=6.0.0 <7.0.0 |
| >=5.0.0 <6.0.0 | >=5.0.0 <6.0.0 |
Because major version number follows ElasticSearch major version number, second number is reserved for breaking changes.
@@ -56,6 +60,14 @@ $searchRequest->setAgg(
(new ElasticSearchClient())->search($searchRequest->jsonSerialize());
```
+## Matcher?
+
+Request object that is received by ElasticSearch `/_search/` has many properties and sub-properties
+like `query`, `filter`, `post_filter`, etc.
+
+To avoid convoluted expressions like `(new SearchRequest())->setQuery((new BoolQuery()->addFilter(new TermQuery('))`
+keyword `matcher` was explicitly chosen.
+
## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
@@ -75,14 +87,14 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/gskema/elasticsearch-query-dsl-php.svg?style=flat-square
-[ico-travis]: https://img.shields.io/travis/gskema/elasticsearch-query-dsl-php/master.svg?style=flat-square
+[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
+[ico-build]: https://img.shields.io/github/actions/workflow/status/gskema/elasticsearch-query-dsl-php/ci.yml?branch=81.x
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/gskema/elasticsearch-query-dsl-php.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/gskema/elasticsearch-query-dsl-php.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/gskema/elasticsearch-query-dsl-php.svg?style=flat-square
[link-packagist]: https://packagist.org/packages/gskema/elasticsearch-query-dsl-php
-[link-travis]: https://travis-ci.org/gskema/elasticsearch-query-dsl-php
+[link-build]: https://github.com/gskema/elasticsearch-query-dsl-php/actions
[link-scrutinizer]: https://scrutinizer-ci.com/g/gskema/elasticsearch-query-dsl-php/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/gskema/elasticsearch-query-dsl-php
[link-downloads]: https://packagist.org/packages/gskema/elasticsearch-query-dsl-php
-[link-contributors]: ../../contributors
diff --git a/composer.json b/composer.json
index 11be339..2ad3639 100644
--- a/composer.json
+++ b/composer.json
@@ -16,12 +16,14 @@
}
],
"require": {
- "php" : "^7.0",
- "ext-json": "*"
+ "php": "^8.1",
+ "ext-json": "*",
+ "gskema/phpcs-type-sniff": "^81.3"
},
"require-dev": {
- "phpunit/phpunit" : "^6.5",
- "squizlabs/php_codesniffer": "^2.6.2"
+ "phpunit/phpunit" : "^10.4",
+ "squizlabs/php_codesniffer": "^3.7",
+ "scrutinizer/ocular": "^1.9"
},
"autoload": {
"psr-4": {
@@ -33,14 +35,11 @@
"psr-4": { "Gskema\\ElasticSearchQueryDSL\\": "tests/" }
},
"scripts": {
- "test": "phpunit",
- "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests --exclude=Generic.Files.LineLength",
- "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
- },
- "extra": {
- "branch-alias": {
- "dev-master": "1.0-dev"
- }
+ "test": "vendor/bin/phpunit",
+ "test-coverage": "vendor/bin/phpunit --coverage-clover=clover.xml",
+ "test-coverage-local": "php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-html=build/coverage",
+ "upload-coverage": "vendor/bin/ocular code-coverage:upload --format=php-clover coverage.xml;",
+ "style": "@composer prep && ./vendor/bin/phpcs --standard=phpcs.xml -p"
},
"config": {
"sort-packages": true
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..ee10b66
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,18 @@
+
+
+
+ ~
+
+
+
+ src
+ tests
+
+
+
+
+
+ ./vendor/autoload.php
+
+
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 22fe879..b0d4e83 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,29 +1,28 @@
-
+
-
- tests
+
+ tests
-
-
- src/
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
diff --git a/src/Aggregation/AggregationInterface.php b/src/Aggregation/AggregationInterface.php
index eed4b5c..155e91c 100644
--- a/src/Aggregation/AggregationInterface.php
+++ b/src/Aggregation/AggregationInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations.html
*/
interface AggregationInterface extends JsonSerializable
{
diff --git a/src/Aggregation/Bucket/AdjacencyMatrixAggregation.php b/src/Aggregation/Bucket/AdjacencyMatrixAggregation.php
index 04cac7c..f9de057 100644
--- a/src/Aggregation/Bucket/AdjacencyMatrixAggregation.php
+++ b/src/Aggregation/Bucket/AdjacencyMatrixAggregation.php
@@ -2,31 +2,28 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use InvalidArgumentException;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-adjacency-matrix-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-adjacency-matrix-aggregation.html
* @see AdjacencyMatrixAggregationTest
*/
class AdjacencyMatrixAggregation implements BucketAggregationInterface
{
use HasAggsTrait;
- /** @var MatcherInterface[] */
- protected $filters;
-
- /**
- * @param MatcherInterface[] $filtersByName
- */
- public function __construct(array $filtersByName)
- {
- if (empty($filtersByName)) {
+ public function __construct(
+ /** @var array */
+ protected array $filters,
+ ) {
+ if (empty($filters)) {
throw new InvalidArgumentException('Expected at least one filter, got none');
}
- $this->filters = $filtersByName;
}
public function __clone()
@@ -36,17 +33,15 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
- $body['adjacency_matrix']['filters'] = array_map(function (MatcherInterface $filter) {
- return $filter->jsonSerialize();
- }, $this->filters);
+ $body['adjacency_matrix']['filters'] = obj_array_json_serialize($this->filters);
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/AutoIntervalDateHistogramAggregation.php b/src/Aggregation/Bucket/AutoIntervalDateHistogramAggregation.php
new file mode 100644
index 0000000..a36f364
--- /dev/null
+++ b/src/Aggregation/Bucket/AutoIntervalDateHistogramAggregation.php
@@ -0,0 +1,92 @@
+ 'yyyy-MM-dd',
+ 'time_zone' => '-01:00',
+ 'missing' => '2000/01/01',
+])]
+class AutoIntervalDateHistogramAggregation implements BucketAggregationInterface
+{
+ use HasAggsTrait;
+ use HasOptionsTrait;
+
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ protected int $buckets,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
+ $this->options = $options;
+ }
+
+ public function __clone(): void
+ {
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
+ $this->aggs = array_clone($this->aggs);
+ }
+
+ /**
+ * @param array $options
+ */
+ public static function fromField(
+ string $field,
+ int $buckets,
+ array $options = [],
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $buckets, $options);
+ }
+
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, int $buckets, array $options = []): static
+ {
+ return new static(null, $script, $buckets, $options);
+ }
+
+ public function jsonSerialize(): mixed
+ {
+ $aggBody = [];
+ if (null !== $this->field) {
+ $aggBody['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $aggBody['script'] = $this->script;
+ }
+ $aggBody['buckets'] = $this->buckets;
+ $aggBody += $this->options;
+
+ $body = [];
+ $body['auto_date_histogram'] = $aggBody;
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
+ }
+
+ return $body;
+ }
+}
diff --git a/src/Aggregation/Bucket/BucketAggregationInterface.php b/src/Aggregation/Bucket/BucketAggregationInterface.php
index 4690f54..69a1e02 100644
--- a/src/Aggregation/Bucket/BucketAggregationInterface.php
+++ b/src/Aggregation/Bucket/BucketAggregationInterface.php
@@ -5,58 +5,29 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\AggregationInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket.html
*/
interface BucketAggregationInterface extends AggregationInterface
{
/**
- * @return AggregationInterface[]
+ * @return array
*/
public function getAggs(): array;
- /**
- * @param string $key
- *
- * @return AggregationInterface|null
- */
- public function getAgg(string $key);
+ public function getAgg(string $key): ?AggregationInterface;
/**
- * @param AggregationInterface[] $aggs
- *
- * @return $this
+ * @param array $keyAggMap
*/
- public function setAggs(array $aggs);
+ public function setAggs(array $keyAggMap): static;
- /**
- * @param string $key
- * @param AggregationInterface $agg
- *
- * @return $this
- */
- public function setAgg(string $key, AggregationInterface $agg);
+ public function setAgg(string $key, AggregationInterface $agg): static;
- /**
- * @return $this
- */
- public function removeAggs();
+ public function removeAggs(): static;
- /**
- * @param string $key
- *
- * @return $this
- */
- public function removeAgg(string $key);
+ public function removeAgg(string $key): static;
- /**
- * @return bool
- */
public function hasAggs(): bool;
- /**
- * @param string $key
- *
- * @return bool
- */
public function hasAgg(string $key): bool;
}
diff --git a/src/Aggregation/Bucket/ChildrenAggregation.php b/src/Aggregation/Bucket/ChildrenAggregation.php
index 4b06748..24a0912 100644
--- a/src/Aggregation/Bucket/ChildrenAggregation.php
+++ b/src/Aggregation/Bucket/ChildrenAggregation.php
@@ -2,23 +2,22 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-children-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-children-aggregation.html
* @see ChildrenAggregationTest
*/
class ChildrenAggregation implements BucketAggregationInterface
{
use HasAggsTrait;
- /** @var string */
- protected $childrenType;
-
- public function __construct(string $childrenType)
- {
- $this->childrenType = $childrenType;
+ public function __construct(
+ protected string $childrenType,
+ ) {
}
public function __clone()
@@ -27,15 +26,15 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['children']['type'] = $this->childrenType;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/CompositeAggregation.php b/src/Aggregation/Bucket/CompositeAggregation.php
new file mode 100644
index 0000000..25c1ef8
--- /dev/null
+++ b/src/Aggregation/Bucket/CompositeAggregation.php
@@ -0,0 +1,54 @@
+ 10,
+ 'after' => ['date' => 1494288000000, 'product' => 'mad max'],
+])]
+class CompositeAggregation implements BucketAggregationInterface
+{
+ use HasAggsTrait;
+ use HasOptionsTrait;
+
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ /** @var array[] */
+ protected array $sources,
+ array $options = [],
+ ) {
+ $this->options = $options;
+ }
+
+ public function __clone(): void
+ {
+ $this->sources = array_clone($this->sources);
+ $this->aggs = array_clone($this->aggs);
+ }
+
+ public function jsonSerialize(): mixed
+ {
+ $aggBody = $this->options;
+ $aggBody['sources'] = $this->sources;
+
+ $body = ['composite' => $aggBody];
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
+ }
+
+ return $body;
+ }
+}
diff --git a/src/Aggregation/Bucket/DateHistogramAggregation.php b/src/Aggregation/Bucket/DateHistogramAggregation.php
index ceb919c..304eb26 100644
--- a/src/Aggregation/Bucket/DateHistogramAggregation.php
+++ b/src/Aggregation/Bucket/DateHistogramAggregation.php
@@ -2,88 +2,102 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-datehistogram-aggregation.html
* @see DateHistogramAggregationTest
- *
- * @options 'format' => 'yyyy-MM-dd',
- * 'time_zone' => '-01:00'
- * 'offset' => '+6h'
- * 'keyed' => true,
- * 'order' => ['_key' => 'desc'],
- * 'min_doc_count' => 1,
- * 'missing' => '2000/01/01',
- * 'extended_bounds' => ['min' => '2000/01/01', 'max' => '2030/01/01'],
*/
+#[Options([
+ 'format' => 'yyyy-MM-dd',
+ 'time_zone' => '-01:00',
+ 'offset' => '+6h',
+ 'keyed' => true,
+ 'order' => ['_key' => 'desc'],
+ 'min_doc_count' => 1,
+ 'missing' => '2000/01/01',
+ 'extended_bounds' => ['min' => '2000/01/01', 'max' => '2030/01/01'],
+])]
class DateHistogramAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var array */
- protected $body;
-
/**
- * 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second'
- * '?d', '?h', '?m, '?s', '?ms', '?micros', '?nanos'
- *
- * @var string
+ * @param array $options
*/
- protected $interval;
-
- protected function __construct(array $body, string $interval, array $options = [])
- {
- $this->body = $body;
- $this->interval = $interval;
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ // 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second'
+ // '?d', '?h', '?m, '?s', '?ms', '?micros', '?nanos'
+ protected string $interval,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
$this->options = $options;
}
public function __clone()
{
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
$this->aggs = array_clone($this->aggs);
}
+ /**
+ * @param array $options
+ */
public static function fromField(
string $field,
string $interval,
array $options = [],
- InlineScript $valueScript = null
- ): DateHistogramAggregation {
- $body = [];
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $interval, $options);
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $interval, $options);
}
+ /**
+ * @param array $options
+ */
public static function fromScript(
ScriptInterface $script,
string $interval,
- array $options = []
- ): DateHistogramAggregation {
- return new static(['script' => $script->jsonSerialize()], $interval, $options);
+ array $options = [],
+ ): static {
+ return new static(null, $script, $interval, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = [];
- $body['date_histogram'] = $this->body;
- $body['date_histogram']['interval'] = $this->interval;
- $body['date_histogram'] += $this->options;
+ $aggBody = [];
+ if (null !== $this->field) {
+ $aggBody['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $aggBody['script'] = $this->script;
+ }
+ $aggBody['interval'] = $this->interval;
+ $aggBody += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ $body = [];
+ $body['date_histogram'] = $aggBody;
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/DateRangeAggregation.php b/src/Aggregation/Bucket/DateRangeAggregation.php
index a4baad1..6043a27 100644
--- a/src/Aggregation/Bucket/DateRangeAggregation.php
+++ b/src/Aggregation/Bucket/DateRangeAggregation.php
@@ -2,37 +2,37 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-daterange-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-daterange-aggregation.html
* @see DateRangeAggregationTest
- *
- * @options 'format' => 'MM-yyy'
- * 'time_zone' => 'CET',
- * 'keyed' => true,
*/
+#[Options([
+ 'format' => 'MM-yyy',
+ 'time_zone' => 'CET',
+ 'keyed' => true,
+ 'missing' => '1976/11/30',
+])]
class DateRangeAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var string */
- protected $field;
-
/**
- * ['from' => '2016/02/01', 'to' => 'now/d', 'key' => 'custom_bucket_key'],
- *
- * @var array[]
+ * @param array $options
*/
- protected $ranges;
-
- public function __construct(string $field, array $ranges, array $options = [])
- {
- $this->field = $field;
- $this->ranges = $ranges;
+ public function __construct(
+ protected string $field,
+ /** @var array[] ['from' => '2016/02/01', 'to' => 'now/d', 'key' => 'custom_bucket_key'], */
+ protected array $ranges,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -42,17 +42,17 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['date_range']['field'] = $this->field;
$body['date_range']['ranges'] = $this->ranges;
$body['date_range'] += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/DayOfWeekAggregation.php b/src/Aggregation/Bucket/DayOfWeekAggregation.php
index 5abf40e..147bc8f 100644
--- a/src/Aggregation/Bucket/DayOfWeekAggregation.php
+++ b/src/Aggregation/Bucket/DayOfWeekAggregation.php
@@ -2,38 +2,43 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html#_use_of_a_script_to_aggregate_by_day_of_the_week
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-datehistogram-aggregation.html#_using_a_script_to_aggregate_by_day_of_the_week
* @see DayOfWeekAggregationTest
- *
- * @options 'size' => 5,
- * 'shard_size' => 5,
- * 'show_term_doc_count_error' => true,
- * 'order' => ['_count' => 'asc'],
- * 'min_doc_count' => 1,
- * 'shard_min_doc_count' => 0,
- * 'include' => '.*sport.*', ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
- * 'exclude' => 'water_.*', ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
- * 'collect_mode' => 'breadth_first', 'depth_first',
- * 'execution_hint' => 'map', 'global_ordinals', 'global_ordinals_hash', 'global_ordinals_low_cardinality',
- * 'missing' => 'N/A',
*/
+#[Options([
+ 'size' => 5,
+ 'shard_size' => 5,
+ 'show_term_doc_count_error' => true,
+ 'order' => ['_count' => 'asc'],
+ 'min_doc_count' => 1,
+ 'shard_min_doc_count' => 0,
+ 'include' => '.*sport.*', // ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
+ 'exclude' => 'water_.*', // ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
+ 'collect_mode' => 'breadth_first', // 'depth_first',
+ 'execution_hint' => 'map', // 'global_ordinals', 'global_ordinals_hash', 'global_ordinals_low_cardinality',
+ 'missing' => 'N/A',
+])]
class DayOfWeekAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field, array $options = [])
- {
- $this->field = $field;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -43,18 +48,18 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $script = new InlineScript('doc[\''.$this->field.'\'].date.dayOfWeek', [], 'expression');
+ $script = new InlineScript('doc[\'' . $this->field . '\'].value.dayOfWeekEnum.value', [], 'painless');
$body = [];
$body['terms']['script'] = $script->jsonSerialize();
$body['terms'] += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/DiversifiedSamplerAggregation.php b/src/Aggregation/Bucket/DiversifiedSamplerAggregation.php
index 5e06f21..1a4892c 100644
--- a/src/Aggregation/Bucket/DiversifiedSamplerAggregation.php
+++ b/src/Aggregation/Bucket/DiversifiedSamplerAggregation.php
@@ -2,59 +2,85 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-diversified-sampler-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-diversified-sampler-aggregation.html
* @see DiversifiedSamplerAggregationTest
- *
- * @options 'shard_size' => 100,
- * 'max_docs_per_value' => 1,
- * 'execution_hint' => 'global_ordinals', 'map', 'bytes_hash'
*/
+#[Options([
+ 'shard_size' => 100,
+ 'max_docs_per_value' => 1,
+ 'execution_hint' => 'global_ordinals', // 'map', 'bytes_hash'
+])]
class DiversifiedSamplerAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var array */
- protected $body;
-
- protected function __construct(array $body, array $options = [])
- {
- $this->body = $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
$this->options = $options;
}
public function __clone()
{
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
$this->aggs = array_clone($this->aggs);
}
- public static function fromField(string $field, array $options = []): DiversifiedSamplerAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromField(string $field, array $options = []): static
{
- return new static(['field' => $field], $options);
+ return new static($field, null, $options);
}
- public static function fromScript(ScriptInterface $script, array $options = []): DiversifiedSamplerAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, array $options = []): static
{
- return new static(['script' => $script->jsonSerialize()], $options);
+ return new static(null, $script, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = [];
- $body['diversified_sampler'] = $this->body;
- $body['diversified_sampler'] += $this->options;
+ $aggBody = [];
+ if (null !== $this->field) {
+ $aggBody['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $aggBody['script'] = $this->script;
+ }
+ $aggBody += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ $body = [];
+ $body['diversified_sampler'] = $aggBody;
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/FilterAggregation.php b/src/Aggregation/Bucket/FilterAggregation.php
index fef8185..510e6d8 100644
--- a/src/Aggregation/Bucket/FilterAggregation.php
+++ b/src/Aggregation/Bucket/FilterAggregation.php
@@ -2,24 +2,23 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-filter-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-filter-aggregation.html
* @see FilterAggregationTest
*/
class FilterAggregation implements BucketAggregationInterface
{
use HasAggsTrait;
- /** @var MatcherInterface */
- protected $filter;
-
- public function __construct(MatcherInterface $filter)
- {
- $this->filter = $filter;
+ public function __construct(
+ protected MatcherInterface $filter,
+ ) {
}
public function __clone()
@@ -29,15 +28,15 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['filter'] = $this->filter->jsonSerialize();
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/FiltersAggregation.php b/src/Aggregation/Bucket/FiltersAggregation.php
index 9accb77..ac026bf 100644
--- a/src/Aggregation/Bucket/FiltersAggregation.php
+++ b/src/Aggregation/Bucket/FiltersAggregation.php
@@ -2,29 +2,35 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-filters-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-filters-aggregation.html
* @see FiltersAggregationTest
- *
- * @options 'other_bucket' => true,
- * 'other_bucket_key' => 'custom_key',
*/
+#[Options([
+ 'other_bucket' => true,
+ 'other_bucket_key' => 'custom_key',
+])]
class FiltersAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var MatcherInterface[] */
- protected $filters;
-
- public function __construct(array $filtersByName, array $options = [])
- {
- $this->filters = $filtersByName;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ /** @var array */
+ protected array $filters,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -35,18 +41,16 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
- $body['filters']['filters'] = array_map(function (MatcherInterface $filter) {
- return $filter->jsonSerialize();
- }, $this->filters);
+ $body['filters']['filters'] = obj_array_json_serialize($this->filters);
$body['filters'] += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/GeoDistanceAggregation.php b/src/Aggregation/Bucket/GeoDistanceAggregation.php
index f81ff3f..71b1e74 100644
--- a/src/Aggregation/Bucket/GeoDistanceAggregation.php
+++ b/src/Aggregation/Bucket/GeoDistanceAggregation.php
@@ -2,42 +2,38 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\GeoPointInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-geodistance-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-geodistance-aggregation.html
* @see GeoDistanceAggregationTest
- *
- * @options 'unit' => 'km',
- * 'distance_type' => 'plane',
- * 'keyed' => true,
*/
+#[Options([
+ 'unit' => 'km',
+ 'distance_type' => 'plane', // 'arc',
+ 'keyed' => true,
+])]
class GeoDistanceAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var string */
- protected $field;
-
- /** @var GeoPointInterface */
- protected $origin;
-
/**
- * ['from' => 10, 'to' => 99, 'key' => 'custom_bucket_key'],
- *
- * @var array[]
+ * @param array $options
*/
- protected $ranges;
-
- public function __construct(string $field, GeoPointInterface $origin, array $ranges, array $options = [])
- {
- $this->field = $field;
- $this->origin = $origin;
- $this->ranges = $ranges;
+ public function __construct(
+ protected string $field,
+ protected GeoPointInterface $origin,
+ /** @var array[] ['from' => 10, 'to' => 99, 'key' => 'custom_bucket_key'], */
+ protected array $ranges,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -48,9 +44,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['geo_distance'] = [
@@ -60,8 +56,8 @@ public function jsonSerialize()
];
$body['geo_distance'] += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/GeoHashGridAggregation.php b/src/Aggregation/Bucket/GeoHashGridAggregation.php
index f1cd197..12cc3d7 100644
--- a/src/Aggregation/Bucket/GeoHashGridAggregation.php
+++ b/src/Aggregation/Bucket/GeoHashGridAggregation.php
@@ -2,29 +2,34 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-geohashgrid-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-geohashgrid-aggregation.html
* @see GeoHashGridAggregationTest
- *
- * @options 'precision' => 3,
- * 'size' => 10000,
- * 'shard_size' => 10,
*/
+#[Options([
+ 'precision' => 3,
+ 'size' => 10000,
+ 'shard_size' => 10,
+])]
class GeoHashGridAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field, array $options = [])
- {
- $this->field = $field;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -34,16 +39,16 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['geohash_grid']['field'] = $this->field;
$body['geohash_grid'] += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/GlobalAggregation.php b/src/Aggregation/Bucket/GlobalAggregation.php
index e10644c..2343b72 100644
--- a/src/Aggregation/Bucket/GlobalAggregation.php
+++ b/src/Aggregation/Bucket/GlobalAggregation.php
@@ -2,12 +2,14 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-global-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-global-aggregation.html
* @see GlobalAggregationTest
*/
class GlobalAggregation implements BucketAggregationInterface
@@ -20,15 +22,15 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['global'] = new stdClass();
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/HistogramAggregation.php b/src/Aggregation/Bucket/HistogramAggregation.php
index f341d9d..3601e81 100644
--- a/src/Aggregation/Bucket/HistogramAggregation.php
+++ b/src/Aggregation/Bucket/HistogramAggregation.php
@@ -2,81 +2,91 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-histogram-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-histogram-aggregation.html
* @see HistogramAggregationTest
- *
- * @options 'min_doc_count' => 1,
- * 'extended_bounds' => ['min' => 0, 'max' => 500],
- * 'order' => ['_key' => 'desc'],
- * 'offset' => 5,
- * 'keyed' => true,
- * 'missing' => 0,
*/
+#[Options([
+ 'min_doc_count' => 1,
+ 'extended_bounds' => ['min' => 0, 'max' => 500],
+ 'order' => ['_key' => 'desc'],
+ 'offset' => 5,
+ 'keyed' => true,
+ 'missing' => 0,
+])]
class HistogramAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var array */
- protected $body;
-
- /** @var float */
- protected $interval;
-
- protected function __construct(array $body, float $interval, array $options = [])
- {
- $this->body = $body;
- $this->interval = $interval;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ protected float $interval,
+ array $options = [],
+ ) {
$this->options = $options;
}
public function __clone()
{
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
$this->aggs = array_clone($this->aggs);
}
+ /**
+ * @param array $options
+ */
public static function fromField(
string $field,
float $interval,
array $options = [],
- InlineScript $valueScript = null
- ): HistogramAggregation {
- $body = [];
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $interval, $options);
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $interval, $options);
}
- public static function fromScript(
- ScriptInterface $script,
- float $interval,
- array $options = []
- ): HistogramAggregation {
- return new static(['script' => $script->jsonSerialize()], $interval, $options);
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, float $interval, array $options = []): static
+ {
+ return new static(null, $script, $interval, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = [];
- $body['histogram'] = $this->body;
- $body['histogram']['interval'] = $this->interval;
- $body['histogram'] += $this->options;
+ $aggBody = [];
+ if (null !== $this->field) {
+ $aggBody['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $aggBody['script'] = $this->script;
+ }
+ $aggBody['interval'] = $this->interval;
+ $aggBody += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ $body = [];
+ $body['histogram'] = $aggBody;
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/IpRangeAggregation.php b/src/Aggregation/Bucket/IpRangeAggregation.php
index a766781..c91ba46 100644
--- a/src/Aggregation/Bucket/IpRangeAggregation.php
+++ b/src/Aggregation/Bucket/IpRangeAggregation.php
@@ -2,36 +2,38 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-iprange-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-iprange-aggregation.html
* @see IpRangeAggregationTest
- *
- * @options 'keyed' => true,
*/
+#[Options([
+ 'keyed' => true,
+])]
class IpRangeAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var string */
- protected $field;
-
/**
- * ['from' => '10.0.0.5', 'to' => '10.0.0.5', 'key' => 'custom_bucket_key'],
- * ['mask' => '10.0.0.0/25', 'key' => 'custom_bucket_key'],
- *
- * @var array[]
+ * @param array $options
*/
- protected $ranges;
-
- public function __construct(string $field, array $ranges, array $options = [])
- {
- $this->field = $field;
- $this->ranges = $ranges;
+ public function __construct(
+ protected string $field,
+ /**
+ * @var array[]
+ * ['from' => '10.0.0.5', 'to' => '10.0.0.5', 'key' => 'custom_bucket_key'],
+ * ['mask' => '10.0.0.0/25', 'key' => 'custom_bucket_key'],
+ */
+ protected array $ranges,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -41,17 +43,17 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['ip_ranges']['field'] = $this->field;
$body['ip_ranges']['ranges'] = $this->ranges;
$body['ip_ranges'] += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/MissingAggregation.php b/src/Aggregation/Bucket/MissingAggregation.php
index 2b5b506..87b5024 100644
--- a/src/Aggregation/Bucket/MissingAggregation.php
+++ b/src/Aggregation/Bucket/MissingAggregation.php
@@ -2,23 +2,22 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-missing-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-missing-aggregation.html
* @see MissingAggregationTest
*/
class MissingAggregation implements BucketAggregationInterface
{
use HasAggsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field)
- {
- $this->field = $field;
+ public function __construct(
+ protected string $field,
+ ) {
}
public function __clone()
@@ -27,15 +26,15 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['missing']['field'] = $this->field;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/NestedAggregation.php b/src/Aggregation/Bucket/NestedAggregation.php
index 7d41fd6..57ac232 100644
--- a/src/Aggregation/Bucket/NestedAggregation.php
+++ b/src/Aggregation/Bucket/NestedAggregation.php
@@ -2,23 +2,22 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-nested-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-nested-aggregation.html
* @see NestedAggregationTest
*/
class NestedAggregation implements BucketAggregationInterface
{
use HasAggsTrait;
- /** @var string */
- protected $path;
-
- public function __construct(string $path)
- {
- $this->path = $path;
+ public function __construct(
+ protected string $path,
+ ) {
}
public function __clone()
@@ -27,15 +26,15 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['nested']['path'] = $this->path;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/ParentAggregation.php b/src/Aggregation/Bucket/ParentAggregation.php
new file mode 100644
index 0000000..0439068
--- /dev/null
+++ b/src/Aggregation/Bucket/ParentAggregation.php
@@ -0,0 +1,37 @@
+aggs = array_clone($this->aggs);
+ }
+
+ public function jsonSerialize(): mixed
+ {
+ $body = ['parent' => ['type' => $this->type]];
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
+ }
+
+ return $body;
+ }
+}
diff --git a/src/Aggregation/Bucket/RangeAggregation.php b/src/Aggregation/Bucket/RangeAggregation.php
index 9cda62f..6f86eba 100644
--- a/src/Aggregation/Bucket/RangeAggregation.php
+++ b/src/Aggregation/Bucket/RangeAggregation.php
@@ -2,77 +2,92 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-range-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-range-aggregation.html
* @see RangeAggregationTest
- *
- * @options 'keyed' => true,
*/
+#[Options([
+ 'keyed' => true,
+])]
class RangeAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var array */
- protected $body;
-
/**
- * ['from' => 5, 'to' => 5, 'key' => 'custom_bucket_key'],
- *
- * @var array[]
+ * @param array $options
*/
- protected $ranges;
-
- protected function __construct(array $body, array $ranges, array $options = [])
- {
- $this->body = $body;
- $this->ranges = $ranges;
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ /** @var array[] ['from' => 5, 'to' => 5, 'key' => 'custom_bucket_key'], */
+ protected array $ranges,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
$this->options = $options;
}
public function __clone()
{
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
$this->aggs = array_clone($this->aggs);
}
+ /**
+ * @param array[] $ranges
+ * @param array $options
+ */
public static function fromField(
string $field,
array $ranges,
array $options = [],
- InlineScript $valueScript = null
- ): RangeAggregation {
- $body = [];
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $ranges, $options);
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $ranges, $options);
}
- public static function fromScript(ScriptInterface $script, array $ranges, array $options = []): RangeAggregation
+ /**
+ * @param mixed[][] $ranges
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, array $ranges, array $options = []): static
{
- return new static(['script' => $script->jsonSerialize()], $ranges, $options);
+ return new static(null, $script, $ranges, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = [];
- $body['range'] = $this->body;
- $body['range']['ranges'] = $this->ranges;
- $body['range'] += $this->options;
+ $aggBody = [];
+ if (null !== $this->field) {
+ $aggBody['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $aggBody['script'] = $this->script;
+ }
+ $aggBody['ranges'] = $this->ranges;
+ $aggBody += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ $body = ['range' => $aggBody];
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/RawBucketAggregation.php b/src/Aggregation/Bucket/RawBucketAggregation.php
index 5876da8..899da4e 100644
--- a/src/Aggregation/Bucket/RawBucketAggregation.php
+++ b/src/Aggregation/Bucket/RawBucketAggregation.php
@@ -2,10 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\RawFragment;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
* @see RawBucketAggregationTest
*/
@@ -20,14 +22,14 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = parent::jsonSerialize();
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/ReverseNestedAggregation.php b/src/Aggregation/Bucket/ReverseNestedAggregation.php
index 64b0f64..1b855d5 100644
--- a/src/Aggregation/Bucket/ReverseNestedAggregation.php
+++ b/src/Aggregation/Bucket/ReverseNestedAggregation.php
@@ -2,24 +2,22 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-reverse-nested-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-reverse-nested-aggregation.html
* @see ReverseNestedAggregationTest
*/
class ReverseNestedAggregation implements BucketAggregationInterface
{
use HasAggsTrait;
- /** @var string|null */
- protected $path;
-
- public function __construct(string $path = null)
+ public function __construct(protected ?string $path = null)
{
- $this->path = $path;
}
public function __clone()
@@ -28,9 +26,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (null !== $this->path) {
@@ -39,8 +37,8 @@ public function jsonSerialize()
$body['reverse_nested'] = new stdClass();
}
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/SamplerAggregation.php b/src/Aggregation/Bucket/SamplerAggregation.php
index be8e8b2..c97620c 100644
--- a/src/Aggregation/Bucket/SamplerAggregation.php
+++ b/src/Aggregation/Bucket/SamplerAggregation.php
@@ -2,22 +2,29 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-sampler-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-sampler-aggregation.html
* @see SamplerAggregationTest
- *
- * @options 'shard_size' => 100,
*/
+#[Options([
+ 'shard_size' => 100,
+])]
class SamplerAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
+ /**
+ * @param array $options
+ */
public function __construct(array $options = [])
{
$this->options = $options;
@@ -29,9 +36,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (empty($this->options)) {
@@ -40,8 +47,8 @@ public function jsonSerialize()
$body['sampler'] = $this->options;
}
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/SignificantTermsAggregation.php b/src/Aggregation/Bucket/SignificantTermsAggregation.php
index 8abdf3a..14b1110 100644
--- a/src/Aggregation/Bucket/SignificantTermsAggregation.php
+++ b/src/Aggregation/Bucket/SignificantTermsAggregation.php
@@ -2,42 +2,47 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-significantterms-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-significantterms-aggregation.html
* @see SignificantTermsAggregationTest
- *
- * @options 'background_filter' => MatcherInterface,
- * 'size' => 3,
- * 'shard_size' => 3,
- * 'mutual_information' => ['include_negatives' => false, 'background_is_superset' => false],
- * 'chi_square' => ['include_negatives' => false, 'background_is_superset' => false],
- * 'jlh' => ?,
- * 'gnd' => ['background_is_superset' => false],
- * 'percentage' => new \stdClass(),
- * 'scripted_heuristic' => ScriptInterface,
- * 'min_doc_count' => 3,
- * 'shard_min_doc_count' => 1,
- * 'include' => '.*sport.*',
- * 'exclude' => 'water_.*',
- * 'execution_hint' => 'map',
*/
+#[Options([
+ 'background_filter' => MatcherInterface::class,
+ 'size' => 3,
+ 'shard_size' => 3,
+ 'mutual_information' => ['include_negatives' => false, 'background_is_superset' => false],
+ 'chi_square' => ['include_negatives' => false, 'background_is_superset' => false],
+ 'jlh' => '?',
+ 'gnd' => ['background_is_superset' => false],
+ 'percentage' => new \stdClass(),
+ 'scripted_heuristic' => ScriptInterface::class,
+ 'min_doc_count' => 3,
+ 'shard_min_doc_count' => 1,
+ 'include' => '.*sport.*',
+ 'exclude' => 'water_.*',
+ 'execution_hint' => 'map',
+])]
class SignificantTermsAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field, array $options = [])
- {
- $this->field = $field;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -48,9 +53,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$aggBody = [];
$aggBody['field'] = $this->field;
@@ -70,8 +75,8 @@ public function jsonSerialize()
$body = [];
$body['significant_terms'] = $aggBody;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/Bucket/SignificantTextAggregation.php b/src/Aggregation/Bucket/SignificantTextAggregation.php
new file mode 100644
index 0000000..29acfbf
--- /dev/null
+++ b/src/Aggregation/Bucket/SignificantTextAggregation.php
@@ -0,0 +1,74 @@
+ true,
+ 'size' => 3,
+ 'shard_size' => 3,
+ 'min_doc_count' => 3,
+ 'shard_min_doc_count' => 1,
+ 'background_filter' => MatcherInterface::class,
+ 'source_fields' => ['content', 'title'],
+ 'include' => '.*sport.*',
+ 'exclude' => 'water_.*',
+ 'mutual_information' => ['include_negatives' => false, 'background_is_superset' => false],
+ 'chi_square' => ['include_negatives' => false, 'background_is_superset' => false],
+ 'jlh' => '?',
+ 'gnd' => ['background_is_superset' => false],
+])]
+class SignificantTextAggregation implements BucketAggregationInterface
+{
+ use HasOptionsTrait;
+ use HasAggsTrait;
+
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
+ $this->options = $options;
+ }
+
+ public function __clone()
+ {
+ $this->options = array_clone($this->options);
+ $this->aggs = array_clone($this->aggs);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function jsonSerialize(): mixed
+ {
+ $aggBody = [];
+ $aggBody['field'] = $this->field;
+ $aggBody += $this->options;
+
+ if (!empty($aggBody['background_filter']) && $aggBody['background_filter'] instanceof MatcherInterface) {
+ $aggBody['background_filter'] = $aggBody['background_filter']->jsonSerialize();
+ }
+
+ $body = [];
+ $body['significant_text'] = $aggBody;
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
+ }
+
+ return $body;
+ }
+}
diff --git a/src/Aggregation/Bucket/TermsAggregation.php b/src/Aggregation/Bucket/TermsAggregation.php
index 121d633..d2fd92b 100644
--- a/src/Aggregation/Bucket/TermsAggregation.php
+++ b/src/Aggregation/Bucket/TermsAggregation.php
@@ -2,76 +2,97 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-terms-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-terms-aggregation.html
* @see TermsAggregationTest
- *
- * @options 'size' => 5,
- * 'shard_size' => 5,
- * 'show_term_doc_count_error' => true,
- * 'order' => ['_count' => 'asc'],
- * 'min_doc_count' => 1,
- * 'shard_min_doc_count' => 0,
- * 'include' => '.*sport.*', ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
- * 'exclude' => 'water_.*', ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
- * 'collect_mode' => 'breadth_first', 'depth_first',
- * 'execution_hint' => 'map', 'global_ordinals', 'global_ordinals_hash', 'global_ordinals_low_cardinality',
- * 'missing' => 'N/A',
*/
+#[Options([
+ 'size' => 5,
+ 'shard_size' => 5,
+ 'show_term_doc_count_error' => true,
+ 'order' => ['_count' => 'asc'],
+ 'min_doc_count' => 1,
+ 'shard_min_doc_count' => 0,
+ 'include' => '.*sport.*', // ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
+ 'exclude' => 'water_.*', // ['mazda', 'toyota'], ['partition' => 0, 'num_partitions' => 20],
+ 'collect_mode' => 'breadth_first', // 'depth_first',
+ 'execution_hint' => 'map', // 'global_ordinals',
+ 'missing' => 'N/A',
+ 'missing_bucket' => true, // when under composite agg
+])]
class TermsAggregation implements BucketAggregationInterface
{
use HasOptionsTrait;
use HasAggsTrait;
- /** @var array */
- protected $body;
-
- protected function __construct(array $body, array $options = [])
- {
- $this->body = $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
$this->options = $options;
}
public function __clone()
{
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
$this->aggs = array_clone($this->aggs);
}
+ /**
+ * @param array $options
+ */
public static function fromField(
string $field,
array $options = [],
- ScriptInterface $valueScript = null
- ): TermsAggregation {
- $body = [];
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $options);
+ ?ScriptInterface $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $options);
}
- public static function fromScript(ScriptInterface $script, array $options = []): TermsAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, array $options = []): static
{
- return new static(['script' => $script->jsonSerialize()], $options);
+ return new static(null, $script, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = [];
- $body['terms'] = $this->body;
- $body['terms'] += $this->options;
+ $aggBody = [];
+ if (null !== $this->field) {
+ $aggBody['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $aggBody['script'] = $this->script;
+ }
+ $aggBody += $this->options;
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ $body = [];
+ $body['terms'] = $aggBody;
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
return $body;
diff --git a/src/Aggregation/EmptyAggregation.php b/src/Aggregation/EmptyAggregation.php
index 1c1936b..a7904e1 100644
--- a/src/Aggregation/EmptyAggregation.php
+++ b/src/Aggregation/EmptyAggregation.php
@@ -5,23 +5,20 @@
use stdClass;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-range-aggregation.html#_sub_aggregations
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-range-aggregation.html#_sub_aggregations
* @see EmptyAggregationTest
*/
class EmptyAggregation implements AggregationInterface
{
- /** @var string */
- protected $type;
-
- public function __construct(string $type)
- {
- $this->type = $type;
+ public function __construct(
+ protected string $type,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return [
$this->type => new stdClass(),
diff --git a/src/Aggregation/Matrix/MatrixAggregationInterface.php b/src/Aggregation/Matrix/MatrixAggregationInterface.php
index 8c366ea..8d0f6e7 100644
--- a/src/Aggregation/Matrix/MatrixAggregationInterface.php
+++ b/src/Aggregation/Matrix/MatrixAggregationInterface.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\AggregationInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-matrix.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-matrix.html
*/
interface MatrixAggregationInterface extends AggregationInterface
{
diff --git a/src/Aggregation/Matrix/MatrixStatsAggregation.php b/src/Aggregation/Matrix/MatrixStatsAggregation.php
index d22734e..0d49c2c 100644
--- a/src/Aggregation/Matrix/MatrixStatsAggregation.php
+++ b/src/Aggregation/Matrix/MatrixStatsAggregation.php
@@ -3,35 +3,35 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Matrix;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-matrix-stats-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-matrix-stats-aggregation.html
* @see MatrixStatsAggregationTest
- *
- * @options 'mode' => 'avg', 'min', 'max', 'sum', 'median',
- * 'missing' => ['field1' => 50, 'field2' => 100],
*/
+#[Options([
+ 'mode' => 'avg', // 'min', 'max', 'sum', 'median',
+ 'missing' => ['field1' => 50, 'field2' => 100],
+])]
class MatrixStatsAggregation implements MatrixAggregationInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field1;
-
- /** @var string */
- protected $field2;
-
- public function __construct(string $field1, string $field2, array $options = [])
- {
- $this->field1 = $field1;
- $this->field2 = $field2;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field1,
+ protected string $field2,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['fields'] = [$this->field1, $this->field2];
diff --git a/src/Aggregation/Metric/AbstractNumericMetricAggregation.php b/src/Aggregation/Metric/AbstractNumericMetricAggregation.php
index 86b2229..67af221 100644
--- a/src/Aggregation/Metric/AbstractNumericMetricAggregation.php
+++ b/src/Aggregation/Metric/AbstractNumericMetricAggregation.php
@@ -5,45 +5,64 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use InvalidArgumentException;
abstract class AbstractNumericMetricAggregation implements MetricAggregationInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
+ $this->options = $options;
+ }
- protected function __construct(array $body, array $options = [])
+ public function __clone()
{
- $this->body = $body;
- $this->options = $options;
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
}
+ /**
+ * @param array $options
+ */
public static function fromField(
string $field,
array $options = [],
- InlineScript $valueScript = null
- ): AbstractNumericMetricAggregation {
- $body = [];
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $options);
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $options);
}
- public static function fromScript(ScriptInterface $script, array $options = []): AbstractNumericMetricAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, array $options = []): static
{
- return new static(['script' => $script->jsonSerialize()], $options);
+ return new static(null, $script, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = $this->body;
+ $body = [];
+ if (null !== $this->field) {
+ $body['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $body['script'] = $this->script;
+ }
$body += $this->options;
return [
diff --git a/src/Aggregation/Metric/AvgAggregation.php b/src/Aggregation/Metric/AvgAggregation.php
index 66349a4..7929177 100644
--- a/src/Aggregation/Metric/AvgAggregation.php
+++ b/src/Aggregation/Metric/AvgAggregation.php
@@ -2,16 +2,19 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-avg-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-avg-aggregation.html
* @see AvgAggregationTest
- *
- * @options 'missing' => 0,
*/
+#[Options([
+ 'missing' => 0,
+])]
class AvgAggregation extends AbstractNumericMetricAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Metric/CardinalityAggregation.php b/src/Aggregation/Metric/CardinalityAggregation.php
index bacbbeb..0c1b73e 100644
--- a/src/Aggregation/Metric/CardinalityAggregation.php
+++ b/src/Aggregation/Metric/CardinalityAggregation.php
@@ -4,43 +4,70 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-cardinality-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-cardinality-aggregation.html
* @see CardinalityAggregationTest
- *
- * @options 'precision_threshold' => 3000,
- * 'missing' => 'N/A',
*/
+#[Options([
+ 'precision_threshold' => 3000,
+ 'missing' => 'N/A',
+])]
class CardinalityAggregation implements MetricAggregationInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
+ $this->options = $options;
+ }
- protected function __construct(array $body, array $options = [])
+ public function __clone()
{
- $this->body = $body;
- $this->options = $options;
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
}
- public static function fromField(string $field, array $options = []): CardinalityAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromField(string $field, array $options = []): static
{
- return new static(['field' => $field], $options);
+ return new static($field, null, $options);
}
- public static function fromScript(ScriptInterface $script, array $options = []): CardinalityAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, array $options = []): static
{
- return new static(['script' => $script->jsonSerialize()], $options);
+ return new static(null, $script, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = $this->body;
+ $body = [];
+ if (null !== $this->field) {
+ $body['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $body['script'] = $this->script;
+ }
$body += $this->options;
return [
diff --git a/src/Aggregation/Metric/ExtendedStatsAggregation.php b/src/Aggregation/Metric/ExtendedStatsAggregation.php
index d33621e..9c5a1c4 100644
--- a/src/Aggregation/Metric/ExtendedStatsAggregation.php
+++ b/src/Aggregation/Metric/ExtendedStatsAggregation.php
@@ -2,17 +2,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-extendedstats-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-extendedstats-aggregation.html
* @see ExtendedStatsAggregationTest
- *
- * @options 'sigma' => 3,
- * 'missing' => 0,
*/
+#[Options([
+ 'sigma' => 3,
+ 'missing' => 0,
+])]
class ExtendedStatsAggregation extends AbstractNumericMetricAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Metric/GeoBoundsAggregation.php b/src/Aggregation/Metric/GeoBoundsAggregation.php
index 074fb29..6b353e1 100644
--- a/src/Aggregation/Metric/GeoBoundsAggregation.php
+++ b/src/Aggregation/Metric/GeoBoundsAggregation.php
@@ -3,30 +3,33 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-geobounds-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-geobounds-aggregation.html
* @see GeoBoundsAggregationTest
- *
- * @options 'wrap_longitude' => true,
*/
+#[Options([
+ 'wrap_longitude' => true,
+])]
class GeoBoundsAggregation implements MetricAggregationInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field, array $options = [])
- {
- $this->field = $field;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['field'] = $this->field;
diff --git a/src/Aggregation/Metric/GeoCentroidAggregation.php b/src/Aggregation/Metric/GeoCentroidAggregation.php
index b3e3b0e..b3a0be7 100644
--- a/src/Aggregation/Metric/GeoCentroidAggregation.php
+++ b/src/Aggregation/Metric/GeoCentroidAggregation.php
@@ -3,23 +3,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-geocentroid-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-geocentroid-aggregation.html
* @see GeoCentroidAggregationTest
*/
class GeoCentroidAggregation implements MetricAggregationInterface
{
- /** @var string */
- protected $field;
-
- public function __construct(string $field)
- {
- $this->field = $field;
+ public function __construct(
+ protected string $field,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return [
'geo_centroid' => [
diff --git a/src/Aggregation/Metric/MaxAggregation.php b/src/Aggregation/Metric/MaxAggregation.php
index 4722619..1797ef2 100644
--- a/src/Aggregation/Metric/MaxAggregation.php
+++ b/src/Aggregation/Metric/MaxAggregation.php
@@ -2,16 +2,19 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-max-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-max-aggregation.html
* @see MaxAggregationTest
- *
- * @options 'missing' => 0,
*/
+#[Options([
+ 'missing' => 0,
+])]
class MaxAggregation extends AbstractNumericMetricAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Metric/MedianAbsoluteDeviationAggregation.php b/src/Aggregation/Metric/MedianAbsoluteDeviationAggregation.php
new file mode 100644
index 0000000..8b143c0
--- /dev/null
+++ b/src/Aggregation/Metric/MedianAbsoluteDeviationAggregation.php
@@ -0,0 +1,50 @@
+ 100,
+ 'missing' => 4,
+])]
+class MedianAbsoluteDeviationAggregation implements MetricAggregationInterface
+{
+ use HasOptionsTrait;
+
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected ScriptInterface|string $fieldOrScript,
+ array $options = [],
+ ) {
+ $this->options = $options;
+ }
+
+ public function __clone(): void
+ {
+ if (is_object($this->fieldOrScript)) {
+ $this->fieldOrScript = clone $this->fieldOrScript;
+ }
+ }
+
+ public function jsonSerialize(): mixed
+ {
+ $body = $this->options;
+
+ if ($this->fieldOrScript instanceof ScriptInterface) {
+ $body['script'] = $this->fieldOrScript->jsonSerialize();
+ } else {
+ $body['field'] = $this->fieldOrScript;
+ }
+
+ return ['median_absolute_deviation' => $body];
+ }
+}
diff --git a/src/Aggregation/Metric/MetricAggregationInterface.php b/src/Aggregation/Metric/MetricAggregationInterface.php
index 80e7431..723fbb5 100644
--- a/src/Aggregation/Metric/MetricAggregationInterface.php
+++ b/src/Aggregation/Metric/MetricAggregationInterface.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\AggregationInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics.html
*/
interface MetricAggregationInterface extends AggregationInterface
{
diff --git a/src/Aggregation/Metric/MinAggregation.php b/src/Aggregation/Metric/MinAggregation.php
index 74ff760..7b8ce9c 100644
--- a/src/Aggregation/Metric/MinAggregation.php
+++ b/src/Aggregation/Metric/MinAggregation.php
@@ -2,16 +2,19 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-min-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-min-aggregation.html
* @see MinAggregationTest
- *
- * @options 'missing' => 0,
*/
+#[Options([
+ 'missing' => 0,
+])]
class MinAggregation extends AbstractNumericMetricAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Metric/PercentileRanksAggregation.php b/src/Aggregation/Metric/PercentileRanksAggregation.php
index 32d8e03..0a87b23 100644
--- a/src/Aggregation/Metric/PercentileRanksAggregation.php
+++ b/src/Aggregation/Metric/PercentileRanksAggregation.php
@@ -5,77 +5,83 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-percentile-rank-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-percentile-rank-aggregation.html
* @see PercentileRanksAggregationTest
- *
- * @options 'keyed' => true,
- * 'hdr' => ['number_of_significant_value_digits' => 3],
- * 'missing' => 10,
*/
+#[Options([
+ 'keyed' => true,
+ 'hdr' => ['number_of_significant_value_digits' => 3],
+ 'missing' => 10,
+])]
class PercentileRanksAggregation implements MetricAggregationInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ /** @var float[]|int[] */
+ protected array $values,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
+ $this->options = $options;
+ }
- protected function __construct(array $body, array $options = [])
+ public function __clone()
{
- $this->body = $body;
- $this->options = $options;
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
}
/**
- * @param string $field
- * @param float[] $values
- * @param array $options
- * @param InlineScript|null $valueScript
- *
- * @return PercentileRanksAggregation
+ * @param float[]|int[] $values
+ * @param array $options
*/
public static function fromField(
string $field,
array $values,
array $options = [],
- InlineScript $valueScript = null
- ): PercentileRanksAggregation {
- $body = [];
- $body['values'] = $values;
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $options);
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $values, $options);
}
/**
- * @param float[] $values
- * @param ScriptInterface $script
- * @param array $options
- *
- * @return PercentileRanksAggregation
+ * @param float[]|int[] $values
+ * @param array $options
*/
public static function fromScript(
array $values,
ScriptInterface $script,
- array $options = []
- ): PercentileRanksAggregation {
- $body = [];
- $body['values'] = $values;
- $body['script'] = $script->jsonSerialize();
-
- return new static($body, $options);
+ array $options = [],
+ ): static {
+ return new static(null, $script, $values, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = $this->body;
+ $body = [];
+ $body['values'] = $this->values;
+ if (null !== $this->field) {
+ $body['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $body['script'] = $this->script->jsonSerialize();
+ }
$body += $this->options;
return [
diff --git a/src/Aggregation/Metric/PercentilesAggregation.php b/src/Aggregation/Metric/PercentilesAggregation.php
index e67afe3..671c972 100644
--- a/src/Aggregation/Metric/PercentilesAggregation.php
+++ b/src/Aggregation/Metric/PercentilesAggregation.php
@@ -5,58 +5,76 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-percentile-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-percentile-aggregation.html
* @see PercentilesAggregationTest
- *
- * @options 'keyed' => true,
- * 'percents' => [95, 99, 99.9],
- * 'tdigest' => ['compression' => 200],
- * 'hdr' => ['number_of_significant_value_digits' => 3],
- * 'missing' => 10,
*/
+#[Options([
+ 'keyed' => true,
+ 'percents' => [95, 99, 99.9],
+ 'tdigest' => ['compression' => 200],
+ 'hdr' => ['number_of_significant_value_digits' => 3],
+ 'missing' => 10,
+])]
class PercentilesAggregation implements MetricAggregationInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ array $options = [],
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
+ $this->options = $options;
+ }
- protected function __construct(array $body, array $options = [])
+ public function __clone()
{
- $this->body = $body;
- $this->options = $options;
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
}
+ /**
+ * @param array $options
+ */
public static function fromField(
string $field,
array $options = [],
- InlineScript $valueScript = null
- ): PercentilesAggregation {
- $body = [];
- $body['field'] = $field;
- if (null !== $valueScript) {
- $body['script'] = $valueScript->jsonSerialize();
- }
-
- return new static($body, $options);
+ ?InlineScript $valueScript = null,
+ ): static {
+ return new static($field, $valueScript, $options);
}
- public static function fromScript(ScriptInterface $script, array $options = []): PercentilesAggregation
+ /**
+ * @param array $options
+ */
+ public static function fromScript(ScriptInterface $script, array $options = []): static
{
- $body = [];
- $body['script'] = $script->jsonSerialize();
-
- return new static($body, $options);
+ return new static(null, $script, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = $this->body;
+ $body = [];
+ if (null !== $this->field) {
+ $body['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $body['script'] = $this->script;
+ }
$body += $this->options;
return [
diff --git a/src/Aggregation/Metric/ScriptedMetricAggregation.php b/src/Aggregation/Metric/ScriptedMetricAggregation.php
index 368fe58..2934ce0 100644
--- a/src/Aggregation/Metric/ScriptedMetricAggregation.php
+++ b/src/Aggregation/Metric/ScriptedMetricAggregation.php
@@ -6,25 +6,20 @@
use UnexpectedValueException;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-scripted-metric-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-scripted-metric-aggregation.html
* @see ScriptedMetricAggregationTest
*/
class ScriptedMetricAggregation implements MetricAggregationInterface
{
- /** @var ScriptInterface|null */
- protected $initScript;
-
- /** @var ScriptInterface|null */
- protected $mapScript;
-
- /** @var ScriptInterface|null */
- protected $combineScript;
-
- /** @var ScriptInterface|null */
- protected $reduceScript;
-
- /** @var array */
- protected $params = [];
+ public function __construct(
+ protected ?ScriptInterface $initScript = null,
+ protected ?ScriptInterface $mapScript = null,
+ protected ?ScriptInterface $combineScript = null,
+ protected ?ScriptInterface $reduceScript = null,
+ /** @var array */
+ protected array $params = [],
+ ) {
+ }
public function __clone()
{
@@ -34,142 +29,88 @@ public function __clone()
$this->reduceScript = $this->reduceScript ? clone $this->reduceScript : null;
}
- /**
- * @return ScriptInterface|null
- */
- public function getInitScript()
+ public function getInitScript(): ?ScriptInterface
{
return $this->initScript;
}
- /**
- * @param ScriptInterface|null $initScript
- *
- * @return $this
- */
- public function setInitScript(ScriptInterface $initScript = null): ScriptedMetricAggregation
+ public function setInitScript(?ScriptInterface $initScript): static
{
$this->initScript = $initScript;
-
return $this;
}
- /**
- * @return ScriptInterface|null
- */
- public function getMapScript()
+ public function getMapScript(): ?ScriptInterface
{
return $this->mapScript;
}
- /**
- * @param ScriptInterface|null $mapScript
- *
- * @return $this
- */
- public function setMapScript(ScriptInterface $mapScript = null): ScriptedMetricAggregation
+ public function setMapScript(?ScriptInterface $mapScript): static
{
$this->mapScript = $mapScript;
-
return $this;
}
- /**
- * @return ScriptInterface|null
- */
- public function getCombineScript()
+ public function getCombineScript(): ?ScriptInterface
{
return $this->combineScript;
}
- /**
- * @param ScriptInterface|null $combineScript
- *
- * @return $this
- */
- public function setCombineScript(ScriptInterface $combineScript = null): ScriptedMetricAggregation
+ public function setCombineScript(?ScriptInterface $combineScript): static
{
$this->combineScript = $combineScript;
-
return $this;
}
- /**
- * @return ScriptInterface|null
- */
- public function getReduceScript()
+ public function getReduceScript(): ?ScriptInterface
{
return $this->reduceScript;
}
- /**
- * @param ScriptInterface|null $reduceScript
- *
- * @return $this
- */
- public function setReduceScript(ScriptInterface $reduceScript = null): ScriptedMetricAggregation
+ public function setReduceScript(?ScriptInterface $reduceScript): static
{
$this->reduceScript = $reduceScript;
-
return $this;
}
+ /**
+ * @return array
+ */
public function getParams(): array
{
return $this->params;
}
- /**
- * @param string $name
- *
- * @return mixed|null
- */
- public function getParam(string $name)
+ public function getParam(string $name): mixed
{
return $this->params[$name] ?? null;
}
/**
- * @param array $paramsByName
- *
- * @return $this
+ * @param array $paramsByName
*/
- public function setParams(array $paramsByName): ScriptedMetricAggregation
+ public function setParams(array $paramsByName): static
{
$this->params = $paramsByName;
-
return $this;
}
- /**
- * @param string $name
- * @param mixed $value
- *
- * @return $this
- */
- public function setParam(string $name, $value): ScriptedMetricAggregation
+ public function setParam(string $name, mixed $value): static
{
$this->params[$name] = $value;
-
return $this;
}
- /**
- * @param string $name
- *
- * @return $this
- */
- public function removeParam(string $name): ScriptedMetricAggregation
+ public function removeParam(string $name): static
{
unset($this->params[$name]);
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (null === $this->mapScript) {
throw new UnexpectedValueException('Map script is required');
diff --git a/src/Aggregation/Metric/StatsAggregation.php b/src/Aggregation/Metric/StatsAggregation.php
index 1a24327..e69e349 100644
--- a/src/Aggregation/Metric/StatsAggregation.php
+++ b/src/Aggregation/Metric/StatsAggregation.php
@@ -2,16 +2,19 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-stats-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-stats-aggregation.html
* @see StatsAggregationTest
- *
- * @options 'missing' => 0,
*/
+#[Options([
+ 'missing' => 0,
+])]
class StatsAggregation extends AbstractNumericMetricAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Metric/SumAggregation.php b/src/Aggregation/Metric/SumAggregation.php
index d7769b6..52a48a2 100644
--- a/src/Aggregation/Metric/SumAggregation.php
+++ b/src/Aggregation/Metric/SumAggregation.php
@@ -2,16 +2,19 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-sum-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-sum-aggregation.html
* @see SumAggregationTest
- *
- * @options 'missing' => 0,
*/
+#[Options([
+ 'missing' => 0,
+])]
class SumAggregation extends AbstractNumericMetricAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Metric/TopHitsAggregation.php b/src/Aggregation/Metric/TopHitsAggregation.php
index a5e957e..1996ca3 100644
--- a/src/Aggregation/Metric/TopHitsAggregation.php
+++ b/src/Aggregation/Metric/TopHitsAggregation.php
@@ -6,17 +6,14 @@
use stdClass;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-top-hits-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-top-hits-aggregation.html
* @see TopHitsAggregationTest
*/
class TopHitsAggregation implements MetricAggregationInterface
{
- /** @var TopHitsRequest|null */
- protected $request;
-
- public function __construct(TopHitsRequest $request = null)
- {
- $this->request = $request;
+ public function __construct(
+ protected ?TopHitsRequest $request = null,
+ ) {
}
public function __clone()
@@ -25,9 +22,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (null !== $this->request) {
$body = $this->request->jsonSerialize();
diff --git a/src/Aggregation/Metric/ValueCountAggregation.php b/src/Aggregation/Metric/ValueCountAggregation.php
index 840c264..ca81177 100644
--- a/src/Aggregation/Metric/ValueCountAggregation.php
+++ b/src/Aggregation/Metric/ValueCountAggregation.php
@@ -3,38 +3,55 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use InvalidArgumentException;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-metrics-valuecount-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics-valuecount-aggregation.html
* @see ValueCountAggregationTest
*/
class ValueCountAggregation implements MetricAggregationInterface
{
- /** @var array */
- protected $body;
+ protected function __construct(
+ protected ?string $field,
+ protected ?ScriptInterface $script,
+ ) {
+ if (null === $field && null === $script) {
+ throw new InvalidArgumentException('Expected at least one to be not null: field or script.');
+ }
+ }
- protected function __construct(array $body)
+ public function __clone()
{
- $this->body = $body;
+ if (null !== $this->script) {
+ $this->script = clone $this->script;
+ }
}
- public static function fromField(string $field): ValueCountAggregation
+ public static function fromField(string $field): static
{
- return new static(['field' => $field]);
+ return new static($field, null);
}
- public static function fromScript(ScriptInterface $script): ValueCountAggregation
+ public static function fromScript(ScriptInterface $script): static
{
- return new static(['script' => $script->jsonSerialize()]);
+ return new static(null, $script);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
+ $body = [];
+ if (null !== $this->field) {
+ $body['field'] = $this->field;
+ }
+ if (null !== $this->script) {
+ $body['script'] = $this->script;
+ }
+
return [
- 'value_count' => $this->body,
+ 'value_count' => $body,
];
}
}
diff --git a/src/Aggregation/Metric/WeightedAvgAggregation.php b/src/Aggregation/Metric/WeightedAvgAggregation.php
new file mode 100644
index 0000000..428e61c
--- /dev/null
+++ b/src/Aggregation/Metric/WeightedAvgAggregation.php
@@ -0,0 +1,69 @@
+ '?',
+ 'value_type' => '?'
+])]
+class WeightedAvgAggregation implements MetricAggregationInterface
+{
+ use HasOptionsTrait;
+
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string|ScriptInterface $valueFieldOrScript,
+ protected string|ScriptInterface $weightFieldOrScript,
+ protected mixed $missingValue = null,
+ protected mixed $missingWeight = null,
+ array $options = [],
+ ) {
+ $this->options = $options;
+ }
+
+ public function __clone()
+ {
+ if (is_object($this->valueFieldOrScript)) {
+ $this->valueFieldOrScript = clone $this->valueFieldOrScript;
+ }
+ if (is_object($this->weightFieldOrScript)) {
+ $this->weightFieldOrScript = clone $this->weightFieldOrScript;
+ }
+ }
+
+ public function jsonSerialize(): mixed
+ {
+ $body = $this->options;
+
+ if ($this->valueFieldOrScript instanceof ScriptInterface) {
+ $body['value']['script'] = $this->valueFieldOrScript->jsonSerialize();
+ } else {
+ $body['value']['field'] = $this->valueFieldOrScript;
+ }
+
+ if ($this->weightFieldOrScript instanceof ScriptInterface) {
+ $body['weight']['script'] = $this->weightFieldOrScript->jsonSerialize();
+ } else {
+ $body['weight']['field'] = $this->weightFieldOrScript;
+ }
+
+ if (null !== $this->missingValue) {
+ $body['value']['missing'] = $this->missingValue;
+ }
+ if (null !== $this->missingWeight) {
+ $body['weight']['missing'] = $this->missingWeight;
+ }
+
+ return ['weighted_avg' => $body];
+ }
+}
diff --git a/src/Aggregation/Pipeline/AbstractNumericPipelineAggregation.php b/src/Aggregation/Pipeline/AbstractNumericPipelineAggregation.php
index dbe3b81..6e34ef1 100644
--- a/src/Aggregation/Pipeline/AbstractNumericPipelineAggregation.php
+++ b/src/Aggregation/Pipeline/AbstractNumericPipelineAggregation.php
@@ -8,19 +8,20 @@ abstract class AbstractNumericPipelineAggregation implements PipelineAggregation
{
use HasOptionsTrait;
- /** @var string */
- protected $bucketsPath;
-
- public function __construct(string $bucketsPath, array $options = [])
- {
- $this->bucketsPath = $bucketsPath;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $bucketsPath,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['buckets_path'] = $this->bucketsPath;
@@ -31,5 +32,8 @@ public function jsonSerialize()
];
}
+ /**
+ * @return string 'avg', 'cumulative_sum', 'derivative', ...
+ */
abstract protected function getType(): string;
}
diff --git a/src/Aggregation/Pipeline/Parent/BucketScriptAggregation.php b/src/Aggregation/Pipeline/Parent/BucketScriptAggregation.php
index 14c702b..463c943 100644
--- a/src/Aggregation/Pipeline/Parent/BucketScriptAggregation.php
+++ b/src/Aggregation/Pipeline/Parent/BucketScriptAggregation.php
@@ -5,33 +5,29 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\PipelineAggregationInterface;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-bucket-script-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-bucket-script-aggregation.html
* @see BucketScriptAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class BucketScriptAggregation implements PipelineAggregationInterface
{
use HasOptionsTrait;
- /** @var string[] */
- protected $bucketsPath;
-
- /** @var ScriptInterface */
- protected $script;
-
/**
- * @param string[] $bucketsPathByVar
- * @param ScriptInterface $script
- * @param array $options
+ * @param array $options
*/
- public function __construct(array $bucketsPathByVar, ScriptInterface $script, array $options = [])
- {
- $this->bucketsPath = $bucketsPathByVar;
- $this->script = $script;
+ public function __construct(
+ /** @var array */
+ protected array $bucketsPath,
+ protected ScriptInterface $script,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -41,9 +37,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'buckets_path' => $this->bucketsPath,
diff --git a/src/Aggregation/Pipeline/Parent/BucketSelectorAggregation.php b/src/Aggregation/Pipeline/Parent/BucketSelectorAggregation.php
index 1f4187b..11913f1 100644
--- a/src/Aggregation/Pipeline/Parent/BucketSelectorAggregation.php
+++ b/src/Aggregation/Pipeline/Parent/BucketSelectorAggregation.php
@@ -5,32 +5,28 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\PipelineAggregationInterface;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-bucket-selector-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-bucket-selector-aggregation.html
* @see BucketSelectorAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
*/
+#[Options([
+ 'gap_policy' => 'skip',// 'insert_zeros',
+])]
class BucketSelectorAggregation implements PipelineAggregationInterface
{
use HasOptionsTrait;
- /** @var string[] */
- protected $bucketsPath;
-
- /** @var ScriptInterface */
- protected $script;
-
/**
- * @param string[] $bucketsPathByVar
- * @param ScriptInterface $script
- * @param array $options
+ * @param array $options
*/
- public function __construct(array $bucketsPathByVar, ScriptInterface $script, array $options = [])
- {
- $this->bucketsPath = $bucketsPathByVar;
- $this->script = $script;
+ public function __construct(
+ /** @var array */
+ protected array $bucketsPath,
+ protected ScriptInterface $script,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -40,9 +36,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'buckets_path' => $this->bucketsPath,
diff --git a/src/Aggregation/Pipeline/Parent/BucketSortAggregation.php b/src/Aggregation/Pipeline/Parent/BucketSortAggregation.php
new file mode 100644
index 0000000..3f7df5b
--- /dev/null
+++ b/src/Aggregation/Pipeline/Parent/BucketSortAggregation.php
@@ -0,0 +1,68 @@
+ 'skip', // 'insert_zeros',
+ 'size' => 1,
+ 'from' => 3,
+])]
+class BucketSortAggregation implements PipelineAggregationInterface
+{
+ use HasSortersTrait;
+ use HasOptionsTrait;
+
+ /**
+ * @param SorterInterface[]|SorterInterface $sorters
+ * @param array $options
+ */
+ public function __construct(
+ array|SorterInterface $sorters = [],
+ protected ?int $from = null,
+ protected ?int $size = null,
+ array $options = [],
+ ) {
+ if (!empty($sorters)) {
+ $this->sorters = is_array($sorters) ? $sorters : [$sorters];
+ }
+ $this->options = $options;
+ }
+
+ public function __clone()
+ {
+ $this->sorters = array_clone($this->sorters);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function jsonSerialize(): mixed
+ {
+ $body = $this->options;
+ if (!empty($this->sorters)) {
+ $body['sort'] = $this->jsonSerializeSorters();
+ }
+ if (null !== $this->from) {
+ $body['from'] = $this->from;
+ }
+ if (null !== $this->size) {
+ $body['size'] = $this->size;
+ }
+
+ return [
+ 'bucket_sort' => $body,
+ ];
+ }
+}
diff --git a/src/Aggregation/Pipeline/Parent/CumulativeSumBucketAggregation.php b/src/Aggregation/Pipeline/Parent/CumulativeSumBucketAggregation.php
index 04ae8e4..3927759 100644
--- a/src/Aggregation/Pipeline/Parent/CumulativeSumBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Parent/CumulativeSumBucketAggregation.php
@@ -3,17 +3,19 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Parent;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-cumulative-sum-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-cumulative-sum-aggregation.html
* @see CumulativeSumBucketAggregationTest
- *
- * @options 'format' => ?,
*/
+#[Options([
+ 'format' => '?',
+])]
class CumulativeSumBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Parent/DerivativeAggregation.php b/src/Aggregation/Pipeline/Parent/DerivativeAggregation.php
index 1bf7be3..d0b0e67 100644
--- a/src/Aggregation/Pipeline/Parent/DerivativeAggregation.php
+++ b/src/Aggregation/Pipeline/Parent/DerivativeAggregation.php
@@ -3,19 +3,21 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Parent;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-derivative-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-derivative-aggregation.html
* @see DerivativeAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
- * 'unit' => 'day',
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+ 'unit' => 'day',
+])]
class DerivativeAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/PipelineAggregationInterface.php b/src/Aggregation/Pipeline/PipelineAggregationInterface.php
index d5c1c78..379bd1d 100644
--- a/src/Aggregation/Pipeline/PipelineAggregationInterface.php
+++ b/src/Aggregation/Pipeline/PipelineAggregationInterface.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\AggregationInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline.html
*/
interface PipelineAggregationInterface extends AggregationInterface
{
diff --git a/src/Aggregation/Pipeline/Sibling/AvgBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/AvgBucketAggregation.php
index b370d06..a96cdc0 100644
--- a/src/Aggregation/Pipeline/Sibling/AvgBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/AvgBucketAggregation.php
@@ -3,18 +3,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-avg-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-avg-bucket-aggregation.html
* @see AvgBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class AvgBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregation.php
index 7ddcb98..3fc5188 100644
--- a/src/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregation.php
@@ -3,19 +3,21 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-extended-stats-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-extended-stats-bucket-aggregation.html
* @see ExtendedStatsBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros'
- * 'format' => ?,
- * 'sigma' => 3,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros'
+ 'format' => '?',
+ 'sigma' => 3,
+])]
class ExtendedStatsBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/MaxBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/MaxBucketAggregation.php
index b2be150..7c68ab7 100644
--- a/src/Aggregation/Pipeline/Sibling/MaxBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/MaxBucketAggregation.php
@@ -3,18 +3,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-max-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-max-bucket-aggregation.html
* @see MaxBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class MaxBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/MinBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/MinBucketAggregation.php
index e0daffc..56c57d2 100644
--- a/src/Aggregation/Pipeline/Sibling/MinBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/MinBucketAggregation.php
@@ -3,18 +3,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-min-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-min-bucket-aggregation.html
* @see MinBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class MinBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/MovingAvgAggregation.php b/src/Aggregation/Pipeline/Sibling/MovingAvgAggregation.php
index 4bf482a..1b0c431 100644
--- a/src/Aggregation/Pipeline/Sibling/MovingAvgAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/MovingAvgAggregation.php
@@ -3,23 +3,24 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-movavg-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-movavg-aggregation.html
* @see MovingAvgAggregationTest
- *
- * @options 'model' => 'simple', 'linear', 'ewma', 'holt', 'holt_winters',
- * 'gap_policy' => 'skip', 'insert_zeros',
- * 'window' => 5,
- * 'minimize' => false,
- * 'settings' => ['alpha' => 0.5, 'beta' => 0.1, 'gamma' => 0.3, 'period' => 7, 'type' => 'add', 'pad' => false],
- * 'predict' => 10,
- * 'minimize' => true,
*/
+#[Options([
+ 'model' => 'simple', // 'linear', 'ewma', 'holt', 'holt_winters',
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'window' => 5,
+ 'minimize' => false,
+ 'settings' => ['alpha' => 0.5, 'beta' => 0.1, 'gamma' => 0.3, 'period' => 7, 'type' => 'add', 'pad' => false],
+ 'predict' => 10,
+])]
class MovingAvgAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/MovingFunctionAggregation.php b/src/Aggregation/Pipeline/Sibling/MovingFunctionAggregation.php
new file mode 100644
index 0000000..7223a97
--- /dev/null
+++ b/src/Aggregation/Pipeline/Sibling/MovingFunctionAggregation.php
@@ -0,0 +1,39 @@
+script = clone $this->script;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function jsonSerialize(): mixed
+ {
+ return [
+ 'moving_fn' => [
+ 'buckets_path' => $this->bucketsPath,
+ 'window' => $this->window,
+ 'script' => $this->script->jsonSerialize(),
+ ],
+ ];
+ }
+}
diff --git a/src/Aggregation/Pipeline/Sibling/PercentilesBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/PercentilesBucketAggregation.php
index 9a48d42..1d3f523 100644
--- a/src/Aggregation/Pipeline/Sibling/PercentilesBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/PercentilesBucketAggregation.php
@@ -3,19 +3,21 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-percentiles-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-percentiles-bucket-aggregation.html
* @see PercentilesBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
- * 'percents' => [1, 5, 25, 50, 75, 95, 99],
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+ 'percents' => [1, 5, 25, 50, 75, 95, 99],
+])]
class PercentilesBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/SerialDifferencingBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/SerialDifferencingBucketAggregation.php
index 3566513..e1ede8f 100644
--- a/src/Aggregation/Pipeline/Sibling/SerialDifferencingBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/SerialDifferencingBucketAggregation.php
@@ -4,32 +4,35 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\PipelineAggregationInterface;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-bucket-selector-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-serialdiff-aggregation.html
* @see SerialDifferencingBucketAggregationTest
- *
- * @options 'lag' => 1,
- * 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'lag' => 1,
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class SerialDifferencingBucketAggregation implements PipelineAggregationInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $bucketsPath;
-
- public function __construct(string $bucketsPath, array $options = [])
- {
- $this->bucketsPath = $bucketsPath;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $bucketsPath,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['buckets_path'] = $this->bucketsPath;
diff --git a/src/Aggregation/Pipeline/Sibling/StatsBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/StatsBucketAggregation.php
index 57ef2fc..9d2582d 100644
--- a/src/Aggregation/Pipeline/Sibling/StatsBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/StatsBucketAggregation.php
@@ -3,18 +3,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-stats-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-stats-bucket-aggregation.html
* @see StatsBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class StatsBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/Pipeline/Sibling/SumBucketAggregation.php b/src/Aggregation/Pipeline/Sibling/SumBucketAggregation.php
index eb859f8..55489c4 100644
--- a/src/Aggregation/Pipeline/Sibling/SumBucketAggregation.php
+++ b/src/Aggregation/Pipeline/Sibling/SumBucketAggregation.php
@@ -3,18 +3,20 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
use Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\AbstractNumericPipelineAggregation;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline-sum-bucket-aggregation.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-pipeline-sum-bucket-aggregation.html
* @see SumBucketAggregationTest
- *
- * @options 'gap_policy' => 'skip', 'insert_zeros',
- * 'format' => ?,
*/
+#[Options([
+ 'gap_policy' => 'skip', // 'insert_zeros',
+ 'format' => '?',
+])]
class SumBucketAggregation extends AbstractNumericPipelineAggregation
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getType(): string
{
diff --git a/src/Aggregation/RawAggregation.php b/src/Aggregation/RawAggregation.php
index 0f280e5..59642dc 100644
--- a/src/Aggregation/RawAggregation.php
+++ b/src/Aggregation/RawAggregation.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations.html
* @see RawAggregationTest
*/
class RawAggregation extends RawFragment implements AggregationInterface
diff --git a/src/FieldCollapser/FieldCollapser.php b/src/FieldCollapser/FieldCollapser.php
index fd7aadb..3dada34 100644
--- a/src/FieldCollapser/FieldCollapser.php
+++ b/src/FieldCollapser/FieldCollapser.php
@@ -2,29 +2,28 @@
namespace Gskema\ElasticSearchQueryDSL\FieldCollapser;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-collapse.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html
* @see FieldCollapserTest
- *
- * @options 'max_concurrent_group_searches' => 4,
*/
+#[Options([
+ 'max_concurrent_group_searches' => 4,
+])]
class FieldCollapser implements FieldCollapserInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var InnerHitsRequest[] */
- protected $innerHits = [];
-
- public function __construct(string $field)
- {
- $this->field = $field;
+ public function __construct(
+ protected string $field,
+ /** @var InnerHitsRequest[] */
+ protected array $innerHits = [],
+ ) {
}
public function __clone()
@@ -47,32 +46,23 @@ public function getInnerHits(): array
/**
* @param InnerHitsRequest[] $requests
- *
- * @return $this
*/
- public function setInnerHits(array $requests): FieldCollapser
+ public function setInnerHits(array $requests): static
{
$this->innerHits = $requests;
-
return $this;
}
- /**
- * @param InnerHitsRequest $request
- *
- * @return $this
- */
- public function addInnerHits(InnerHitsRequest $request): FieldCollapser
+ public function addInnerHits(InnerHitsRequest $request): static
{
$this->innerHits[] = $request;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['field'] = $this->field;
diff --git a/src/FieldCollapser/FieldCollapserInterface.php b/src/FieldCollapser/FieldCollapserInterface.php
index 4d3d7bc..238c183 100644
--- a/src/FieldCollapser/FieldCollapserInterface.php
+++ b/src/FieldCollapser/FieldCollapserInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-collapse.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html
*/
interface FieldCollapserInterface extends JsonSerializable
{
diff --git a/src/FieldCollapser/RawFieldCollapser.php b/src/FieldCollapser/RawFieldCollapser.php
index 3e5c582..6e52666 100644
--- a/src/FieldCollapser/RawFieldCollapser.php
+++ b/src/FieldCollapser/RawFieldCollapser.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-collapse.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html
* @see RawFieldCollapserTest
*/
class RawFieldCollapser extends RawFragment implements FieldCollapserInterface
diff --git a/src/HasAggsTrait.php b/src/HasAggsTrait.php
index 1883019..a69efe5 100644
--- a/src/HasAggsTrait.php
+++ b/src/HasAggsTrait.php
@@ -5,76 +5,51 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\AggregationInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations.html
* @see HasAggsTraitTest
*/
trait HasAggsTrait
{
- /** @var AggregationInterface[] */
- protected $aggs = [];
+ /** @var array */
+ protected array $aggs = [];
/**
- * @return AggregationInterface[]
+ * @inheritDoc
*/
public function getAggs(): array
{
return $this->aggs;
}
- /**
- * @param string $key
- *
- * @return AggregationInterface|null
- */
- public function getAgg(string $key)
+ public function getAgg(string $key): ?AggregationInterface
{
return $this->aggs[$key] ?? null;
}
/**
- * @param AggregationInterface[] $aggsByKey
- *
- * @return $this
+ * @inheritDoc
*/
- public function setAggs(array $aggsByKey)
+ public function setAggs(array $keyAggMap): static
{
- $this->aggs = $aggsByKey;
-
+ $this->aggs = $keyAggMap;
return $this;
}
- /**
- * @param string $key
- * @param AggregationInterface $agg
- *
- * @return $this
- */
- public function setAgg(string $key, AggregationInterface $agg)
+ public function setAgg(string $key, AggregationInterface $agg): static
{
$this->aggs[$key] = $agg;
-
return $this;
}
- /**
- * @return $this
- */
- public function removeAggs()
+ public function removeAggs(): static
{
$this->aggs = [];
-
return $this;
}
- /**
- * @param string $key
- *
- * @return $this
- */
- public function removeAgg(string $key)
+ public function removeAgg(string $key): static
{
unset($this->aggs[$key]);
-
return $this;
}
@@ -87,11 +62,4 @@ public function hasAgg(string $key): bool
{
return key_exists($key, $this->aggs);
}
-
- protected function jsonSerializeAggs(): array
- {
- return array_map(function (AggregationInterface $agg) {
- return $agg->jsonSerialize();
- }, $this->aggs);
- }
}
diff --git a/src/HasOptionsTrait.php b/src/HasOptionsTrait.php
index 06ced9a..fcdfe57 100644
--- a/src/HasOptionsTrait.php
+++ b/src/HasOptionsTrait.php
@@ -7,68 +7,46 @@
*/
trait HasOptionsTrait
{
- /** @var array */
- protected $options = [];
+ /** @var array */
+ protected array $options = [];
+ /**
+ * @return array
+ */
public function getOptions(): array
{
return $this->options;
}
- /**
- * @param string $key
- *
- * @return mixed|null
- */
- public function getOption(string $key)
+ public function getOption(string $key): mixed
{
return $this->options[$key] ?? null;
}
/**
- * @param array $optionsByKey
- *
- * @return $this
+ * @param array $optionsByKey
*/
- public function setOptions(array $optionsByKey)
+ public function setOptions(array $optionsByKey): static
{
$this->options = $optionsByKey;
-
return $this;
}
- /**
- * @param string $key
- * @param mixed $value
- *
- * @return $this
- */
- public function setOption(string $key, $value)
+ public function setOption(string $key, mixed $value): static
{
$this->options[$key] = $value;
-
return $this;
}
- /**
- * @return $this
- */
- public function removeOptions()
+ public function removeOptions(): static
{
$this->options = [];
-
return $this;
}
- /**
- * @param string $key
- *
- * @return $this
- */
- public function removeOption(string $key)
+ public function removeOption(string $key): static
{
unset($this->options[$key]);
-
return $this;
}
diff --git a/src/HasParametersTrait.php b/src/HasParametersTrait.php
index 3e75586..e501c8a 100644
--- a/src/HasParametersTrait.php
+++ b/src/HasParametersTrait.php
@@ -7,68 +7,46 @@
*/
trait HasParametersTrait
{
- /** @var array */
- protected $parameters = [];
+ /** @var array */
+ protected array $parameters = [];
+ /**
+ * @return array
+ */
public function getParameters(): array
{
return $this->parameters;
}
- /**
- * @param string $key
- *
- * @return mixed|null
- */
- public function getParameter(string $key)
+ public function getParameter(string $key): mixed
{
return $this->parameters[$key] ?? null;
}
/**
- * @param array $parameters
- *
- * @return $this
+ * @param array $parameters
*/
- public function setParameters(array $parameters)
+ public function setParameters(array $parameters): static
{
$this->parameters = $parameters;
-
return $this;
}
- /**
- * @param string $key
- * @param mixed $value
- *
- * @return $this
- */
- public function setParameter(string $key, $value)
+ public function setParameter(string $key, mixed $value): static
{
$this->parameters[$key] = $value;
-
return $this;
}
- /**
- * @return $this
- */
- public function removeParameters()
+ public function removeParameters(): static
{
$this->parameters = [];
-
return $this;
}
- /**
- * @param string $key
- *
- * @return $this
- */
- public function removeParameter(string $key)
+ public function removeParameter(string $key): static
{
unset($this->parameters[$key]);
-
return $this;
}
diff --git a/src/Highlighter/Highlighter.php b/src/Highlighter/Highlighter.php
index ceb42c5..c5d9cf3 100644
--- a/src/Highlighter/Highlighter.php
+++ b/src/Highlighter/Highlighter.php
@@ -2,48 +2,53 @@
namespace Gskema\ElasticSearchQueryDSL\Highlighter;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+
/**
* Options can be global or on overridden on field level.
*
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-highlighting.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html
* @see HighlighterTest
- *
- * @options 'type' => 'plain', 'fvh', 'postings',
- * 'force_source' => true,
- * 'pre_tags' => ['', ''],
- * 'post_tags' => ['', ''],
- * 'tags_schema' => 'styled',
- * 'encoder' => 'default', 'html',
- * 'order' => score,
- * 'fragment_size' => 150,
- * 'number_of_fragments' => 3,
- * 'fragment_offset' => 10,
- * 'no_match_size' => 150,
- * 'fragmenter' => 'simple', 'span',
- * 'highlight_query' => MatcherInterface,
- * 'require_field_match' => false,
- * 'boundary_scanner' => 'chars', 'sentence', 'word',
- * 'boundary_chars' => '.,!? \\t\\n',
- * 'boundary_max_scan' => 20,
- * 'boundary_scanner_locale' => '?',
- * 'max_fragment_length' => 20,
- * 'matched_fields' => ['content', 'content.plain'],
- * 'phrase_limit' => 256,
*/
+#[Options([
+ 'boundary_chars' => '.,!? \\t\\n',
+ 'boundary_max_scan' => 20,
+ 'boundary_scanner' => 'chars', // 'sentence', 'word',
+ 'boundary_scanner_locale' => '?',
+ 'encoder' => 'default', // 'html',
+ 'force_source' => true,
+ 'fragmenter' => 'simple', // 'span',
+ 'fragment_offset' => 10,
+ 'fragment_size' => 150,
+ 'highlight_query' => MatcherInterface::class,
+ 'matched_fields' => ['content', 'content.plain'],
+ 'no_match_size' => 150,
+ 'number_of_fragments' => 3,
+ 'order' => 'score',
+ 'phrase_limit' => 256,
+ 'pre_tags' => ['', ''],
+ 'post_tags' => ['', ''],
+ 'require_field_match' => false,
+ 'tags_schema' => 'styled',
+ 'type' => 'plain', // 'fvh', 'unified',
+])]
class Highlighter implements HighlighterInterface
{
use HasOptionsTrait;
- /** @var array[] */
- protected $optionsByField = [];
-
- public function __construct(array $options = [])
- {
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ /** @var array */
+ protected array $optionsByField = [],
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -54,22 +59,19 @@ public function __clone()
}
/**
- * @param string $field
- * @param array $options
- *
- * @return $this
+ * @param array $options
*/
- public function setField(string $field, array $options = []): Highlighter
+ public function setField(string $field, array $options = []): static
{
$this->optionsByField[$field] = $options;
-
return $this;
}
+
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = $this->options;
$query = $body['highlight_query'] ?? null;
diff --git a/src/Highlighter/HighlighterInterface.php b/src/Highlighter/HighlighterInterface.php
index 6f93d4b..5fdaf9d 100644
--- a/src/Highlighter/HighlighterInterface.php
+++ b/src/Highlighter/HighlighterInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-highlighting.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html
*/
interface HighlighterInterface extends JsonSerializable
{
diff --git a/src/Matcher/Compound/BoolMatcher.php b/src/Matcher/Compound/BoolMatcher.php
index af8ddd9..88d4040 100644
--- a/src/Matcher/Compound/BoolMatcher.php
+++ b/src/Matcher/Compound/BoolMatcher.php
@@ -2,36 +2,38 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-bool-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-bool-query.html
* @see BoolMatcherTest
- *
- * @options 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ '_name' => '?',
+])]
class BoolMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var MatcherInterface[] */
- protected $filters = [];
-
- /** @var MatcherInterface[] */
- protected $musts = [];
-
- /** @var MatcherInterface[] */
- protected $mustNots = [];
-
- /** @var MatcherInterface[] */
- protected $shoulds = [];
-
- /** @var string|int|null */
- protected $minimumShouldMatch;
+ public function __construct(
+ /** @var MatcherInterface[] */
+ protected array $filters = [],
+ /** @var MatcherInterface[] */
+ protected array $musts = [],
+ /** @var MatcherInterface[] */
+ protected array $mustNots = [],
+ /** @var MatcherInterface[] */
+ protected array $shoulds = [],
+ protected string|int|null $minimumShouldMatch = null,
+ ) {
+ }
public function __clone()
{
@@ -51,25 +53,16 @@ public function getFilters(): array
/**
* @param MatcherInterface[] $filters
- *
- * @return $this
*/
- public function setFilters(array $filters): BoolMatcher
+ public function setFilters(array $filters): static
{
$this->filters = $filters;
-
return $this;
}
- /**
- * @param MatcherInterface $filter
- *
- * @return $this
- */
- public function addFilter(MatcherInterface $filter): BoolMatcher
+ public function addFilter(MatcherInterface $filter): static
{
$this->filters[] = $filter;
-
return $this;
}
@@ -83,25 +76,16 @@ public function getMusts(): array
/**
* @param MatcherInterface[] $matchers
- *
- * @return $this
*/
- public function setMusts(array $matchers): BoolMatcher
+ public function setMusts(array $matchers): static
{
$this->musts = $matchers;
-
return $this;
}
- /**
- * @param MatcherInterface $matcher
- *
- * @return $this
- */
- public function addMust(MatcherInterface $matcher): BoolMatcher
+ public function addMust(MatcherInterface $matcher): static
{
$this->musts[] = $matcher;
-
return $this;
}
@@ -115,25 +99,16 @@ public function getMustNots(): array
/**
* @param MatcherInterface[] $matchers
- *
- * @return $this
*/
- public function setMustNots(array $matchers): BoolMatcher
+ public function setMustNots(array $matchers): static
{
$this->mustNots = $matchers;
-
return $this;
}
- /**
- * @param MatcherInterface $matcher
- *
- * @return $this
- */
- public function addMustNot(MatcherInterface $matcher): BoolMatcher
+ public function addMustNot(MatcherInterface $matcher): static
{
$this->mustNots[] = $matcher;
-
return $this;
}
@@ -147,80 +122,54 @@ public function getShoulds(): array
/**
* @param MatcherInterface[] $matchers
- *
- * @return $this
*/
- public function setShoulds(array $matchers): BoolMatcher
+ public function setShoulds(array $matchers): static
{
$this->shoulds = $matchers;
-
return $this;
}
- /**
- * @param MatcherInterface $matcher
- *
- * @return $this
- */
- public function addShould(MatcherInterface $matcher): BoolMatcher
+ public function addShould(MatcherInterface $matcher): static
{
$this->shoulds[] = $matcher;
-
return $this;
}
- /**
- * @return string|int|null
- */
- public function getMinimumShouldMatch()
+ public function getMinimumShouldMatch(): string|int|null
{
return $this->minimumShouldMatch;
}
- /**
- * @param string|int|null $minimumShouldMatch
- *
- * @return $this
- */
- public function setMinimumShouldMatch($minimumShouldMatch = null): BoolMatcher
+ public function setMinimumShouldMatch(string|int|null $minimumShouldMatch): static
{
$this->minimumShouldMatch = $minimumShouldMatch;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (!empty($this->filters)) {
- $rawFilters = array_map(function (MatcherInterface $filterMatcher) {
- return $filterMatcher->jsonSerialize();
- }, $this->filters);
+ $rawFilters = obj_array_json_serialize($this->filters);
$body['filter'] = 1 === count($this->filters) ? $rawFilters[0] : $rawFilters;
}
if (!empty($this->musts)) {
- $rawMusts = array_map(function (MatcherInterface $mustMatcher) {
- return $mustMatcher->jsonSerialize();
- }, $this->musts);
+ $rawMusts = obj_array_json_serialize($this->musts);
$body['must'] = 1 === count($this->musts) ? $rawMusts[0] : $rawMusts;
}
if (!empty($this->mustNots)) {
- $rawMustNots = array_map(function (MatcherInterface $mustNotMatcher) {
- return $mustNotMatcher->jsonSerialize();
- }, $this->mustNots);
+ $rawMustNots = obj_array_json_serialize($this->mustNots);
$body['must_not'] = 1 === count($this->mustNots) ? $rawMustNots[0] : $rawMustNots;
}
if (!empty($this->shoulds)) {
- $rawShoulds = array_map(function (MatcherInterface $shouldMatcher) {
- return $shouldMatcher->jsonSerialize();
- }, $this->shoulds);
+ $rawShoulds = obj_array_json_serialize($this->shoulds);
$body['should'] = 1 === count($this->shoulds) ? $rawShoulds[0] : $rawShoulds;
}
diff --git a/src/Matcher/Compound/BoostingMatcher.php b/src/Matcher/Compound/BoostingMatcher.php
index b415c44..185f375 100644
--- a/src/Matcher/Compound/BoostingMatcher.php
+++ b/src/Matcher/Compound/BoostingMatcher.php
@@ -4,31 +4,24 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-boosting-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-boosting-query.html
* @see BoostingMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class BoostingMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var MatcherInterface */
- protected $positiveQuery;
-
- /** @var MatcherInterface */
- protected $negativeQuery;
-
- /** @var float */
- protected $negativeBoost;
-
- public function __construct(MatcherInterface $positiveQuery, MatcherInterface $negativeQuery, float $negativeBoost)
- {
- $this->positiveQuery = $positiveQuery;
- $this->negativeQuery = $negativeQuery;
- $this->negativeBoost = $negativeBoost;
+ public function __construct(
+ protected MatcherInterface $positiveQuery,
+ protected MatcherInterface $negativeQuery,
+ protected float $negativeBoost,
+ ) {
}
public function __clone()
@@ -38,9 +31,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'positive' => $this->positiveQuery->jsonSerialize(),
diff --git a/src/Matcher/Compound/ConstantScoreMatcher.php b/src/Matcher/Compound/ConstantScoreMatcher.php
index 779c560..a540cff 100644
--- a/src/Matcher/Compound/ConstantScoreMatcher.php
+++ b/src/Matcher/Compound/ConstantScoreMatcher.php
@@ -4,27 +4,27 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-constant-score-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-constant-score-query.html
* @see ConstantScoreMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class ConstantScoreMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var MatcherInterface */
- protected $filter;
-
- /** @var float */
- protected $boost;
-
- public function __construct(MatcherInterface $filter, float $boost, array $options = [])
- {
- $this->filter = $filter;
- $this->boost = $boost;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected MatcherInterface $filter,
+ protected float $boost,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -34,9 +34,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'filter' => $this->filter->jsonSerialize(),
diff --git a/src/Matcher/Compound/DisMaxScoreMatcher.php b/src/Matcher/Compound/DisMaxScoreMatcher.php
index d429836..16213d9 100644
--- a/src/Matcher/Compound/DisMaxScoreMatcher.php
+++ b/src/Matcher/Compound/DisMaxScoreMatcher.php
@@ -2,36 +2,38 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use InvalidArgumentException;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-dis-max-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-dis-max-query.html
* @see DisMaxScoreMatcherTest
- *
- * @options 'boost' => 1.0,
- * 'tie_breaker' => 0.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ 'tie_breaker' => 0.0,
+ '_name' => '?',
+])]
class DisMaxScoreMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var MatcherInterface[] */
- protected $queries;
-
/**
- * @param MatcherInterface[] $queries
- * @param array $options
+ * @param array $options
*/
- public function __construct(array $queries, array $options = [])
- {
+ public function __construct(
+ /** @var MatcherInterface[] */
+ protected array $queries,
+ array $options = [],
+ ) {
if (empty($queries)) {
throw new InvalidArgumentException('Expected at least one query, got none');
}
- $this->queries = $queries;
$this->options = $options;
}
@@ -41,14 +43,12 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
- $body['queries'] = array_map(function (MatcherInterface $query) {
- return $query->jsonSerialize();
- }, $this->queries);
+ $body['queries'] = obj_array_json_serialize($this->queries);
$body += $this->options;
return [
diff --git a/src/Matcher/Compound/FunctionScoreMatcher.php b/src/Matcher/Compound/FunctionScoreMatcher.php
index d37b9a5..e3f0af5 100644
--- a/src/Matcher/Compound/FunctionScoreMatcher.php
+++ b/src/Matcher/Compound/FunctionScoreMatcher.php
@@ -2,35 +2,39 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
use Gskema\ElasticSearchQueryDSL\ScoreFunction\ScoreFunctionInterface;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html
* @see FunctionScoreMatcherTest
- *
- * @options 'boost' => 5.0,
- * 'max_boost' => 2000,
- * 'score_mode' => 'multiply', 'sum', 'avg', 'first', 'max', 'min',
- * 'boost_mode' => 'multiply', 'replace', 'sum', 'avg', 'max', 'min',
- * 'min_score' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 5.0,
+ 'max_boost' => 2000,
+ 'score_mode' => 'multiply', // 'sum', 'avg', 'first', 'max', 'min',
+ 'boost_mode' => 'multiply', // 'replace', 'sum', 'avg', 'max', 'min',
+ 'min_score' => 1.0,
+ '_name' => '?',
+])]
class FunctionScoreMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var MatcherInterface */
- protected $query;
+ /** @var mixed[][] */
+ protected array $functions = [];
- /** @var array[] */
- protected $functions = [];
-
- public function __construct(MatcherInterface $query = null, array $options = [])
- {
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected ?MatcherInterface $query = null,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -40,18 +44,11 @@ public function __clone()
$this->functions = array_clone($this->functions);
}
- /**
- * @param ScoreFunctionInterface $function
- * @param MatcherInterface|null $filter
- * @param int|null $weight
- *
- * @return $this
- */
public function addScoreFunction(
ScoreFunctionInterface $function,
- MatcherInterface $filter = null,
- int $weight = null
- ): FunctionScoreMatcher {
+ ?MatcherInterface $filter = null,
+ ?int $weight = null,
+ ): static {
$rawFunction = [];
$rawFunction['_function'] = $function;
if (null !== $filter) {
@@ -66,9 +63,9 @@ public function addScoreFunction(
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (null !== $this->query) {
diff --git a/src/Matcher/Compound/IndicesMatcher.php b/src/Matcher/Compound/IndicesMatcher.php
deleted file mode 100644
index 75121ec..0000000
--- a/src/Matcher/Compound/IndicesMatcher.php
+++ /dev/null
@@ -1,56 +0,0 @@
- '?',
- */
-class IndicesMatcher implements MatcherInterface
-{
- use HasOptionsTrait;
-
- /** @var string[] */
- protected $indices;
-
- /** @var MatcherInterface */
- protected $query;
-
- /** @var MatcherInterface */
- protected $noMatchQuery;
-
- public function __construct(array $indices, MatcherInterface $query, MatcherInterface $noMatchQuery)
- {
- $this->indices = $indices;
- $this->query = $query;
- $this->noMatchQuery = $noMatchQuery;
- }
-
- public function __clone()
- {
- $this->query = clone $this->query;
- $this->noMatchQuery = clone $this->noMatchQuery;
- }
-
- /**
- * @inheritdoc
- */
- public function jsonSerialize()
- {
- $body = [
- 'indices' => $this->indices,
- 'query' => $this->query->jsonSerialize(),
- 'no_match_query' => $this->noMatchQuery->jsonSerialize(),
- ];
- $body += $this->options;
-
- return [
- 'indices' => $body,
- ];
- }
-}
diff --git a/src/Matcher/Compound/NotMatcher.php b/src/Matcher/Compound/NotMatcher.php
index 345d115..be57042 100644
--- a/src/Matcher/Compound/NotMatcher.php
+++ b/src/Matcher/Compound/NotMatcher.php
@@ -4,23 +4,22 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-bool-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-bool-query.html
* @see NotMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class NotMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var MatcherInterface */
- protected $matcher;
-
- public function __construct(MatcherInterface $matcher)
- {
- $this->matcher = $matcher;
+ public function __construct(
+ protected MatcherInterface $matcher,
+ ) {
}
public function __clone()
@@ -29,9 +28,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['must_not'] = $this->matcher->jsonSerialize();
diff --git a/src/Matcher/FullText/CommonTermsMatcher.php b/src/Matcher/FullText/CommonTermsMatcher.php
index 8bc92ec..a52b8ea 100644
--- a/src/Matcher/FullText/CommonTermsMatcher.php
+++ b/src/Matcher/FullText/CommonTermsMatcher.php
@@ -4,44 +4,40 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-common-terms-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-common-terms-query.html
* @see CommonTermsMatcherTest
- *
- * @options 'minimum_should_match' => ?, ['low_freq' => 2, 'high_freq' => 3],
- * 'low_freq_operator' => 'and', 'or',
- * 'high_freq_operator' => 'and', 'or',
- * 'boost' => 2.0,
- * 'analyzer' => 'standard',
- * 'disable_coord' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'minimum_should_match' => '?', // ['low_freq' => 2, 'high_freq' => 3],
+ 'low_freq_operator' => 'and', // 'or',
+ 'high_freq_operator' => 'and',// 'or',
+ 'boost' => 2.0,
+ 'analyzer' => 'standard',
+ '_name' => '?',
+])]
class CommonTermsMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $query;
-
- /** @var float */
- protected $cutoffFrequency;
-
- public function __construct(string $field, string $query, float $cutoffFrequency, array $options = [])
- {
- $this->field = $field;
- $this->query = $query;
- $this->cutoffFrequency = $cutoffFrequency;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $query,
+ protected float $cutoffFrequency,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'query' => $this->query,
diff --git a/src/Matcher/FullText/MatchMatcher.php b/src/Matcher/FullText/MatchMatcher.php
index ebddb93..89e8a8a 100644
--- a/src/Matcher/FullText/MatchMatcher.php
+++ b/src/Matcher/FullText/MatchMatcher.php
@@ -4,45 +4,46 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query.html
* @see MatchMatcherTest
- *
- * @options 'operator' => 'and', 'or',
- * 'minimum_should_match' => ?,
- * 'analyzer' => 'standard',
- * 'lenient' => true,
- * 'fuzziness' => 2, 'AUTO',
- * 'prefix_length' => 5,
- * 'max_expansions' => 5,
- * 'fuzzy_rewrite' => 10,
- * 'fuzzy_transpositions' => false,
- * 'zero_terms_query' => 'all', 'none',
- * 'cutoff_frequency' => 0.01,
- * '_name' => '?',
*/
+#[Options([
+ 'operator' => 'and', // 'or',
+ 'minimum_should_match' => '?',
+ 'analyzer' => 'standard',
+ 'lenient' => true,
+ 'fuzziness' => 2, // 'AUTO',
+ 'prefix_length' => 5,
+ 'max_expansions' => 5,
+ 'fuzzy_rewrite' => 10,
+ 'fuzzy_transpositions' => false,
+ 'zero_terms_query' => 'all', // 'none',
+ 'cutoff_frequency' => 0.01,
+ 'auto_generate_synonyms_phrase_query' => true,
+ '_name' => '?',
+])]
class MatchMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $query;
-
- public function __construct(string $field, string $query, array $options = [])
- {
- $this->field = $field;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['query'] = $this->query;
diff --git a/src/Matcher/FullText/MatchPhraseMatcher.php b/src/Matcher/FullText/MatchPhraseMatcher.php
index fa1cab3..7e89092 100644
--- a/src/Matcher/FullText/MatchPhraseMatcher.php
+++ b/src/Matcher/FullText/MatchPhraseMatcher.php
@@ -4,36 +4,37 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-query-phrase.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query-phrase.html
* @see MatchPhraseMatcherTest
- *
- * @options 'slop' => 2,
- * 'analyzer' => 'standard',
- * '_name' => '?',
*/
+#[Options([
+ 'slop' => 2,
+ 'analyzer' => 'standard',
+ 'zero_terms_query' => 'all',
+ '_name' => '?',
+])]
class MatchPhraseMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $query;
-
- public function __construct(string $field, string $query, array $options = [])
- {
- $this->field = $field;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['query'] = $this->query;
diff --git a/src/Matcher/FullText/MatchPhrasePrefixMatcher.php b/src/Matcher/FullText/MatchPhrasePrefixMatcher.php
index 641f731..78b23ce 100644
--- a/src/Matcher/FullText/MatchPhrasePrefixMatcher.php
+++ b/src/Matcher/FullText/MatchPhrasePrefixMatcher.php
@@ -4,37 +4,37 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-query-phrase-prefix.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query-phrase-prefix.html
* @see MatchPhrasePrefixMatcherTest
- *
- * @options 'slop' => 2,
- * 'analyzer' => 'standard',
- * 'max_expansions' => 50,
- * '_name' => '?',
*/
+#[Options([
+ 'slop' => 2,
+ 'analyzer' => 'standard',
+ 'max_expansions' => 50,
+ '_name' => '?',
+])]
class MatchPhrasePrefixMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $query;
-
- public function __construct(string $field, string $query, array $options = [])
- {
- $this->field = $field;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['query'] = $this->query;
diff --git a/src/Matcher/FullText/MultiMatchMatcher.php b/src/Matcher/FullText/MultiMatchMatcher.php
index 1363a5d..9cbb79a 100644
--- a/src/Matcher/FullText/MultiMatchMatcher.php
+++ b/src/Matcher/FullText/MultiMatchMatcher.php
@@ -4,48 +4,50 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-multi-match-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-multi-match-query.html
* @see MultiMatchMatcherTest
- *
- * @options 'type' => 'best_fields', 'most_fields', 'cross_fields', 'phrase', 'phrase_prefix',
- * 'tie_breaker' => 0.3,
- * 'operator' => 'and', 'or',
- * 'minimum_should_match' => '1',
- * 'analyzer' => 'standard',
- * 'lenient' => true,
- * 'slop' => 2,
- * 'fuzziness' => 2, 'AUTO',
- * 'prefix_length' => 5,
- * 'max_expansions' => 5,
- * 'fuzzy_rewrite' => 10,
- * 'fuzzy_transpositions' => false,
- * 'zero_terms_query' => 'all', 'none',
- * 'cutoff_frequency' => 0.01,
- * '_name' => '?',
*/
+#[Options([
+ 'type' => 'best_fields', // 'most_fields', 'cross_fields', 'phrase', 'phrase_prefix',
+ 'tie_breaker' => 0.3,
+ 'operator' => 'and', // 'or',
+ 'minimum_should_match' => '1',
+ 'analyzer' => 'standard',
+ 'lenient' => true,
+ 'slop' => 2,
+ 'fuzziness' => 2, // 'AUTO',
+ 'prefix_length' => 5,
+ 'max_expansions' => 5,
+ 'fuzzy_rewrite' => "constant_score",
+ 'fuzzy_transpositions' => false,
+ 'zero_terms_query' => 'all', // 'none',
+ 'cutoff_frequency' => 0.01,
+ 'boost' => 2,
+ '_name' => '?',
+])]
class MultiMatchMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string[] */
- protected $fields;
-
- /** @var string */
- protected $query;
-
- public function __construct(array $fields, string $query, array $options = [])
- {
- $this->fields = $fields;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ /** @var string[] */
+ protected array $fields,
+ protected string $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'query' => $this->query,
diff --git a/src/Matcher/FullText/QueryStringMatcher.php b/src/Matcher/FullText/QueryStringMatcher.php
index d335fb4..720a064 100644
--- a/src/Matcher/FullText/QueryStringMatcher.php
+++ b/src/Matcher/FullText/QueryStringMatcher.php
@@ -4,52 +4,55 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-query-string-query.html
* @see QueryStringMatcherTest
- *
- * @options 'fields' => ?,
- * 'default_field' => '_all', '?',
- * 'default_operator' => 'AND', 'OR',
- * 'analyzer' => 'standard', '?',
- * 'allow_leading_wildcard' => true,
- * 'enable_position_increments' => true,
- * 'fuzzy_max_expansions' => false,
- * 'fuzziness' => 3, 'AUTO',
- * 'fuzzy_prefix_length' => 0,
- * 'phrase_slop' => 5,
- * 'boost' => 1.0,
- * 'auto_generate_phrase_queries' => false,
- * 'analyze_wildcard' => true,
- * 'max_determinized_states' => 10000,
- * 'minimum_should_match' => 2, -2, '75%', '-25%', '3<90%', '2<-25%', '9<-3',
- * 'lenient' => true,
- * 'time_zone' => '?',
- * 'quote_field_suffix' => ?,
- * 'split_on_whitespace' => true,
- * 'all_fields' => false,
- * 'use_dis_max' => true,
- * 'tie_breaker' => 0.3,
- * '_name' => '?',
*/
+#[Options([
+ 'fields' => '?',
+ 'type' => 'best_fields', // 'most_fields', 'cross_fields', 'phrase', 'phrase_prefix',
+ 'default_field' => '_all', // '?',
+ 'default_operator' => 'AND', // 'OR',
+ 'analyzer' => 'standard', // '?',
+ 'quote_analyzer' => '?',
+ 'allow_leading_wildcard' => true,
+ 'enable_position_increments' => true,
+ 'fuzzy_max_expansions' => false,
+ 'fuzziness' => 3, // 'AUTO',
+ 'fuzzy_prefix_length' => 0,
+ 'fuzzy_transpositions' => false,
+ 'phrase_slop' => 5,
+ 'boost' => 1.0,
+ 'analyze_wildcard' => true,
+ 'max_determinized_states' => 10000,
+ 'minimum_should_match' => 2, // -2, '75%', '-25%', '3<90%', '2<-25%', '9<-3',
+ 'lenient' => true,
+ 'time_zone' => '?',
+ 'quote_field_suffix' => '?',
+ 'auto_generate_synonyms_phrase_query' => true,
+ 'tie_breaker' => 0.3,
+ '_name' => '?',
+])]
class QueryStringMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $query;
-
- public function __construct(string $query, array $options = [])
- {
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['query'] = $this->query;
diff --git a/src/Matcher/FullText/SimpleQueryStringMatcher.php b/src/Matcher/FullText/SimpleQueryStringMatcher.php
index 66a8ce6..6c435a6 100644
--- a/src/Matcher/FullText/SimpleQueryStringMatcher.php
+++ b/src/Matcher/FullText/SimpleQueryStringMatcher.php
@@ -4,39 +4,45 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-simple-query-string-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-simple-query-string-query.html
* @see SimpleQueryStringMatcherTest
- *
- * @options 'fields' => ['body^5', '_all'],
- * 'default_operator' => 'AND','OR',
- * 'analyzer' => 'standard',
- * 'flags' => 'ALL|NONE|AND|OR|NOT|PREFIX|PHRASE|PRECEDENCE|ESCAPE|WHITESPACE|FUZZY|NEAR|SLOP'
- * 'analyze_wildcard' => true,
- * 'lenient' => true,
- * 'minimum_should_match' => 5,
- * 'quote_field_suffix' => '.exact',
- * 'all_fields' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'fields' => ['body^5', '_all'],
+ 'default_operator' => 'AND', // 'OR',
+ 'analyzer' => 'standard',
+ 'flags' => 'ALL|NONE|AND|OR|NOT|PREFIX|PHRASE|PRECEDENCE|ESCAPE|WHITESPACE|FUZZY|NEAR|SLOP',
+ 'analyze_wildcard' => true,
+ 'lenient' => true,
+ 'minimum_should_match' => 5,
+ 'quote_field_suffix' => '.exact',
+ 'auto_generate_synonyms_phrase_query' => false,
+ 'fuzzy_prefix_length' => 0,
+ 'fuzzy_max_expansions' => 50,
+ 'fuzzy_transpositions' => true,
+ '_name' => '?',
+])]
class SimpleQueryStringMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $query;
-
- public function __construct(string $query, array $options = [])
- {
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['query'] = $this->query;
diff --git a/src/Matcher/Geo/GeoBoundingBoxMatcher.php b/src/Matcher/Geo/GeoBoundingBoxMatcher.php
index db881e6..5cba705 100644
--- a/src/Matcher/Geo/GeoBoundingBoxMatcher.php
+++ b/src/Matcher/Geo/GeoBoundingBoxMatcher.php
@@ -5,48 +5,33 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use Gskema\ElasticSearchQueryDSL\Model\GeoPointInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-geo-bounding-box-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-bounding-box-query.html
* @see GeoBoundingBoxMatcherTest
- *
- * @options 'validation_method' => 'IGNORE_MALFORMED', 'COERCE', 'STRICT'
- * 'type' => 'indexed', 'memory',
- * 'ignore_unmapped' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'validation_method' => 'IGNORE_MALFORMED', // 'COERCE', 'STRICT'
+ 'type' => 'indexed', // 'memory',
+ 'ignore_unmapped' => true,
+ '_name' => '?',
+])]
class GeoBoundingBoxMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var GeoPointInterface */
- protected $topLeft;
-
- /** @var GeoPointInterface */
- protected $topRight;
-
- /** @var GeoPointInterface */
- protected $bottomLeft;
-
- /** @var GeoPointInterface */
- protected $bottomRight;
-
+ /**
+ * @param array $options
+ */
protected function __construct(
- string $field,
- GeoPointInterface $topLeft = null,
- GeoPointInterface $topRight = null,
- GeoPointInterface $bottomLeft = null,
- GeoPointInterface $bottomRight = null,
- array $options = []
+ protected string $field,
+ protected ?GeoPointInterface $topLeft = null,
+ protected ?GeoPointInterface $topRight = null,
+ protected ?GeoPointInterface $bottomLeft = null,
+ protected ?GeoPointInterface $bottomRight = null,
+ array $options = [],
) {
- $this->field = $field;
- $this->topLeft = $topLeft;
- $this->topRight = $topRight;
- $this->bottomLeft = $bottomLeft;
- $this->bottomRight = $bottomRight;
$this->options = $options;
}
@@ -58,28 +43,34 @@ public function __clone()
$this->bottomRight = $this->bottomRight ? clone $this->bottomRight : null;
}
+ /**
+ * @param array $options
+ */
public static function fromTopLeft(
string $field,
GeoPointInterface $topLeft,
GeoPointInterface $bottomRight,
- array $options = []
- ): GeoBoundingBoxMatcher {
+ array $options = [],
+ ): static {
return new static($field, $topLeft, null, null, $bottomRight, $options);
}
+ /**
+ * @param array $options
+ */
public static function fromTopRight(
string $field,
GeoPointInterface $topRight,
GeoPointInterface $bottomLeft,
- array $options = []
- ): GeoBoundingBoxMatcher {
+ array $options = [],
+ ): static {
return new static($field, null, $topRight, $bottomLeft, null, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$rawBox = [];
if (null !== $this->topLeft) {
diff --git a/src/Matcher/Geo/GeoDistanceMatcher.php b/src/Matcher/Geo/GeoDistanceMatcher.php
index eccdc65..8e189e4 100644
--- a/src/Matcher/Geo/GeoDistanceMatcher.php
+++ b/src/Matcher/Geo/GeoDistanceMatcher.php
@@ -5,36 +5,31 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use Gskema\ElasticSearchQueryDSL\Model\GeoPointInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-geo-distance-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-distance-query.html
* @see GeoDistanceMatcherTest
- *
- * @options 'distance_type' => 'arc', 'plane',
- * 'optimize_bbox' => 'memory', 'indexed',
- * 'ignore_malformed' => true,
- * 'ignore_unmapped' => true,
- * 'validation_method' => 'IGNORE_MALFORMED', 'COERCE', 'STRICT',
- * '_name' => '?',
*/
+#[Options([
+ 'distance_type' => 'arc', // 'plane',
+ 'ignore_unmapped' => true,
+ 'validation_method' => 'IGNORE_MALFORMED', // 'COERCE', 'STRICT',
+ '_name' => '?',
+])]
class GeoDistanceMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var GeoPointInterface */
- protected $origin;
-
- /** @var string */
- protected $distance;
-
- public function __construct(string $field, GeoPointInterface $origin, string $distance, array $options = [])
- {
- $this->field = $field;
- $this->origin = $origin;
- $this->distance = $distance;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected GeoPointInterface $origin,
+ protected string $distance,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -44,9 +39,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
$this->field => $this->origin->jsonSerialize(),
diff --git a/src/Matcher/Geo/GeoDistanceRangeMatcher.php b/src/Matcher/Geo/GeoDistanceRangeMatcher.php
deleted file mode 100644
index 47cf9b1..0000000
--- a/src/Matcher/Geo/GeoDistanceRangeMatcher.php
+++ /dev/null
@@ -1,71 +0,0 @@
- 'arc', 'plane',
- * 'optimize_bbox' => 'memory', 'indexed',
- * 'ignore_malformed' => true,
- * 'ignore_unmapped' => true,
- * 'validation_method' => 'IGNORE_MALFORMED', 'COERCE', 'STRICT',
- * 'include_upper' => ?,
- * 'include_lower' => ?,
- * '_name' => '?',
- */
-class GeoDistanceRangeMatcher implements MatcherInterface
-{
- use HasOptionsTrait;
-
- /** @var string */
- protected $field;
-
- /** @var GeoPointInterface */
- protected $origin;
-
- /**
- * 'lt' => '1km',
- * 'lte' => '1m',
- * 'gt' => '1cm',
- * 'gte' => '1mi',
- * 'from' => '1yd',
- * 'to' => '1in',
- *
- * @var array
- */
- protected $range;
-
- public function __construct(string $field, GeoPointInterface $origin, array $range, array $options = [])
- {
- $this->field = $field;
- $this->origin = $origin;
- $this->range = $range;
- $this->options = $options;
- }
-
- public function __clone()
- {
- $this->origin = clone $this->origin;
- }
-
- /**
- * @inheritdoc
- */
- public function jsonSerialize()
- {
- $body = [];
- $body[$this->field] = $this->origin->jsonSerialize();
- $body += $this->range;
- $body += $this->options;
-
- return [
- 'geo_distance_range' => $body,
- ];
- }
-}
diff --git a/src/Matcher/Geo/GeoPolygonMatcher.php b/src/Matcher/Geo/GeoPolygonMatcher.php
index 1fa2ccf..2ec5149 100644
--- a/src/Matcher/Geo/GeoPolygonMatcher.php
+++ b/src/Matcher/Geo/GeoPolygonMatcher.php
@@ -2,44 +2,41 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Geo;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use Gskema\ElasticSearchQueryDSL\Model\GeoPointInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use InvalidArgumentException;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-geo-polygon-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-polygon-query.html
* @see GeoPolygonMatcherTest
- *
- * @options 'ignore_malformed' => true,
- * 'ignore_unmapped' => true,
- * 'validation_method' => 'IGNORE_MALFORMED', 'COERCE', 'STRICT',
- * '_name' => '?',
*/
+#[Options([
+ 'ignore_unmapped' => true,
+ 'validation_method' => 'IGNORE_MALFORMED', // 'COERCE', 'STRICT',
+ '_name' => '?',
+])]
class GeoPolygonMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var GeoPointInterface[] */
- protected $points;
-
/**
- * @param string $field
- * @param GeoPointInterface[] $points
- * @param array $options
+ * @param array $options
*/
- public function __construct(string $field, array $points, array $options = [])
- {
+ public function __construct(
+ protected string $field,
+ /** @var GeoPointInterface[] */
+ protected array $points,
+ array $options = [],
+ ) {
$pointCount = count($points);
if ($pointCount < 3) {
- throw new InvalidArgumentException('Expected at least 3 geo polygon points, got '.$pointCount);
+ throw new InvalidArgumentException('Expected at least 3 geo polygon points, got ' . $pointCount);
}
- $this->field = $field;
- $this->points = $points;
$this->options = $options;
}
@@ -49,13 +46,11 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $rawPoints = array_map(function (GeoPointInterface $point) {
- return $point->jsonSerialize();
- }, $this->points);
+ $rawPoints = obj_array_json_serialize($this->points);
$body = [];
$body[$this->field]['points'] = $rawPoints;
diff --git a/src/Matcher/Geo/GeoShapeMatcher.php b/src/Matcher/Geo/GeoShapeMatcher.php
index 815cd90..013acaf 100644
--- a/src/Matcher/Geo/GeoShapeMatcher.php
+++ b/src/Matcher/Geo/GeoShapeMatcher.php
@@ -6,40 +6,29 @@
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use Gskema\ElasticSearchQueryDSL\Model\GeoShape\GeoShapeInterface;
use Gskema\ElasticSearchQueryDSL\Model\GeoShape\IndexedGeoShape;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-geo-shape-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-shape-query.html
* @see GeoShapeMatcherTest
- *
- * @options 'ignore_unmapped' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'ignore_unmapped' => true,
+ '_name' => '?',
+])]
class GeoShapeMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var GeoShapeInterface */
- protected $geoShape;
-
/**
- * 'INTERSECTS', DISJOINT, 'WITHIN', 'CONTAINS'
- *
- * @var string|null
+ * @param array $options
*/
- protected $relation;
-
public function __construct(
- string $field,
- GeoShapeInterface $geoShape,
- string $relation = null,
- array $options = []
+ protected string $field,
+ protected GeoShapeInterface $geoShape,
+ protected ?string $relation = null, // 'INTERSECTS', DISJOINT, 'WITHIN', 'CONTAINS'
+ array $options = [],
) {
- $this->field = $field;
- $this->geoShape = $geoShape;
- $this->relation = $relation;
$this->options = $options;
}
@@ -49,9 +38,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$shapeKey = $this->geoShape instanceof IndexedGeoShape ? 'indexed_shape' : 'shape';
diff --git a/src/Matcher/Joining/HasChildMatcher.php b/src/Matcher/Joining/HasChildMatcher.php
index 5d50ad2..33adc29 100644
--- a/src/Matcher/Joining/HasChildMatcher.php
+++ b/src/Matcher/Joining/HasChildMatcher.php
@@ -4,33 +4,32 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-has-child-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-has-child-query.html
* @see HasChildMatcherTest
- *
- * @options 'score_mode' => 'min', 'max', 'sum', 'avg', 'none',
- * 'min_children' => 2,
- * 'max_children' => 10,
- * 'min_children' => true,
- * 'ignore_unmapped' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'score_mode' => 'min', // 'max', 'sum', 'avg', 'none',
+ 'min_children' => 2,
+ 'max_children' => 10,
+ 'ignore_unmapped' => true,
+ '_name' => '?',
+])]
class HasChildMatcher implements MatcherInterface
{
use HasOptionsTrait;
use HasInnerHitsTrait;
- /** @var string */
- protected $childType;
-
- /** @var MatcherInterface */
- protected $query;
-
- public function __construct(string $childType, MatcherInterface $query, array $options = [])
- {
- $this->childType = $childType;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $childType,
+ protected MatcherInterface $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -41,9 +40,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['type'] = $this->childType;
diff --git a/src/Matcher/Joining/HasInnerHitsTrait.php b/src/Matcher/Joining/HasInnerHitsTrait.php
index 87a64a5..537daa2 100644
--- a/src/Matcher/Joining/HasInnerHitsTrait.php
+++ b/src/Matcher/Joining/HasInnerHitsTrait.php
@@ -5,31 +5,21 @@
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-inner-hits.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-inner-hits.html
* @see HasInnerHitsTraitTest
*/
trait HasInnerHitsTrait
{
- /** @var InnerHitsRequest|null */
- protected $innerHits;
+ protected ?InnerHitsRequest $innerHits = null;
- /**
- * @return InnerHitsRequest|null
- */
- public function getInnerHits()
+ public function getInnerHits(): ?InnerHitsRequest
{
return $this->innerHits;
}
- /**
- * @param InnerHitsRequest|null $request
- *
- * @return $this
- */
- public function setInnerHits(InnerHitsRequest $request = null)
+ public function setInnerHits(?InnerHitsRequest $request): static
{
$this->innerHits = $request;
-
return $this;
}
diff --git a/src/Matcher/Joining/HasParentMatcher.php b/src/Matcher/Joining/HasParentMatcher.php
index 0159717..39b52bf 100644
--- a/src/Matcher/Joining/HasParentMatcher.php
+++ b/src/Matcher/Joining/HasParentMatcher.php
@@ -4,30 +4,30 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-has-parent-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-has-parent-query.html
* @see HasParentMatcherTest
- *
- * @options 'score' => true,
- * 'ignore_unmapped' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'score' => true,
+ 'ignore_unmapped' => true,
+ '_name' => '?',
+])]
class HasParentMatcher implements MatcherInterface
{
use HasOptionsTrait;
use HasInnerHitsTrait;
- /** @var string */
- protected $parentType;
-
- /** @var MatcherInterface */
- protected $query;
-
- public function __construct(string $parentType, MatcherInterface $query, array $options = [])
- {
- $this->parentType = $parentType;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $parentType,
+ protected MatcherInterface $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -38,9 +38,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['parent_type'] = $this->parentType;
diff --git a/src/Matcher/Joining/NestedMatcher.php b/src/Matcher/Joining/NestedMatcher.php
index 2f1d1ce..ca0d560 100644
--- a/src/Matcher/Joining/NestedMatcher.php
+++ b/src/Matcher/Joining/NestedMatcher.php
@@ -4,43 +4,43 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-nested-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-nested-query.html
* @see NestedMatcherTest
- *
- * @options 'score_mode' => 'min', 'max', 'sum', 'avg', 'none',
- * 'ignore_unmapped' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'score_mode' => 'min', // 'max', 'sum', 'avg', 'none',
+ 'ignore_unmapped' => true,
+ '_name' => '?',
+])]
class NestedMatcher implements MatcherInterface
{
use HasOptionsTrait;
use HasInnerHitsTrait;
- /** @var string */
- protected $path;
-
- /** @var MatcherInterface */
- protected $query;
-
- public function __construct(string $path, MatcherInterface $query, array $options = [])
- {
- $this->path = $path;
- $this->query = $query;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $path,
+ protected MatcherInterface $query,
+ array $options = [],
+ ) {
$this->options = $options;
}
public function __clone()
{
$this->query = clone $this->query;
- $this->innerHits = $this->innerHits ? clone $this->innerHits: null;
+ $this->innerHits = $this->innerHits ? clone $this->innerHits : null;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['path'] = $this->path;
diff --git a/src/Matcher/Joining/ParentIdMatcher.php b/src/Matcher/Joining/ParentIdMatcher.php
index af40729..e38f904 100644
--- a/src/Matcher/Joining/ParentIdMatcher.php
+++ b/src/Matcher/Joining/ParentIdMatcher.php
@@ -4,29 +4,29 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-parent-id-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-parent-id-query.html
* @see ParentIdMatcherTest
- *
- * @options 'ignore_unmapped' => true,
- * '_name' => '?',
*/
+#[Options([
+ 'ignore_unmapped' => true,
+ '_name' => '?',
+])]
class ParentIdMatcher implements MatcherInterface
{
use HasOptionsTrait;
use HasInnerHitsTrait;
- /** @var string */
- protected $childType;
-
- /** @var string|int */
- protected $parentId;
-
- public function __construct(string $childType, string $parentId, array $options = [])
- {
- $this->childType = $childType;
- $this->parentId = $parentId;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $childType,
+ protected string $parentId,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -36,9 +36,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'type' => $this->childType,
diff --git a/src/Matcher/MatchAllMatcher.php b/src/Matcher/MatchAllMatcher.php
index 7a588af..091a37f 100644
--- a/src/Matcher/MatchAllMatcher.php
+++ b/src/Matcher/MatchAllMatcher.php
@@ -3,37 +3,36 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
use stdClass;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-all-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-all-query.html
* @see MatchAllMatcherTest
- *
- * @options 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ '_name' => '?',
+])]
class MatchAllMatcher implements MatcherInterface
{
use HasOptionsTrait;
+ /**
+ * @param array $options
+ */
public function __construct(array $options = [])
{
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- if (!empty($this->options)) {
- $body = $this->options;
- } else {
- $body = new stdClass();
- }
-
return [
- 'match_all' => $body,
+ 'match_all' => $this->options ?: new stdClass(),
];
}
}
diff --git a/src/Matcher/MatchNoneMatcher.php b/src/Matcher/MatchNoneMatcher.php
index 7c64711..6d0d95e 100644
--- a/src/Matcher/MatchNoneMatcher.php
+++ b/src/Matcher/MatchNoneMatcher.php
@@ -5,15 +5,15 @@
use stdClass;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-match-all-query.html#query-dsl-match-none-query
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-all-query.html#query-dsl-match-none-query
* @see MatchNoneMatcherTest
*/
class MatchNoneMatcher implements MatcherInterface
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return [
'match_none' => new stdClass(),
diff --git a/src/Matcher/Span/SpanContainingMatcher.php b/src/Matcher/Span/SpanContainingMatcher.php
index 01f0673..4a89eb4 100644
--- a/src/Matcher/Span/SpanContainingMatcher.php
+++ b/src/Matcher/Span/SpanContainingMatcher.php
@@ -3,27 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-containing-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-containing-query.html
* @see SpanContainingMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanContainingMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var SpanMatcherInterface */
- protected $little;
-
- /** @var SpanMatcherInterface */
- protected $big;
-
- public function __construct(SpanMatcherInterface $little, SpanMatcherInterface $big)
- {
- $this->little = $little;
- $this->big = $big;
+ public function __construct(
+ protected SpanMatcherInterface $little,
+ protected SpanMatcherInterface $big,
+ ) {
}
public function __clone()
@@ -33,9 +29,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'little' => $this->little->jsonSerialize(),
diff --git a/src/Matcher/Span/SpanFieldMaskingMatcher.php b/src/Matcher/Span/SpanFieldMaskingMatcher.php
index 0cc6f61..6866a22 100644
--- a/src/Matcher/Span/SpanFieldMaskingMatcher.php
+++ b/src/Matcher/Span/SpanFieldMaskingMatcher.php
@@ -3,27 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-field-masking-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-field-masking-query.html
* @see SpanFieldMaskingMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanFieldMaskingMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var SpanMatcherInterface */
- protected $matcher;
-
- public function __construct(string $field, SpanMatcherInterface $matcher)
- {
- $this->field = $field;
- $this->matcher = $matcher;
+ public function __construct(
+ protected string $field,
+ protected SpanMatcherInterface $matcher,
+ ) {
}
public function __clone()
@@ -32,9 +28,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'query' => $this->matcher->jsonSerialize(),
diff --git a/src/Matcher/Span/SpanFirstMatcher.php b/src/Matcher/Span/SpanFirstMatcher.php
index 6f18a8f..683d703 100644
--- a/src/Matcher/Span/SpanFirstMatcher.php
+++ b/src/Matcher/Span/SpanFirstMatcher.php
@@ -3,27 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-first-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-first-query.html
* @see SpanFirstMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanFirstMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var SpanMatcherInterface */
- protected $matcher;
-
- /** @var int */
- protected $end;
-
- public function __construct(SpanMatcherInterface $matcher, int $end)
- {
- $this->matcher = $matcher;
- $this->end = $end;
+ public function __construct(
+ protected SpanMatcherInterface $matcher,
+ protected int $end,
+ ) {
}
public function __clone()
@@ -32,9 +28,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'match' => $this->matcher->jsonSerialize(),
diff --git a/src/Matcher/Span/SpanMultiMatcher.php b/src/Matcher/Span/SpanMultiMatcher.php
index 7c0df7f..8c59de1 100644
--- a/src/Matcher/Span/SpanMultiMatcher.php
+++ b/src/Matcher/Span/SpanMultiMatcher.php
@@ -4,23 +4,22 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MultiTermMatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-multi-term-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-multi-term-query.html
* @see SpanMultiMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanMultiMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var MultiTermMatcherInterface */
- protected $matcher;
-
- public function __construct(MultiTermMatcherInterface $matcher)
- {
- $this->matcher = $matcher;
+ public function __construct(
+ protected MultiTermMatcherInterface $matcher,
+ ) {
}
public function __clone()
@@ -29,9 +28,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['match'] = $this->matcher->jsonSerialize();
diff --git a/src/Matcher/Span/SpanNearMatcher.php b/src/Matcher/Span/SpanNearMatcher.php
index b6a5dce..8a9f81e 100644
--- a/src/Matcher/Span/SpanNearMatcher.php
+++ b/src/Matcher/Span/SpanNearMatcher.php
@@ -2,42 +2,33 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
use InvalidArgumentException;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-near-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-near-query.html
* @see SpanNearMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanNearMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var SpanMatcherInterface[] */
- protected $spanMatchers;
-
- /** @var int */
- protected $slop;
-
- /** @var bool */
- protected $inOrder;
-
- /**
- * @param SpanMatcherInterface[] $spanMatchers
- * @param int $slop
- * @param bool $inOrder
- */
- public function __construct(array $spanMatchers, int $slop, bool $inOrder)
- {
+ public function __construct(
+ /** @var SpanMatcherInterface[] */
+ protected array $spanMatchers,
+ protected int $slop,
+ protected bool $inOrder,
+ ) {
if (empty($spanMatchers)) {
throw new InvalidArgumentException('Expected at least one span matcher, got none');
}
- $this->spanMatchers = $spanMatchers;
- $this->slop = $slop;
- $this->inOrder = $inOrder;
}
public function __clone()
@@ -46,14 +37,12 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
- 'clauses' => array_map(function (SpanMatcherInterface $matcher) {
- return $matcher->jsonSerialize();
- }, $this->spanMatchers),
+ 'clauses' => obj_array_json_serialize($this->spanMatchers),
'slop' => $this->slop,
'in_order' => $this->inOrder,
];
diff --git a/src/Matcher/Span/SpanNotMatcher.php b/src/Matcher/Span/SpanNotMatcher.php
index d8caad5..26e2e3c 100644
--- a/src/Matcher/Span/SpanNotMatcher.php
+++ b/src/Matcher/Span/SpanNotMatcher.php
@@ -3,30 +3,30 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-not-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-not-query.html
* @see SpanNotMatcherTest
- *
- * @options 'pre' => 1,
- * 'post' => 2,
- * 'dist' => 2,
- * '_name' => '?',
*/
+#[Options([
+ 'pre' => 1,
+ 'post' => 2,
+ 'dist' => 2,
+ '_name' => '?',
+])]
class SpanNotMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var SpanMatcherInterface */
- protected $include;
-
- /** @var SpanMatcherInterface */
- protected $exclude;
-
- public function __construct(SpanMatcherInterface $include, SpanMatcherInterface $exclude, array $options = [])
- {
- $this->include = $include;
- $this->exclude = $exclude;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected SpanMatcherInterface $include,
+ protected SpanMatcherInterface $exclude,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -37,9 +37,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'include' => $this->include->jsonSerialize(),
diff --git a/src/Matcher/Span/SpanOrMatcher.php b/src/Matcher/Span/SpanOrMatcher.php
index 00a5bbc..9760967 100644
--- a/src/Matcher/Span/SpanOrMatcher.php
+++ b/src/Matcher/Span/SpanOrMatcher.php
@@ -2,32 +2,31 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
use InvalidArgumentException;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-or-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-or-query.html
* @see SpanOrMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanOrMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var SpanMatcherInterface[] */
- protected $spanMatchers;
-
- /**
- * @param SpanMatcherInterface[] $spanMatchers
- */
- public function __construct(array $spanMatchers)
- {
+ public function __construct(
+ /** @var SpanMatcherInterface[] */
+ protected array $spanMatchers,
+ ) {
if (empty($spanMatchers)) {
throw new InvalidArgumentException('Expected at least one span matcher, got none');
}
- $this->spanMatchers = $spanMatchers;
}
public function __clone()
@@ -36,14 +35,12 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
- $body['clauses'] =array_map(function (SpanMatcherInterface $matcher) {
- return $matcher->jsonSerialize();
- }, $this->spanMatchers);
+ $body['clauses'] = obj_array_json_serialize($this->spanMatchers);
$body += $this->options;
return [
diff --git a/src/Matcher/Span/SpanTermMatcher.php b/src/Matcher/Span/SpanTermMatcher.php
index 2a3e5e5..d900f7f 100644
--- a/src/Matcher/Span/SpanTermMatcher.php
+++ b/src/Matcher/Span/SpanTermMatcher.php
@@ -3,35 +3,35 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-term-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-term-query.html
* @see SpanTermMatcherTest
- *
- * @options 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ '_name' => '?',
+])]
class SpanTermMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $value;
-
- public function __construct(string $field, string $value, array $options = [])
- {
- $this->field = $field;
- $this->value = $value;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $value,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (!empty($this->options)) {
diff --git a/src/Matcher/Span/SpanWithinMatcher.php b/src/Matcher/Span/SpanWithinMatcher.php
index 35e9ebd..834897d 100644
--- a/src/Matcher/Span/SpanWithinMatcher.php
+++ b/src/Matcher/Span/SpanWithinMatcher.php
@@ -3,27 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-span-within-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-span-within-query.html
* @see SpanWithinMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class SpanWithinMatcher implements SpanMatcherInterface
{
use HasOptionsTrait;
- /** @var SpanMatcherInterface */
- protected $little;
-
- /** @var SpanMatcherInterface */
- protected $big;
-
- public function __construct(SpanMatcherInterface $little, SpanMatcherInterface $big)
- {
- $this->little = $little;
- $this->big = $big;
+ public function __construct(
+ protected SpanMatcherInterface $little,
+ protected SpanMatcherInterface $big,
+ ) {
}
public function __clone()
@@ -33,9 +29,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'little' => $this->little->jsonSerialize(),
diff --git a/src/Matcher/Specialized/MoreLikeThisMatcher.php b/src/Matcher/Specialized/MoreLikeThisMatcher.php
index dbbf640..d26b712 100644
--- a/src/Matcher/Specialized/MoreLikeThisMatcher.php
+++ b/src/Matcher/Specialized/MoreLikeThisMatcher.php
@@ -4,49 +4,50 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-mlt-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-mlt-query.html
* @see MoreLikeThisMatcherTest
- *
- * @options 'unlike' => ?,
- * 'like_text' => ?,
- * 'ids' => ['id1', 'id2'],
- * 'docs' => ?,
- * 'max_query_terms' => 2,
- * 'min_term_freq' => 5,
- * 'max_doc_freq' => 0,
- * 'min_word_length' => 0,
- * 'max_word_length' => 0,
- * 'stop_words' => ['word1', 'word2'],
- * 'analyzer' => 'standard',
- * 'minimum_should_match' => ?,
- * 'boost_terms' => 0,
- * 'include' => false,
- * 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'unlike' => '?',
+ 'max_query_terms' => 2,
+ 'min_term_freq' => 5,
+ 'min_doc_freq' => 5,
+ 'max_doc_freq' => 0,
+ 'min_word_length' => 0,
+ 'max_word_length' => 0,
+ 'stop_words' => ['word1', 'word2'],
+ 'analyzer' => 'standard',
+ 'minimum_should_match' => '?',
+ 'fail_on_unsupported_field' => true,
+ 'boost_terms' => 0,
+ 'include' => false,
+ 'boost' => 1.0,
+ '_name' => '?',
+])]
class MoreLikeThisMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $fields;
-
- /** @var array|string */
- protected $like;
-
- public function __construct(array $fields, $like, array $options = [])
- {
- $this->fields = $fields;
- $this->like = $like;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ /** @var string[] */
+ protected array $fields,
+ /** @var mixed[]|string */
+ protected array|string $like,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'fields' => $this->fields,
diff --git a/src/Matcher/Specialized/PercolateMatcher.php b/src/Matcher/Specialized/PercolateMatcher.php
index 4b7215e..dc9cc3c 100644
--- a/src/Matcher/Specialized/PercolateMatcher.php
+++ b/src/Matcher/Specialized/PercolateMatcher.php
@@ -4,55 +4,80 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-percolate-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-percolate-query.html
* @see PercolateMatcherTest
- *
- * @options 'routing' => ?,
- * 'preference' => ?
- * 'version' => 2,
- * '_name' => '?',
*/
+#[Options([
+ 'routing' => '?',
+ 'preference' => '?',
+ 'version' => 2,
+ 'name' => 'query1',
+ '_name' => '?',
+])]
class PercolateMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $body;
-
- protected function __construct(array $body, array $options = [])
- {
- $this->body = $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ /** @var mixed[] */
+ protected array $body,
+ array $options = [],
+ ) {
$this->options = $options;
}
+ /**
+ * @param mixed[][] $docSources
+ * @param array $options
+ */
+ public static function fromDocSources(
+ string $queryField,
+ array $docSources,
+ array $options = [],
+ ): static {
+ $body = [
+ 'field' => $queryField,
+ 'documents' => $docSources,
+ ];
+
+ return new static($body, $options);
+ }
+
+ /**
+ * @param mixed[] $docSource
+ * @param array $options
+ */
public static function fromDocSource(
string $queryField,
- string $docType,
array $docSource,
- array $options = []
- ): PercolateMatcher {
+ array $options = [],
+ ): static {
$body = [
'field' => $queryField,
- 'document_type' => $docType,
'document' => $docSource,
];
return new static($body, $options);
}
+ /**
+ * @param array $options
+ */
public static function fromIndexedDoc(
string $queryField,
- string $docType,
string $index,
string $type,
string $id,
- array $options = []
- ): PercolateMatcher {
+ array $options = [],
+ ): static {
$body = [
'field' => $queryField,
- 'document_type' => $docType,
'index' => $index,
'type' => $type,
'id' => $id,
@@ -62,9 +87,9 @@ public static function fromIndexedDoc(
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = $this->body;
$body += $this->options;
diff --git a/src/Matcher/Specialized/ScriptMatcher.php b/src/Matcher/Specialized/ScriptMatcher.php
index 145cc4d..e5bd35e 100644
--- a/src/Matcher/Specialized/ScriptMatcher.php
+++ b/src/Matcher/Specialized/ScriptMatcher.php
@@ -5,23 +5,22 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-script-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-script-query.html
* @see ScriptMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class ScriptMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var ScriptInterface */
- protected $script;
-
- public function __construct(ScriptInterface $script)
- {
- $this->script = $script;
+ public function __construct(
+ protected ScriptInterface $script,
+ ) {
}
public function __clone()
@@ -30,9 +29,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['script'] = $this->script->jsonSerialize();
diff --git a/src/Matcher/Specialized/TemplateMatcher.php b/src/Matcher/Specialized/TemplateMatcher.php
deleted file mode 100644
index 706d074..0000000
--- a/src/Matcher/Specialized/TemplateMatcher.php
+++ /dev/null
@@ -1,66 +0,0 @@
- '?',
- */
-class TemplateMatcher implements MatcherInterface
-{
- use HasOptionsTrait;
-
- /** @var array */
- protected $body;
-
- /** @var array */
- protected $params;
-
- protected function __construct(array $body, array $params)
- {
- $this->body = $body;
- $this->params = $params;
- }
-
- /**
- * @param MatcherInterface|string $source
- * @param array $params
- *
- * @return TemplateMatcher
- */
- public static function fromSource($source, array $params): TemplateMatcher
- {
- $rawSource = $source instanceof MatcherInterface ? $source->jsonSerialize() : $source;
-
- return new static(['source' => $rawSource], $params);
- }
-
- public static function fromId(string $templateId, array $params): TemplateMatcher
- {
- return new static(['id' => $templateId], $params);
- }
-
- public static function fromFile(string $file, array $params): TemplateMatcher
- {
- return new static(['file' => $file], $params);
- }
-
- /**
- * @inheritdoc
- */
- public function jsonSerialize()
- {
- $body = $this->body;
- $body['params'] = $this->params;
- $this->options += $this->options;
-
- return [
- 'template' => $body,
- ];
- }
-}
diff --git a/src/Matcher/Specialized/WrapperMatcher.php b/src/Matcher/Specialized/WrapperMatcher.php
new file mode 100644
index 0000000..80db0c6
--- /dev/null
+++ b/src/Matcher/Specialized/WrapperMatcher.php
@@ -0,0 +1,38 @@
+ '?',
+])]
+class WrapperMatcher implements MatcherInterface
+{
+ use HasOptionsTrait;
+
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $queryString,
+ array $options = [],
+ ) {
+ $this->options = $options;
+ }
+
+ public function jsonSerialize(): mixed
+ {
+ $body = [];
+ $body['query'] = $this->queryString;
+ $body += $this->options;
+
+ return ['wrapper' => $body];
+ }
+}
diff --git a/src/Matcher/TermLevel/ExistsMatcher.php b/src/Matcher/TermLevel/ExistsMatcher.php
index d41b334..37b78a8 100644
--- a/src/Matcher/TermLevel/ExistsMatcher.php
+++ b/src/Matcher/TermLevel/ExistsMatcher.php
@@ -4,29 +4,28 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-exists-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-exists-query.html
* @see ExistsMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class ExistsMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field)
- {
- $this->field = $field;
+ public function __construct(
+ protected string $field,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['field'] = $this->field;
diff --git a/src/Matcher/TermLevel/FuzzyMatcher.php b/src/Matcher/TermLevel/FuzzyMatcher.php
index 610d1e1..5089edb 100644
--- a/src/Matcher/TermLevel/FuzzyMatcher.php
+++ b/src/Matcher/TermLevel/FuzzyMatcher.php
@@ -4,38 +4,39 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MultiTermMatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-fuzzy-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-fuzzy-query.html
* @see FuzzyMatcherTest
- *
- * @options 'boost' => 2.0,
- * 'fuzziness' => 'AUTO', 5,
- * 'prefix_length' => 0,
- * 'max_expansions' => 50,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 2.0,
+ 'fuzziness' => 'AUTO', // 5,
+ 'prefix_length' => 0,
+ 'max_expansions' => 50,
+ 'transpositions' => false,
+ '_name' => '?',
+])]
class FuzzyMatcher implements MultiTermMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $value;
-
- public function __construct(string $field, string $value, array $options = [])
- {
- $this->field = $field;
- $this->value = $value;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $value,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (!empty($this->options)) {
$body = [];
diff --git a/src/Matcher/TermLevel/IdsMatcher.php b/src/Matcher/TermLevel/IdsMatcher.php
index 5015ddf..bfa657c 100644
--- a/src/Matcher/TermLevel/IdsMatcher.php
+++ b/src/Matcher/TermLevel/IdsMatcher.php
@@ -4,37 +4,30 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-ids-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-ids-query.html
* @see IdsMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class IdsMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string[] */
- protected $ids;
-
- /** @var string|null */
- protected $type;
-
- /**
- * @param string[] $ids
- * @param string|null $type
- */
- public function __construct(array $ids, string $type = null)
- {
- $this->ids = $ids;
- $this->type = $type;
+ public function __construct(
+ /** @var string[] */
+ protected array $ids,
+ protected ?string $type = null,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['values'] = $this->ids;
diff --git a/src/Matcher/TermLevel/LookupTermsMatcher.php b/src/Matcher/TermLevel/LookupTermsMatcher.php
index 7efc93e..dffe51a 100644
--- a/src/Matcher/TermLevel/LookupTermsMatcher.php
+++ b/src/Matcher/TermLevel/LookupTermsMatcher.php
@@ -4,55 +4,33 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-terms-query.html#query-dsl-terms-lookup
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-terms-query.html#query-dsl-terms-lookup
* @see LookupTermsMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class LookupTermsMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $index;
-
- /** @var string */
- protected $type;
-
- /** @var string */
- protected $id;
-
- /** @var string */
- protected $path;
-
- /** @var string|null */
- protected $routing = null;
-
public function __construct(
- string $field,
- string $index,
- string $type,
- string $id,
- string $path,
- string $routing = null
+ protected string $field,
+ protected string $index,
+ protected string $type,
+ protected string $id,
+ protected string $path,
+ protected ?string $routing = null,
) {
- $this->field = $field;
- $this->index = $index;
- $this->type = $type;
- $this->id = $id;
- $this->path = $path;
- $this->routing = $routing;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body[$this->field] = [
diff --git a/src/Matcher/TermLevel/MissingMatcher.php b/src/Matcher/TermLevel/MissingMatcher.php
index 8a98423..85ba072 100644
--- a/src/Matcher/TermLevel/MissingMatcher.php
+++ b/src/Matcher/TermLevel/MissingMatcher.php
@@ -4,29 +4,31 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-exists-query.html#_literal_missing_literal_query
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-exists-query.html#_literal_missing_literal_query
* @see MissingMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class MissingMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field)
- {
- $this->field = $field;
+ /** @param array $options */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
+ $this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['must_not']['exists']['field'] = $this->field;
diff --git a/src/Matcher/TermLevel/PrefixMatcher.php b/src/Matcher/TermLevel/PrefixMatcher.php
index b1f7861..d42d2cb 100644
--- a/src/Matcher/TermLevel/PrefixMatcher.php
+++ b/src/Matcher/TermLevel/PrefixMatcher.php
@@ -4,35 +4,35 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MultiTermMatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-prefix-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-prefix-query.html
* @see PrefixMatcherTest
- *
- * @options 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ '_name' => '?',
+])]
class PrefixMatcher implements MultiTermMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $prefix;
-
- public function __construct(string $field, string $prefix, array $options = [])
- {
- $this->field = $field;
- $this->prefix = $prefix;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $prefix,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (!empty($this->options)) {
$body = [];
diff --git a/src/Matcher/TermLevel/RangeMatcher.php b/src/Matcher/TermLevel/RangeMatcher.php
index 64b19c2..e8507ce 100644
--- a/src/Matcher/TermLevel/RangeMatcher.php
+++ b/src/Matcher/TermLevel/RangeMatcher.php
@@ -4,46 +4,40 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MultiTermMatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/range.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-range-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/range.html
* @see RangeMatcherTest
- *
- * @options 'boost' => 2.0,
- * 'format' => 'dd/MM/yyyy||yyyy'
- * 'time_zone' => '+01:00',
- * 'relation' => 'WITHIN', 'INTERSECTS', 'CONTAINS',
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 2.0,
+ 'format' => 'dd/MM/yyyy||yyyy',
+ 'time_zone' => '+01:00',
+ 'relation' => 'WITHIN', // 'INTERSECTS', 'CONTAINS',
+ '_name' => '?',
+])]
class RangeMatcher implements MultiTermMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
/**
- * 'gt' => 5,
- * 'gte' => 5,
- * 'lt' => 5,
- * 'lte' => 5,
- *
- * @var array
+ * @param array $options
*/
- protected $range;
-
- public function __construct(string $field, array $range, array $options = [])
- {
- $this->field = $field;
- $this->range = $range;
+ public function __construct(
+ protected string $field,
+ /** @var array ['gt' => 5, 'gte' => 5, 'lt' => 5, 'lte' => 5] */
+ protected array $range,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = $this->range;
$body += $this->options;
diff --git a/src/Matcher/TermLevel/RegexMatcher.php b/src/Matcher/TermLevel/RegexpMatcher.php
similarity index 53%
rename from src/Matcher/TermLevel/RegexMatcher.php
rename to src/Matcher/TermLevel/RegexpMatcher.php
index d9b4d1f..49d9b57 100644
--- a/src/Matcher/TermLevel/RegexMatcher.php
+++ b/src/Matcher/TermLevel/RegexpMatcher.php
@@ -4,36 +4,37 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MultiTermMatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-regexp-query.html
- * @see RegexMatcherTest
- *
- * @options 'flags' => 'ALL|ANYSTRING|COMPLEMENT|EMPTY|INTERSECTION|INTERVAL|NONE',
- * 'max_determinized_states' => 2000,
- * '_name' => '?',
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-regexp-query.html
+ * @see RegexpMatcherTest
*/
-class RegexMatcher implements MultiTermMatcherInterface
+#[Options([
+ 'flags' => 'ALL|ANYSTRING|COMPLEMENT|EMPTY|INTERSECTION|INTERVAL|NONE',
+ 'max_determinized_states' => 2000,
+ 'boost' => 2,
+ '_name' => '?',
+])]
+class RegexpMatcher implements MultiTermMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $regex;
-
- public function __construct(string $field, string $regex, array $options = [])
- {
- $this->field = $field;
- $this->regex = $regex;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $regex,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (!empty($this->options)) {
$body = [];
diff --git a/src/Matcher/TermLevel/TermMatcher.php b/src/Matcher/TermLevel/TermMatcher.php
index b50bfe6..83292c9 100644
--- a/src/Matcher/TermLevel/TermMatcher.php
+++ b/src/Matcher/TermLevel/TermMatcher.php
@@ -4,40 +4,35 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-term-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-term-query.html
* @see TermMatcherTest
- *
- * @options 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ '_name' => '?',
+])]
class TermMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string|float|int|bool|null */
- protected $value;
-
/**
- * @param string $field
- * @param string|float|int|bool|null $value
- * @param array $options
+ * @param array $options
*/
- public function __construct(string $field, $value, array $options = [])
- {
- $this->field = $field;
- $this->value = $value;
+ public function __construct(
+ protected string $field,
+ protected string|float|int|bool|null $value,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (!empty($this->options)) {
$body = [];
diff --git a/src/Matcher/TermLevel/TermsMatcher.php b/src/Matcher/TermLevel/TermsMatcher.php
index ed145ab..a66a250 100644
--- a/src/Matcher/TermLevel/TermsMatcher.php
+++ b/src/Matcher/TermLevel/TermsMatcher.php
@@ -4,34 +4,36 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
* @see LookupTermsMatcher
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-terms-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-terms-query.html
* @see TermsMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class TermsMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string[]|float[]|int[]|bool[]|null[]|null */
- protected $values;
-
- public function __construct(string $field, array $values)
- {
- $this->field = $field;
- $this->values = $values;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ /** @var string[]|float[]|int[]|bool[]|null[] */
+ protected array $values,
+ array $options = [],
+ ) {
+ $this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body[$this->field] = $this->values;
diff --git a/src/Matcher/TermLevel/TermsSetMatcher.php b/src/Matcher/TermLevel/TermsSetMatcher.php
new file mode 100644
index 0000000..af5bb2f
--- /dev/null
+++ b/src/Matcher/TermLevel/TermsSetMatcher.php
@@ -0,0 +1,61 @@
+ '?',
+])]
+class TermsSetMatcher implements MatcherInterface
+{
+ use HasOptionsTrait;
+
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ /** @var string[]|float[]|int[]|bool[]|null[] */
+ protected array $values,
+ protected string|ScriptInterface $msmFieldOrScript,
+ array $options = [],
+ ) {
+ $this->options = $options;
+ }
+
+ public function __clone()
+ {
+ if (is_object($this->msmFieldOrScript)) {
+ $this->msmFieldOrScript = clone $this->msmFieldOrScript;
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function jsonSerialize(): mixed
+ {
+ $body = [];
+ $body[$this->field] = [
+ 'terms' => $this->values,
+ ];
+ if ($this->msmFieldOrScript instanceof ScriptInterface) {
+ $body[$this->field]['minimum_should_match_script'] = $this->msmFieldOrScript->jsonSerialize();
+ } else {
+ $body[$this->field]['minimum_should_match_field'] = $this->msmFieldOrScript;
+ }
+ $body += $this->options;
+
+ return [
+ 'terms_set' => $body,
+ ];
+ }
+}
diff --git a/src/Matcher/TermLevel/TypeMatcher.php b/src/Matcher/TermLevel/TypeMatcher.php
index 723c60d..f528930 100644
--- a/src/Matcher/TermLevel/TypeMatcher.php
+++ b/src/Matcher/TermLevel/TypeMatcher.php
@@ -4,29 +4,33 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-type-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-type-query.html
* @see TypeMatcherTest
- *
- * @options '_name' => '?',
*/
+#[Options([
+ '_name' => '?',
+])]
class TypeMatcher implements MatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $docType;
-
- public function __construct(string $docType)
- {
- $this->docType = $docType;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $docType,
+ array $options = [],
+ ) {
+ $this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['value'] = $this->docType;
diff --git a/src/Matcher/TermLevel/WildcardMatcher.php b/src/Matcher/TermLevel/WildcardMatcher.php
index 4c08ee7..d2d812b 100644
--- a/src/Matcher/TermLevel/WildcardMatcher.php
+++ b/src/Matcher/TermLevel/WildcardMatcher.php
@@ -4,35 +4,37 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MultiTermMatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-wildcard-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-wildcard-query.html
* @see WildcardMatcherTest
- *
- * @options 'boost' => 1.0,
- * '_name' => '?',
*/
+#[Options([
+ 'boost' => 1.0,
+ '_name' => '?',
+ 'rewrite' => 'constant_score', // 'scoring_boolean', 'constant_score_boolean', 'top_terms_N',
+ // 'top_terms_boost_N', 'top_terms_blended_freqs_N',
+])]
class WildcardMatcher implements MultiTermMatcherInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $value;
-
- public function __construct(string $field, string $value, array $options = [])
- {
- $this->field = $field;
- $this->value = $value;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $value,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
if (!empty($this->options)) {
$body = [];
diff --git a/src/Model/GeoHash.php b/src/Model/GeoHash.php
index ffe7f5c..2b91751 100644
--- a/src/Model/GeoHash.php
+++ b/src/Model/GeoHash.php
@@ -7,12 +7,8 @@
*/
class GeoHash implements GeoPointInterface
{
- /** @var string */
- protected $value;
-
- public function __construct(string $value)
+ public function __construct(protected string $value)
{
- $this->value = $value;
}
public function getValue(): string
@@ -26,9 +22,9 @@ public function __toString(): string
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return $this->value;
}
diff --git a/src/Model/GeoPoint.php b/src/Model/GeoPoint.php
index 7c46c42..8785245 100644
--- a/src/Model/GeoPoint.php
+++ b/src/Model/GeoPoint.php
@@ -7,32 +7,26 @@
*/
class GeoPoint implements GeoPointInterface
{
- /** @var float */
- protected $lat;
-
- /** @var float */
- protected $lon;
-
- public function __construct(float $lat, float $lon)
- {
- $this->lat = $lat;
- $this->lon = $lon;
+ public function __construct(
+ protected float|string $lat,
+ protected float|string $lon,
+ ) {
}
- public function getLat(): float
+ public function getLat(): float|string
{
return $this->lat;
}
- public function getLon(): float
+ public function getLon(): float|string
{
return $this->lon;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return [
'lat' => $this->lat,
diff --git a/src/Model/GeoShape/GeoShapeInterface.php b/src/Model/GeoShape/GeoShapeInterface.php
index 6065707..f3625e3 100644
--- a/src/Model/GeoShape/GeoShapeInterface.php
+++ b/src/Model/GeoShape/GeoShapeInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/geo-shape.html#input-structure
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/geo-shape.html#input-structure
*/
interface GeoShapeInterface extends JsonSerializable
{
diff --git a/src/Model/GeoShape/IndexedGeoShape.php b/src/Model/GeoShape/IndexedGeoShape.php
index 1509509..85fe338 100644
--- a/src/Model/GeoShape/IndexedGeoShape.php
+++ b/src/Model/GeoShape/IndexedGeoShape.php
@@ -3,35 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Model\GeoShape;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-geo-shape-query.html#_pre_indexed_shape
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-geo-shape-query.html#_pre_indexed_shape
* @see IndexedGeoShapeTest
*/
class IndexedGeoShape implements GeoShapeInterface
{
- /** @var string */
- protected $index;
-
- /** @var string */
- protected $type;
-
- /** @var string */
- protected $id;
-
- /** @var string */
- protected $path;
-
- public function __construct(string $index, string $type, string $id, string $path)
- {
- $this->index = $index;
- $this->type = $type;
- $this->id = $id;
- $this->path = $path;
+ public function __construct(
+ protected string $index,
+ protected string $type,
+ protected string $id,
+ protected string $path,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return [
'index' => $this->index,
diff --git a/src/Model/GeoShape/RawGeoShape.php b/src/Model/GeoShape/RawGeoShape.php
index a45d1b2..2e99e85 100644
--- a/src/Model/GeoShape/RawGeoShape.php
+++ b/src/Model/GeoShape/RawGeoShape.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/geo-shape.html#input-structure
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/geo-shape.html#input-structure
* @see RawGeoShapeTest
*/
class RawGeoShape extends RawFragment implements GeoShapeInterface
diff --git a/src/Model/Script/FileScript.php b/src/Model/Script/FileScript.php
index 13585e2..4da4234 100644
--- a/src/Model/Script/FileScript.php
+++ b/src/Model/Script/FileScript.php
@@ -3,31 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Model\Script;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-using.html#modules-scripting-file-scripts
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting-using.html#modules-scripting-file-scripts
* @see FileScriptTest
*/
class FileScript implements ScriptInterface
{
- /** @var string */
- protected $file;
-
- /** @var array */
- protected $params;
-
- /** @var string|null */
- protected $lang;
-
- public function __construct(string $file, array $params = [], string $lang = null)
- {
- $this->file = $file;
- $this->params = $params;
- $this->lang = $lang;
+ public function __construct(
+ protected string $file,
+ /** @var array */
+ protected array $params = [],
+ protected ?string $lang = null,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['file'] = $this->file;
diff --git a/src/Model/Script/IndexedScript.php b/src/Model/Script/IndexedScript.php
index 8859ed3..65e4d2c 100644
--- a/src/Model/Script/IndexedScript.php
+++ b/src/Model/Script/IndexedScript.php
@@ -3,27 +3,22 @@
namespace Gskema\ElasticSearchQueryDSL\Model\Script;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-using.html#modules-scripting-stored-scripts
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting-using.html#modules-scripting-stored-scripts
* @see IndexedScriptTest
*/
class IndexedScript implements ScriptInterface
{
- /** @var string */
- protected $id;
-
- /** @var array */
- protected $params;
-
- public function __construct(string $id, array $params = [])
- {
- $this->id = $id;
- $this->params = $params;
+ public function __construct(
+ protected string $id,
+ /** @var array */
+ protected array $params = [],
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['id'] = $this->id;
diff --git a/src/Model/Script/InlineScript.php b/src/Model/Script/InlineScript.php
index 1c41e6b..1ee9bcc 100644
--- a/src/Model/Script/InlineScript.php
+++ b/src/Model/Script/InlineScript.php
@@ -3,31 +3,23 @@
namespace Gskema\ElasticSearchQueryDSL\Model\Script;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-using.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting-using.html
* @see InlineScriptTest
*/
class InlineScript implements ScriptInterface
{
- /** @var string */
- protected $source;
-
- /** @var array */
- protected $params;
-
- /** @var string */
- protected $lang;
-
- public function __construct(string $source, array $params = [], string $lang = null)
- {
- $this->source = $source;
- $this->params = $params;
- $this->lang = $lang;
+ public function __construct(
+ protected string $source,
+ /** @var array */
+ protected array $params = [],
+ protected ?string $lang = null,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (null !== $this->lang) {
@@ -38,8 +30,6 @@ public function jsonSerialize()
$body['params'] = $this->params;
}
- $body = 1 === count($body) ? $body['source'] : $body;
-
- return $body;
+ return 1 === count($body) ? $body['source'] : $body;
}
}
diff --git a/src/Model/Script/RawScript.php b/src/Model/Script/RawScript.php
index 9a53303..a284033 100644
--- a/src/Model/Script/RawScript.php
+++ b/src/Model/Script/RawScript.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-using.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting-using.html
* @see RawScriptTest
*/
class RawScript extends RawFragment implements ScriptInterface
diff --git a/src/Model/Script/ScriptInterface.php b/src/Model/Script/ScriptInterface.php
index 21b98ee..da95165 100644
--- a/src/Model/Script/ScriptInterface.php
+++ b/src/Model/Script/ScriptInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-scripting-using.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/modules-scripting-using.html
*/
interface ScriptInterface extends JsonSerializable
{
diff --git a/src/Options.php b/src/Options.php
new file mode 100644
index 0000000..266d697
--- /dev/null
+++ b/src/Options.php
@@ -0,0 +1,15 @@
+ */
+ public readonly array $options,
+ ) {
+ }
+}
diff --git a/src/Parameters.php b/src/Parameters.php
new file mode 100644
index 0000000..43f83da
--- /dev/null
+++ b/src/Parameters.php
@@ -0,0 +1,15 @@
+ */
+ public readonly array $parameters,
+ ) {
+ }
+}
diff --git a/src/RawFragment.php b/src/RawFragment.php
index a58d9f1..e1e69a7 100644
--- a/src/RawFragment.php
+++ b/src/RawFragment.php
@@ -9,15 +9,8 @@
*/
class RawFragment implements JsonSerializable
{
- /** @var mixed */
- protected $body;
-
- /**
- * @param mixed $body
- */
- public function __construct($body)
+ public function __construct(protected mixed $body)
{
- $this->body = $body;
}
public function __clone()
@@ -30,9 +23,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return $this->body;
}
diff --git a/src/Rescorer/QueryRescorer.php b/src/Rescorer/QueryRescorer.php
index d495f9f..ea6723e 100644
--- a/src/Rescorer/QueryRescorer.php
+++ b/src/Rescorer/QueryRescorer.php
@@ -5,29 +5,20 @@
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-rescore.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-rescore.html
* @see QueryRescorerTest
*/
class QueryRescorer implements RescorerInterface
{
- /** @var MatcherInterface */
- protected $query;
-
- /** @var float|null */
- protected $queryWeight;
-
- /** @var float|null */
- protected $rescoreQueryWeight;
-
- /** @var string|null 'total', 'multiply', 'avg', 'max', 'min' */
- protected $scoreMode;
-
- /** @var int|null */
- protected $windowSize;
-
- public function __construct(MatcherInterface $query)
- {
- $this->query = $query;
+ protected ?float $queryWeight = null;
+ protected ?float $rescoreQueryWeight = null;
+ /** 'total', 'multiply', 'avg', 'max', 'min' */
+ protected ?string $scoreMode = null;
+ protected ?int $windowSize = null;
+
+ public function __construct(
+ protected MatcherInterface $query,
+ ) {
}
public function __clone()
@@ -40,90 +31,54 @@ public function getQuery(): MatcherInterface
return $this->query;
}
- /**
- * @return float|null
- */
- public function getQueryWeight()
+ public function getQueryWeight(): ?float
{
return $this->queryWeight;
}
- /**
- * @param float|null $queryWeight
- *
- * @return $this
- */
- public function setQueryWeight(float $queryWeight): QueryRescorer
+ public function setQueryWeight(?float $queryWeight): static
{
$this->queryWeight = $queryWeight;
-
return $this;
}
- /**
- * @return float|null
- */
- public function getRescoreQueryWeight()
+ public function getRescoreQueryWeight(): ?float
{
return $this->rescoreQueryWeight;
}
- /**
- * @param float|null $rescoreQueryWeight
- *
- * @return $this
- */
- public function setRescoreQueryWeight(float $rescoreQueryWeight): QueryRescorer
+ public function setRescoreQueryWeight(?float $rescoreQueryWeight): static
{
$this->rescoreQueryWeight = $rescoreQueryWeight;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getScoreMode()
+ public function getScoreMode(): ?string
{
return $this->scoreMode;
}
- /**
- * @param string|null $scoreMode
- *
- * @return $this
- */
- public function setScoreMode(string $scoreMode = null): QueryRescorer
+ public function setScoreMode(?string $scoreMode): static
{
$this->scoreMode = $scoreMode;
-
return $this;
}
- /**
- * @return int|null
- */
- public function getWindowSize()
+ public function getWindowSize(): ?int
{
return $this->windowSize;
}
- /**
- * @param int|null $windowSize
- *
- * @return $this
- */
- public function setWindowSize(int $windowSize = null): QueryRescorer
+ public function setWindowSize(?int $windowSize): static
{
$this->windowSize = $windowSize;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (null !== $this->windowSize) {
diff --git a/src/Rescorer/RawRescorer.php b/src/Rescorer/RawRescorer.php
index 88ac142..3ad6014 100644
--- a/src/Rescorer/RawRescorer.php
+++ b/src/Rescorer/RawRescorer.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-rescore.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-rescore.html
* @see RawRescorerTest
*/
class RawRescorer extends RawFragment implements RescorerInterface
diff --git a/src/Rescorer/RescorerInterface.php b/src/Rescorer/RescorerInterface.php
index 154c3ee..2cbcd82 100644
--- a/src/Rescorer/RescorerInterface.php
+++ b/src/Rescorer/RescorerInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-rescore.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-rescore.html
*/
interface RescorerInterface extends JsonSerializable
{
diff --git a/src/ScoreFunction/AbstractDecayScoreFunction.php b/src/ScoreFunction/AbstractDecayScoreFunction.php
index f085a04..b977bdb 100644
--- a/src/ScoreFunction/AbstractDecayScoreFunction.php
+++ b/src/ScoreFunction/AbstractDecayScoreFunction.php
@@ -2,47 +2,47 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#_supported_decay_functions
- *
- * @options 'offset' => 0,
- * 'decay' => 0.5,
- * 'multi_value_mode' => 'min', 'max', 'avg', 'sum',
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_supported_decay_functions
*/
+#[Options([
+ 'offset' => 0,
+ 'decay' => 0.5,
+ 'multi_value_mode' => 'min', // 'max', 'avg', 'sum',
+])]
abstract class AbstractDecayScoreFunction implements ScoreFunctionInterface
{
- use HasOptionsTrait;
-
- /** @var string */
- protected $field;
-
- /** @var string|float|int */
- protected $origin;
-
- /** @var string|float|int */
- protected $scale;
-
- public function __construct(string $field, $origin, $scale, array $options = [])
- {
- $this->field = $field;
- $this->origin = $origin;
- $this->scale = $scale;
- $this->options = $options;
+ public function __construct(
+ protected string $field,
+ protected string|float|int $origin,
+ protected string|float|int $scale,
+ protected string|float|int|null $offset = null,
+ protected string|float|int|null $decay = null,
+ protected ?string $multiValueMode = null, // 'min', 'max', 'avg', 'sum'
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [
'field' => $this->field,
'origin' => $this->origin,
'scale' => $this->scale,
];
- $body += $this->options;
+ if (null !== $this->offset) {
+ $body['offset'] = $this->offset;
+ }
+ if (null !== $this->decay) {
+ $body['decay'] = $this->decay;
+ }
+ if (null !== $this->multiValueMode) {
+ $body['multi_value_mode'] = $this->multiValueMode;
+ }
return [
$this->getFunctionType() => $body,
diff --git a/src/ScoreFunction/ExpDecayScoreFunction.php b/src/ScoreFunction/ExpDecayScoreFunction.php
index 2791fda..0685f56 100644
--- a/src/ScoreFunction/ExpDecayScoreFunction.php
+++ b/src/ScoreFunction/ExpDecayScoreFunction.php
@@ -2,18 +2,21 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#_supported_decay_functions
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_supported_decay_functions
* @see ExpDecayScoreFunctionTest
- *
- * @options 'offset' => 0,
- * 'decay' => 0.5,
- * 'multi_value_mode' => 'min', 'max', 'avg', 'sum',
*/
+#[Options([
+ 'offset' => 0,
+ 'decay' => 0.5,
+ 'multi_value_mode' => 'min', // 'max', 'avg', 'sum',
+])]
class ExpDecayScoreFunction extends AbstractDecayScoreFunction
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getFunctionType(): string
{
diff --git a/src/ScoreFunction/FieldValueFactorScoreFunction.php b/src/ScoreFunction/FieldValueFactorScoreFunction.php
index e77af0d..7623df3 100644
--- a/src/ScoreFunction/FieldValueFactorScoreFunction.php
+++ b/src/ScoreFunction/FieldValueFactorScoreFunction.php
@@ -2,37 +2,36 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
-
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#function-field-value-factor
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#function-field-value-factor
* @see FieldValueFactorScoreFunctionTest
- *
- * @options 'factor' => 1,
- * 'modifier' => 'none', 'log', 'log1p', 'log2p', 'ln', 'ln1p', 'ln2p', 'square', 'sqrt', 'reciprocal',
- * 'missing' => 0,
*/
class FieldValueFactorScoreFunction implements ScoreFunctionInterface
{
- use HasOptionsTrait;
-
- /** @var string */
- protected $field;
-
- public function __construct(string $field, array $options = [])
- {
- $this->field = $field;
- $this->options = $options;
+ public function __construct(
+ protected string $field,
+ protected ?float $factor = null,
+ protected ?string $modifier = null, // none, log, log1p, log2p, ln, ln1p, ln2p, square, sqrt, reciprocal
+ protected float|int|null $missing = null,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['field'] = $this->field;
- $body += $this->options;
+ if (null !== $this->factor) {
+ $body['factor'] = $this->factor;
+ }
+ if (null !== $this->modifier) {
+ $body['modifier'] = $this->modifier;
+ }
+ if (null !== $this->missing) {
+ $body['missing'] = $this->missing;
+ }
return [
'field_value_factor' => $body,
diff --git a/src/ScoreFunction/GaussDecayScoreFunction.php b/src/ScoreFunction/GaussDecayScoreFunction.php
index e26e69b..12f6971 100644
--- a/src/ScoreFunction/GaussDecayScoreFunction.php
+++ b/src/ScoreFunction/GaussDecayScoreFunction.php
@@ -2,18 +2,21 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#_supported_decay_functions
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_supported_decay_functions
* @see GaussDecayScoreFunctionTest
- *
- * @options 'offset' => 0,
- * 'decay' => 0.5,
- * 'multi_value_mode' => 'min', 'max', 'avg', 'sum',
*/
+#[Options([
+ 'offset' => 0,
+ 'decay' => 0.5,
+ 'multi_value_mode' => 'min', // 'max', 'avg', 'sum',
+])]
class GaussDecayScoreFunction extends AbstractDecayScoreFunction
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getFunctionType(): string
{
diff --git a/src/ScoreFunction/LinearDecayScoreFunction.php b/src/ScoreFunction/LinearDecayScoreFunction.php
index a4d51ea..711c60c 100644
--- a/src/ScoreFunction/LinearDecayScoreFunction.php
+++ b/src/ScoreFunction/LinearDecayScoreFunction.php
@@ -2,18 +2,21 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
+use Gskema\ElasticSearchQueryDSL\Options;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#_supported_decay_functions
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#_supported_decay_functions
* @see LinearDecayScoreFunctionTest
- *
- * @options 'offset' => 0,
- * 'decay' => 0.5,
- * 'multi_value_mode' => 'min', 'max', 'avg', 'sum',
*/
+#[Options([
+ 'offset' => 0,
+ 'decay' => 0.5,
+ 'multi_value_mode' => 'min', // 'max', 'avg', 'sum',
+])]
class LinearDecayScoreFunction extends AbstractDecayScoreFunction
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
protected function getFunctionType(): string
{
diff --git a/src/ScoreFunction/RandomScoreFunction.php b/src/ScoreFunction/RandomScoreFunction.php
index dc14bc3..f71c7a2 100644
--- a/src/ScoreFunction/RandomScoreFunction.php
+++ b/src/ScoreFunction/RandomScoreFunction.php
@@ -5,33 +5,32 @@
use stdClass;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#function-random
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#function-random
* @see RandomScoreFunctionTest
*/
class RandomScoreFunction implements ScoreFunctionInterface
{
- /** @var int|null */
- protected $seed;
-
- public function __construct(int $seed = null)
- {
- $this->seed = $seed;
+ public function __construct(
+ protected ?int $seed = null,
+ protected ?string $field = null,
+ ) {
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
+ $body = [];
if (null !== $this->seed) {
- $body = [];
$body['seed'] = $this->seed;
- } else {
- $body = new stdClass();
+ }
+ if (null !== $this->field) {
+ $body['field'] = $this->field;
}
return [
- 'random_score' => $body,
+ 'random_score' => $body ?: new stdClass(),
];
}
}
diff --git a/src/ScoreFunction/RawScoreFunction.php b/src/ScoreFunction/RawScoreFunction.php
index c7a0f06..a46ba7d 100644
--- a/src/ScoreFunction/RawScoreFunction.php
+++ b/src/ScoreFunction/RawScoreFunction.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html
* @see RawScoreFunctionTest
*/
class RawScoreFunction extends RawFragment implements ScoreFunctionInterface
diff --git a/src/ScoreFunction/ScoreFunctionInterface.php b/src/ScoreFunction/ScoreFunctionInterface.php
index 55b9a60..945ef39 100644
--- a/src/ScoreFunction/ScoreFunctionInterface.php
+++ b/src/ScoreFunction/ScoreFunctionInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#score-functions
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#score-functions
*/
interface ScoreFunctionInterface extends JsonSerializable
{
diff --git a/src/ScoreFunction/ScriptScoreFunction.php b/src/ScoreFunction/ScriptScoreFunction.php
index f71dd51..fd97095 100644
--- a/src/ScoreFunction/ScriptScoreFunction.php
+++ b/src/ScoreFunction/ScriptScoreFunction.php
@@ -4,23 +4,26 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#function-script-score
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#function-script-score
* @see ScriptScoreFunctionTest
- *
- * @options 'boost_mode' => 'replace'
*/
+#[Options([
+ 'boost_mode' => 'replace'
+])]
class ScriptScoreFunction implements ScoreFunctionInterface
{
use HasOptionsTrait;
- /** @var ScriptInterface */
- protected $script;
-
- public function __construct(ScriptInterface $script, array $options = [])
- {
- $this->script = $script;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected ScriptInterface $script,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -30,9 +33,9 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['script'] = $this->script->jsonSerialize();
diff --git a/src/ScoreFunction/WeightScoreFunction.php b/src/ScoreFunction/WeightScoreFunction.php
index 141cf54..b923b17 100644
--- a/src/ScoreFunction/WeightScoreFunction.php
+++ b/src/ScoreFunction/WeightScoreFunction.php
@@ -3,13 +3,12 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-function-score-query.html#function-weight
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-function-score-query.html#function-weight
* @see WeightScoreFunctionTest
*/
class WeightScoreFunction implements ScoreFunctionInterface
{
- /** @var float */
- protected $weight;
+ protected float $weight;
public function __construct(float $weight)
{
@@ -17,9 +16,9 @@ public function __construct(float $weight)
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return [
'weight' => $this->weight,
diff --git a/src/SearchRequest/HasDocValueFieldsTrait.php b/src/SearchRequest/HasDocValueFieldsTrait.php
index 66a3c8f..f585574 100644
--- a/src/SearchRequest/HasDocValueFieldsTrait.php
+++ b/src/SearchRequest/HasDocValueFieldsTrait.php
@@ -3,13 +3,13 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-docvalue-fields.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-docvalue-fields.html
* @see HasDocValueFieldsTraitTest
*/
trait HasDocValueFieldsTrait
{
/** @var string[] */
- protected $docValueFields = [];
+ protected array $docValueFields = [];
/**
* @return string[]
@@ -21,13 +21,10 @@ public function getDocValueFields(): array
/**
* @param string[] $docValueFields
- *
- * @return $this
*/
- public function setDocValueFields(array $docValueFields)
+ public function setDocValueFields(array $docValueFields): static
{
$this->docValueFields = $docValueFields;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasFieldCollapserTrait.php b/src/SearchRequest/HasFieldCollapserTrait.php
index e0af6fd..04abbfc 100644
--- a/src/SearchRequest/HasFieldCollapserTrait.php
+++ b/src/SearchRequest/HasFieldCollapserTrait.php
@@ -5,31 +5,21 @@
use Gskema\ElasticSearchQueryDSL\FieldCollapser\FieldCollapserInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-collapse.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-collapse.html
* @see HasFieldCollapserTraitTest
*/
trait HasFieldCollapserTrait
{
- /** @var FieldCollapserInterface|null */
- protected $fieldCollapser;
+ protected ?FieldCollapserInterface $fieldCollapser = null;
- /**
- * @return FieldCollapserInterface|null
- */
- public function getFieldCollapser()
+ public function getFieldCollapser(): ?FieldCollapserInterface
{
return $this->fieldCollapser;
}
- /**
- * @param FieldCollapserInterface|null $fieldCollapser
- *
- * @return $this
- */
- public function setFieldCollapser(FieldCollapserInterface $fieldCollapser = null)
+ public function setFieldCollapser(?FieldCollapserInterface $fieldCollapser): static
{
$this->fieldCollapser = $fieldCollapser;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasFromTrait.php b/src/SearchRequest/HasFromTrait.php
index c7c2d37..e97b9ee 100644
--- a/src/SearchRequest/HasFromTrait.php
+++ b/src/SearchRequest/HasFromTrait.php
@@ -3,31 +3,21 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-from-size.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-from-size.html
* @see HasFromTraitTest
*/
trait HasFromTrait
{
- /** @var int|null */
- protected $from;
+ protected ?int $from = null;
- /**
- * @return int|null
- */
- public function getFrom()
+ public function getFrom(): ?int
{
return $this->from;
}
- /**
- * @param int|null $from
- *
- * @return $this
- */
- public function setFrom(int $from = null)
+ public function setFrom(?int $from): static
{
$this->from = $from;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasHighlighterTrait.php b/src/SearchRequest/HasHighlighterTrait.php
index d13f44b..f21c8b7 100644
--- a/src/SearchRequest/HasHighlighterTrait.php
+++ b/src/SearchRequest/HasHighlighterTrait.php
@@ -5,31 +5,21 @@
use Gskema\ElasticSearchQueryDSL\Highlighter\HighlighterInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-highlighting.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html
* @see HasHighlighterTraitTest
*/
trait HasHighlighterTrait
{
- /** @var HighlighterInterface|null */
- protected $highlighter;
+ protected ?HighlighterInterface $highlighter = null;
- /**
- * @return HighlighterInterface|null
- */
- public function getHighlighter()
+ public function getHighlighter(): ?HighlighterInterface
{
return $this->highlighter;
}
- /**
- * @param HighlighterInterface|null $highlighter
- *
- * @return $this
- */
- public function setHighlighter(HighlighterInterface $highlighter = null)
+ public function setHighlighter(?HighlighterInterface $highlighter): static
{
$this->highlighter = $highlighter;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasPostFilterTrait.php b/src/SearchRequest/HasPostFilterTrait.php
index b0d987b..e1a62da 100644
--- a/src/SearchRequest/HasPostFilterTrait.php
+++ b/src/SearchRequest/HasPostFilterTrait.php
@@ -5,31 +5,21 @@
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-post-filter.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-post-filter.html
* @see HasPostFilterTraitTest
*/
trait HasPostFilterTrait
{
- /** @var MatcherInterface|null */
- protected $postFilter;
+ protected ?MatcherInterface $postFilter = null;
- /**
- * @return MatcherInterface|null
- */
- public function getPostFilter()
+ public function getPostFilter(): ?MatcherInterface
{
return $this->postFilter;
}
- /**
- * @param MatcherInterface|null $filter
- *
- * @return $this
- */
- public function setPostFilter(MatcherInterface $filter = null)
+ public function setPostFilter(?MatcherInterface $filter): static
{
$this->postFilter = $filter;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasQueryTrait.php b/src/SearchRequest/HasQueryTrait.php
index 1d0c892..ce3688f 100644
--- a/src/SearchRequest/HasQueryTrait.php
+++ b/src/SearchRequest/HasQueryTrait.php
@@ -5,31 +5,21 @@
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-query.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-query.html
* @see HasQueryTraitTest
*/
trait HasQueryTrait
{
- /** @var MatcherInterface|null */
- protected $query;
+ protected ?MatcherInterface $query = null;
- /**
- * @return MatcherInterface|null
- */
- public function getQuery()
+ public function getQuery(): ?MatcherInterface
{
return $this->query;
}
- /**
- * @param MatcherInterface|null $query
- *
- * @return $this
- */
- public function setQuery(MatcherInterface $query = null)
+ public function setQuery(?MatcherInterface $query): static
{
$this->query = $query;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasRescorersTrait.php b/src/SearchRequest/HasRescorersTrait.php
index 204c1e0..e2ca6e9 100644
--- a/src/SearchRequest/HasRescorersTrait.php
+++ b/src/SearchRequest/HasRescorersTrait.php
@@ -5,13 +5,13 @@
use Gskema\ElasticSearchQueryDSL\Rescorer\RescorerInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-rescore.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-rescore.html
* @see HasRescorersTraitTest
*/
trait HasRescorersTrait
{
/** @var RescorerInterface[] */
- protected $rescorers = [];
+ protected array $rescorers = [];
/**
* @return RescorerInterface[]
@@ -23,25 +23,16 @@ public function getRescorers(): array
/**
* @param RescorerInterface[] $rescorers
- *
- * @return $this
*/
- public function setRescorers(array $rescorers)
+ public function setRescorers(array $rescorers): static
{
$this->rescorers = $rescorers;
-
return $this;
}
- /**
- * @param RescorerInterface $rescorer
- *
- * @return $this
- */
- public function addRescorer(RescorerInterface $rescorer)
+ public function addRescorer(RescorerInterface $rescorer): static
{
$this->rescorers[] = $rescorer;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasScriptFieldsTrait.php b/src/SearchRequest/HasScriptFieldsTrait.php
index d2d51bb..5373027 100644
--- a/src/SearchRequest/HasScriptFieldsTrait.php
+++ b/src/SearchRequest/HasScriptFieldsTrait.php
@@ -5,13 +5,13 @@
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-script-fields.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-script-fields.html
* @see HasScriptFieldsTraitTest
*/
trait HasScriptFieldsTrait
{
/** @var ScriptInterface[] */
- protected $scriptFields = [];
+ protected array $scriptFields = [];
/**
* @return ScriptInterface[]
@@ -21,50 +21,29 @@ public function getScriptFields(): array
return $this->scriptFields;
}
- /**
- * @param string $field
- *
- * @return ScriptInterface|null
- */
- public function getScriptField(string $field)
+ public function getScriptField(string $field): ?ScriptInterface
{
return $this->scriptFields[$field] ?? null;
}
/**
* @param ScriptInterface[] $scriptsByField
- *
- * @return $this
*/
- public function setScriptFields(array $scriptsByField)
+ public function setScriptFields(array $scriptsByField): static
{
$this->scriptFields = $scriptsByField;
-
return $this;
}
- /**
- * @param string $field
- * @param ScriptInterface $script
- *
- * @return $this
- */
- public function setScriptField(string $field, ScriptInterface $script)
+ public function setScriptField(string $field, ScriptInterface $script): static
{
$this->scriptFields[$field] = $script;
-
return $this;
}
- /**
- * @param string $field
- *
- * @return $this
- */
- public function removeScriptField(string $field)
+ public function removeScriptField(string $field): static
{
unset($this->scriptFields[$field]);
-
return $this;
}
}
diff --git a/src/SearchRequest/HasSizeTrait.php b/src/SearchRequest/HasSizeTrait.php
index 77c0491..0e3ee4d 100644
--- a/src/SearchRequest/HasSizeTrait.php
+++ b/src/SearchRequest/HasSizeTrait.php
@@ -3,31 +3,21 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-from-size.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-from-size.html
* @see HasSizeTraitTest
*/
trait HasSizeTrait
{
- /** @var int|null */
- protected $size;
+ protected ?int $size = null;
- /**
- * @return int|null
- */
- public function getSize()
+ public function getSize(): ?int
{
return $this->size;
}
- /**
- * @param int|null $size
- *
- * @return $this
- */
- public function setSize(int $size = null)
+ public function setSize(?int $size): static
{
$this->size = $size;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasSortersTrait.php b/src/SearchRequest/HasSortersTrait.php
index 5fb5eec..75e5f22 100644
--- a/src/SearchRequest/HasSortersTrait.php
+++ b/src/SearchRequest/HasSortersTrait.php
@@ -4,14 +4,16 @@
use Gskema\ElasticSearchQueryDSL\Sorter\SorterInterface;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html
* @see HasSortersTraitTest
*/
trait HasSortersTrait
{
/** @var SorterInterface[] */
- protected $sorters = [];
+ protected array $sorters = [];
/**
* @return SorterInterface[]
@@ -23,25 +25,22 @@ public function getSorters(): array
/**
* @param SorterInterface[] $sorters
- *
- * @return $this
*/
- public function setSorters(array $sorters)
+ public function setSorters(array $sorters): static
{
$this->sorters = $sorters;
-
return $this;
}
- /**
- * @param SorterInterface $sorter
- *
- * @return $this
- */
- public function addSorter(SorterInterface $sorter)
+ public function addSorter(SorterInterface $sorter): static
{
$this->sorters[] = $sorter;
-
return $this;
}
+
+ protected function jsonSerializeSorters(): mixed
+ {
+ $rawSorters = obj_array_json_serialize($this->sorters);
+ return 1 === count($this->sorters) ? $rawSorters[0] : $rawSorters;
+ }
}
diff --git a/src/SearchRequest/HasSourceFieldsTrait.php b/src/SearchRequest/HasSourceFieldsTrait.php
index 8b81e91..1161ede 100644
--- a/src/SearchRequest/HasSourceFieldsTrait.php
+++ b/src/SearchRequest/HasSourceFieldsTrait.php
@@ -5,31 +5,33 @@
use Gskema\ElasticSearchQueryDSL\SourceFilter\SourceFilterInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html
* @see HasSourceFieldsTraitTest
*/
trait HasSourceFieldsTrait
{
- /** @var SourceFilterInterface|null */
- protected $sourceFields;
+ /** @var SourceFilterInterface|string[]|null */
+ protected SourceFilterInterface|array|null $sourceFields = null;
/**
- * @return SourceFilterInterface|null
+ * @return SourceFilterInterface|string[]|null
*/
- public function getSourceFields()
+ public function getSourceFields(): SourceFilterInterface|array|null
{
return $this->sourceFields;
}
/**
- * @param SourceFilterInterface|null $sourceFilter
- *
- * @return $this
+ * @param SourceFilterInterface|string[]|null $sourceFields
*/
- public function setSourceFields(SourceFilterInterface $sourceFilter = null)
+ public function setSourceFields(SourceFilterInterface|array|null $sourceFields): static
{
- $this->sourceFields = $sourceFilter;
-
+ $this->sourceFields = $sourceFields;
return $this;
}
+
+ protected function jsonSerializeSourceFields(): mixed
+ {
+ return is_array($this->sourceFields) ? $this->sourceFields : $this->sourceFields?->jsonSerialize();
+ }
}
diff --git a/src/SearchRequest/HasStatGroupsTrait.php b/src/SearchRequest/HasStatGroupsTrait.php
index 3c5ac22..ed6158f 100644
--- a/src/SearchRequest/HasStatGroupsTrait.php
+++ b/src/SearchRequest/HasStatGroupsTrait.php
@@ -3,13 +3,13 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search.html#stats-groups
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search.html#stats-groups
* @see HasStatGroupsTraitTest
*/
trait HasStatGroupsTrait
{
/** @var string[] */
- protected $statGroups = [];
+ protected array $statGroups = [];
/**
* @return string[]
@@ -21,25 +21,16 @@ public function getStatGroups(): array
/**
* @param string[] $statGroups
- *
- * @return $this
*/
- public function setStatGroups(array $statGroups)
+ public function setStatGroups(array $statGroups): static
{
$this->statGroups = $statGroups;
-
return $this;
}
- /**
- * @param string $statGroup
- *
- * @return $this
- */
- public function addStatGroup(string $statGroup)
+ public function addStatGroup(string $statGroup): static
{
$this->statGroups[] = $statGroup;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasStoredFieldsTrait.php b/src/SearchRequest/HasStoredFieldsTrait.php
index 3dc1310..cd07a26 100644
--- a/src/SearchRequest/HasStoredFieldsTrait.php
+++ b/src/SearchRequest/HasStoredFieldsTrait.php
@@ -3,31 +3,28 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-stored-fields.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-stored-fields.html
* @see HasStoredFieldsTraitTest
*/
trait HasStoredFieldsTrait
{
/** @var string[]|string|null */
- protected $storedFields;
+ protected array|string|null $storedFields = null;
/**
* @return string[]|string|null
*/
- public function getStoredFields()
+ public function getStoredFields(): array|string|null
{
return $this->storedFields;
}
/**
* @param string[]|string|null $storedFields
- *
- * @return $this
*/
- public function setStoredFields($storedFields = null)
+ public function setStoredFields(array|string|null $storedFields): static
{
$this->storedFields = $storedFields;
-
return $this;
}
}
diff --git a/src/SearchRequest/HasSuggestersTrait.php b/src/SearchRequest/HasSuggestersTrait.php
index a47fb0c..dcf02e6 100644
--- a/src/SearchRequest/HasSuggestersTrait.php
+++ b/src/SearchRequest/HasSuggestersTrait.php
@@ -5,66 +5,45 @@
use Gskema\ElasticSearchQueryDSL\Suggester\SuggesterInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters.html
* @see HasSuggestersTraitTest
*/
trait HasSuggestersTrait
{
- /** @var SuggesterInterface[] */
- protected $suggesters = [];
+ /** @var array */
+ protected array $suggesters = [];
/**
- * @return SuggesterInterface[]
+ * @return array
*/
public function getSuggesters(): array
{
return $this->suggesters;
}
- /**
- * @param string $key
- *
- * @return SuggesterInterface|null
- */
- public function getSuggester(string $key)
+ public function getSuggester(string $key): ?SuggesterInterface
{
return $this->suggesters[$key] ?? null;
}
/**
- * @param SuggesterInterface[] $suggestersByKey
- *
- * @return $this
+ * @param array $keySuggesterMap
*/
- public function setSuggesters(array $suggestersByKey)
+ public function setSuggesters(array $keySuggesterMap): static
{
- $this->suggesters = $suggestersByKey;
-
+ $this->suggesters = $keySuggesterMap;
return $this;
}
- /**
- * @param string $key
- * @param SuggesterInterface $suggester
- *
- * @return $this
- */
- public function setSuggester(string $key, SuggesterInterface $suggester)
+ public function setSuggester(string $key, SuggesterInterface $suggester): static
{
$this->suggesters[$key] = $suggester;
-
return $this;
}
- /**
- * @param string $key
- *
- * @return $this
- */
- public function removeSuggester(string $key)
+ public function removeSuggester(string $key): static
{
unset($this->suggesters[$key]);
-
return $this;
}
}
diff --git a/src/SearchRequest/InnerHitsRequest.php b/src/SearchRequest/InnerHitsRequest.php
index 5ec1958..8a373cc 100644
--- a/src/SearchRequest/InnerHitsRequest.php
+++ b/src/SearchRequest/InnerHitsRequest.php
@@ -2,20 +2,22 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
-use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
-use Gskema\ElasticSearchQueryDSL\Sorter\SorterInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use JsonSerializable;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-inner-hits.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-inner-hits.html
* @see InnerHitsRequestTest
- *
- * @options 'explain' => true,
- * 'version' => true,
*/
+#[Options([
+ 'explain' => true,
+ 'version' => true,
+])]
class InnerHitsRequest implements JsonSerializable
{
use HasOptionsTrait;
@@ -27,8 +29,7 @@ class InnerHitsRequest implements JsonSerializable
use HasScriptFieldsTrait;
use HasDocValueFieldsTrait;
- /** @var string|null */
- protected $name;
+ protected ?string $name = null;
public function __clone()
{
@@ -38,25 +39,21 @@ public function __clone()
$this->sourceFields = $this->sourceFields ? clone $this->sourceFields : null;
}
- /**
- * @return string|null
- */
- public function getName()
+ public function getName(): ?string
{
return $this->name;
}
- public function setName(string $name): InnerHitsRequest
+ public function setName(string $name): static
{
$this->name = $name;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = $this->options;
@@ -64,12 +61,10 @@ public function jsonSerialize()
$body['name'] = $this->name;
}
if (null !== $this->sourceFields) {
- $body['_source'] = $this->sourceFields->jsonSerialize();
+ $body['_source'] = $this->jsonSerializeSourceFields();
}
if (!empty($this->scriptFields)) {
- $body['script_fields'] = array_map(function (ScriptInterface $script) {
- return $script->jsonSerialize();
- }, $this->scriptFields);
+ $body['script_fields'] = obj_array_json_serialize($this->scriptFields);
}
if (!empty($this->docValueFields)) {
$body['docvalue_fields'] = $this->docValueFields;
@@ -81,17 +76,12 @@ public function jsonSerialize()
$body['size'] = $this->size;
}
if (!empty($this->sorters)) {
- $rawSorters = array_map(function (SorterInterface $sorter) {
- return $sorter->jsonSerialize();
- }, $this->sorters);
- $body['sort'] = 1 === count($this->sorters) ? $rawSorters[0] : $rawSorters;
+ $body['sort'] = $this->jsonSerializeSorters();
}
if (null !== $this->highlighter) {
$body['highlight'] = $this->highlighter->jsonSerialize();
}
- $body = $body ?: new stdClass();
-
- return $body;
+ return $body ?: new stdClass();
}
}
diff --git a/src/SearchRequest/RawSearchRequest.php b/src/SearchRequest/RawSearchRequest.php
index 8dedfd2..f7b8315 100644
--- a/src/SearchRequest/RawSearchRequest.php
+++ b/src/SearchRequest/RawSearchRequest.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-body.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-body.html
* @see RawSearchRequestTest
*/
class RawSearchRequest extends RawFragment implements SearchRequestInterface
diff --git a/src/SearchRequest/SearchRequest.php b/src/SearchRequest/SearchRequest.php
index 07361b1..452fd89 100644
--- a/src/SearchRequest/SearchRequest.php
+++ b/src/SearchRequest/SearchRequest.php
@@ -2,39 +2,41 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasAggsTrait;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\HasParametersTrait;
-use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
-use Gskema\ElasticSearchQueryDSL\Rescorer\RescorerInterface;
-use Gskema\ElasticSearchQueryDSL\Sorter\SorterInterface;
-use Gskema\ElasticSearchQueryDSL\Suggester\SuggesterInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+use Gskema\ElasticSearchQueryDSL\Parameters;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-body.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-body.html
* @see SearchRequestTest
- *
- * @options 'track_scores' => true,
- * 'slice' => ['field' => 'date', 'id' => 0, 'max' => 10],
- * 'explain' => true,
- * 'version' => true,
- * 'indices_boost' => [['alias1' => 1.4], ['index*' => 1.3]],
- * 'min_score' => 0.5,
- * 'search_after' => [1463538857, "tweet#654323"],
- *
- * @parameters 'routing' => 'kimchy',
- * 'timeout' => '2s',
- * 'terminate_after' => 1,
- * 'max_concurrent_shard_requests' => 2,
- * 'search_type' => 'dfs_query_then_fetch', 'query_then_fetch'
- * 'request_cache' => true,
- * 'batched_reduce_size' => 2,
- * 'scroll' => '1m',
- * 'preference' => ?,
- * 'error_trace' => true,
*/
+#[Options([
+ 'track_scores' => true,
+ 'slice' => ['field' => 'date', 'id' => 0, 'max' => 10],
+ 'explain' => true,
+ 'version' => true,
+ 'indices_boost' => [['alias1' => 1.4], ['index*' => 1.3]],
+ 'min_score' => 0.5,
+ 'search_after' => [1463538857, "tweet#654323"],
+])]
+#[Parameters([
+ 'routing' => 'kimchy',
+ 'timeout' => '2s',
+ 'terminate_after' => 1,
+ 'max_concurrent_shard_requests' => 2,
+ 'search_type' => 'dfs_query_then_fetch', // 'query_then_fetch'
+ 'request_cache' => true,
+ 'batched_reduce_size' => 2,
+ 'scroll' => '1m',
+ 'preference' => '?',
+ 'error_trace' => true,
+])]
class SearchRequest implements SearchRequestInterface
{
use HasOptionsTrait;
@@ -71,22 +73,20 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = $this->options;
if (null !== $this->sourceFields) {
- $body['_source'] = $this->sourceFields->jsonSerialize();
+ $body['_source'] = $this->jsonSerializeSourceFields();
}
if (null !== $this->storedFields) {
$body['stored_fields'] = $this->storedFields;
}
if (!empty($this->scriptFields)) {
- $body['script_fields'] = array_map(function (ScriptInterface $script) {
- return $script->jsonSerialize();
- }, $this->scriptFields);
+ $body['script_fields'] = obj_array_json_serialize($this->scriptFields);
}
if (!empty($this->docValueFields)) {
$body['docvalue_fields'] = $this->docValueFields;
@@ -104,24 +104,17 @@ public function jsonSerialize()
$body['post_filter'] = $this->postFilter->jsonSerialize();
}
if (!empty($this->sorters)) {
- $rawSorters = array_map(function (SorterInterface $sorter) {
- return $sorter->jsonSerialize();
- }, $this->sorters);
- $body['sort'] = 1 === count($this->sorters) ? $rawSorters[0] : $rawSorters;
+ $body['sort'] = $this->jsonSerializeSorters();
}
if (!empty($this->rescorers)) {
- $rawRescoreQueries = array_map(function (RescorerInterface $query) {
- return $query->jsonSerialize();
- }, $this->rescorers);
+ $rawRescoreQueries = obj_array_json_serialize($this->rescorers);
$body['rescore'] = 1 === count($this->rescorers) ? $rawRescoreQueries[0] : $rawRescoreQueries;
}
if (null !== $this->highlighter) {
$body['highlight'] = $this->highlighter->jsonSerialize();
}
if (!empty($this->suggesters)) {
- $body['suggest'] = array_map(function (SuggesterInterface $suggester) {
- return $suggester->jsonSerialize();
- }, $this->suggesters);
+ $body['suggest'] = obj_array_json_serialize($this->suggesters);
}
if (!empty($this->statGroups)) {
$body['stats'] = $this->statGroups;
@@ -130,12 +123,10 @@ public function jsonSerialize()
$body['collapse'] = $this->fieldCollapser->jsonSerialize();
}
- if ($this->hasAggs()) {
- $body['aggs'] = $this->jsonSerializeAggs();
+ if (!empty($this->aggs)) {
+ $body['aggs'] = obj_array_json_serialize($this->aggs);
}
- $body = $body ?: new stdClass();
-
- return $body;
+ return $body ?: new stdClass();
}
}
diff --git a/src/SearchRequest/SearchRequestInterface.php b/src/SearchRequest/SearchRequestInterface.php
index e8ad064..bf3946d 100644
--- a/src/SearchRequest/SearchRequestInterface.php
+++ b/src/SearchRequest/SearchRequestInterface.php
@@ -9,7 +9,7 @@
* Can be used to type-hint when an ElasticSearch client search method expects an instance of SearchRequestInterface.
* TopHitsRequest and InnerHitsRequest are not SearchRequestInterface because they have custom properties.
*
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-body.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-body.html
*/
interface SearchRequestInterface extends JsonSerializable
{
diff --git a/src/SearchRequest/TopHitsRequest.php b/src/SearchRequest/TopHitsRequest.php
index 9cc5392..721cba4 100644
--- a/src/SearchRequest/TopHitsRequest.php
+++ b/src/SearchRequest/TopHitsRequest.php
@@ -2,20 +2,22 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
-use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
-use Gskema\ElasticSearchQueryDSL\Sorter\SorterInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use JsonSerializable;
use stdClass;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-inner-hits.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-inner-hits.html
* @see TopHitsRequest
- *
- * @options 'explain' => true,
- * 'version' => true,
*/
+#[Options([
+ 'explain' => true,
+ 'version' => true,
+])]
class TopHitsRequest implements JsonSerializable
{
use HasFromTrait;
@@ -37,22 +39,20 @@ public function __clone()
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = $this->options;
if (null !== $this->sourceFields) {
- $body['_source'] = $this->sourceFields->jsonSerialize();
+ $body['_source'] = $this->jsonSerializeSourceFields();
}
if (null !== $this->storedFields) {
$body['stored_fields'] = $this->storedFields;
}
if (!empty($this->scriptFields)) {
- $body['script_fields'] = array_map(function (ScriptInterface $script) {
- return $script->jsonSerialize();
- }, $this->scriptFields);
+ $body['script_fields'] = obj_array_json_serialize($this->scriptFields);
}
if (!empty($this->docValueFields)) {
$body['docvalue_fields'] = $this->docValueFields;
@@ -64,17 +64,12 @@ public function jsonSerialize()
$body['size'] = $this->size;
}
if (!empty($this->sorters)) {
- $rawSorters = array_map(function (SorterInterface $sorter) {
- return $sorter->jsonSerialize();
- }, $this->sorters);
- $body['sort'] = 1 === count($this->sorters) ? $rawSorters[0] : $rawSorters;
+ $body['sort'] = $this->jsonSerializeSorters();
}
if (null !== $this->highlighter) {
$body['highlight'] = $this->highlighter->jsonSerialize();
}
- $body = $body ?: new stdClass();
-
- return $body;
+ return $body ?: new stdClass();
}
}
diff --git a/src/Sorter/FieldSorter.php b/src/Sorter/FieldSorter.php
index a9cb7a1..53779c3 100644
--- a/src/Sorter/FieldSorter.php
+++ b/src/Sorter/FieldSorter.php
@@ -3,32 +3,25 @@
namespace Gskema\ElasticSearchQueryDSL\Sorter;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html
* @see FieldSorterTest
- *
- * @options 'missing' => '_first', '_last',
- * 'unmapped_type' => 'long',
*/
+#[Options([
+ 'missing' => '_first', // '_last',
+ 'unmapped_type' => 'long',
+])]
class FieldSorter implements SorterInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string|null 'asc', 'desc' */
- protected $order;
-
- /** @var string|null 'min', 'max', 'sum', 'avg', 'median' */
- protected $mode;
-
- public function __construct(string $field, string $order = null, string $mode = null)
- {
- $this->field = $field;
- $this->order = $order;
- $this->mode = $mode;
+ public function __construct(
+ protected string $field,
+ protected ?string $order = null, // 'asc', 'desc'
+ protected ?string $mode = null, // 'min', 'max', 'sum', 'avg', 'median'
+ ) {
}
public function getField(): string
@@ -36,50 +29,32 @@ public function getField(): string
return $this->field;
}
- /**
- * @return string|null
- */
- public function getOrder()
+ public function getOrder(): ?string
{
return $this->order;
}
- /**
- * @param string|null $order
- *
- * @return $this
- */
- public function setOrder(string $order = null): FieldSorter
+ public function setOrder(?string $order): static
{
$this->order = $order;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getMode()
+ public function getMode(): ?string
{
return $this->mode;
}
- /**
- * @param string|null $mode
- *
- * @return $this
- */
- public function setMode(string $mode = null): FieldSorter
+ public function setMode(?string $mode): static
{
$this->mode = $mode;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
if (null !== $this->order) {
diff --git a/src/Sorter/GeoDistanceSorter.php b/src/Sorter/GeoDistanceSorter.php
index 10855c9..734e6f8 100644
--- a/src/Sorter/GeoDistanceSorter.php
+++ b/src/Sorter/GeoDistanceSorter.php
@@ -2,43 +2,32 @@
namespace Gskema\ElasticSearchQueryDSL\Sorter;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Model\GeoPointInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
+
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html#geo-sorting
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#geo-sorting
* @see GeoDistanceSorterTest
- *
- * @options 'distance_type' => 'arc', 'plane',
*/
+#[Options([
+ 'distance_type' => 'arc', // 'plane',
+])]
class GeoDistanceSorter implements SorterInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var GeoPointInterface[] */
- protected $origins;
-
- /** @var string|null 'km', 'm', ... */
- protected $unit;
-
- /** @var string|null 'asc', 'desc' */
- protected $order;
-
- /** @var string|null 'min', 'max', 'sum', 'avg', 'median' */
- protected $mode;
-
- /**
- * @param string $field
- * @param GeoPointInterface[] $origins
- */
- public function __construct(string $field, array $origins)
- {
- $this->field = $field;
- $this->origins = $origins;
+ public function __construct(
+ protected string $field,
+ /** @var GeoPointInterface[] */
+ protected array $origins,
+ protected ?string $unit = null, // 'km', 'm', ...
+ protected ?string $order = null, // 'asc', 'desc'
+ protected ?string $mode = null, // 'min', 'max', 'sum', 'avg', 'median'
+ ) {
}
public function __clone()
@@ -59,77 +48,48 @@ public function getOrigins(): array
return $this->origins;
}
- /**
- * @return string|null
- */
- public function getUnit()
+ public function getUnit(): ?string
{
return $this->unit;
}
- /**
- * @param string|null $unit
- *
- * @return $this
- */
- public function setUnit(string $unit = null): GeoDistanceSorter
+ public function setUnit(?string $unit): static
{
$this->unit = $unit;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getOrder()
+ public function getOrder(): ?string
{
return $this->order;
}
- /**
- * @param string|null $order
- *
- * @return $this
- */
- public function setOrder(string $order = null): GeoDistanceSorter
+ public function setOrder(?string $order): static
{
$this->order = $order;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getMode()
+ public function getMode(): ?string
{
return $this->mode;
}
- /**
- * @param string|null $mode
- *
- * @return $this
- */
- public function setMode(string $mode = null): GeoDistanceSorter
+ public function setMode(?string $mode): static
{
$this->mode = $mode;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body[$this->field] = $this->field;
- $rawPoints = array_map(function (GeoPointInterface $origin) {
- return $origin->jsonSerialize();
- }, $this->origins);
+ $rawPoints = obj_array_json_serialize($this->origins);
$body[$this->field] = 1 === count($this->origins) ? $rawPoints[0] : $rawPoints;
if (null !== $this->unit) {
diff --git a/src/Sorter/NestedSorter.php b/src/Sorter/NestedSorter.php
index ff0d473..dd3a22a 100644
--- a/src/Sorter/NestedSorter.php
+++ b/src/Sorter/NestedSorter.php
@@ -4,37 +4,27 @@
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html#nested-sorting
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#nested-sorting
* @see NestedSorterTest
- *
- * @options 'missing' => '_first', '_last',
- * 'unmapped_type' => 'long',
*/
+#[Options([
+ 'missing' => '_first', // '_last',
+ 'unmapped_type' => 'long',
+])]
class NestedSorter implements SorterInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $nestedPath;
-
- /** @var MatcherInterface|null */
- protected $nestedFilter;
-
- /** @var string|null 'asc', 'desc' */
- protected $order;
-
- /** @var string|null 'min', 'max', 'sum', 'avg', 'median' */
- protected $mode;
-
- public function __construct(string $field, string $nestedPath)
- {
- $this->field = $field;
- $this->nestedPath = $nestedPath;
+ public function __construct(
+ protected string $field,
+ protected string $nestedPath,
+ protected ?MatcherInterface $nestedFilter = null,
+ protected ?string $order = null, // 'asc', 'desc'
+ protected ?string $mode = null, // /** 'min', 'max', 'sum', 'avg', 'median'
+ ) {
}
public function __clone()
@@ -52,70 +42,43 @@ public function getNestedPath(): string
return $this->nestedPath;
}
- /**
- * @return MatcherInterface|null
- */
- public function getNestedFilter()
+ public function getNestedFilter(): ?MatcherInterface
{
return $this->nestedFilter;
}
- /**
- * @param MatcherInterface|null $filter
- *
- * @return $this
- */
- public function setNestedFilter(MatcherInterface $filter = null): NestedSorter
+ public function setNestedFilter(?MatcherInterface $filter): static
{
$this->nestedFilter = $filter;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getOrder()
+ public function getOrder(): ?string
{
return $this->order;
}
- /**
- * @param string|null $order
- *
- * @return $this
- */
- public function setOrder(string $order = null): NestedSorter
+ public function setOrder(?string $order): static
{
$this->order = $order;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getMode()
+ public function getMode(): ?string
{
return $this->mode;
}
- /**
- * @param string|null $mode
- *
- * @return $this
- */
- public function setMode(string $mode = null): NestedSorter
+ public function setMode(?string $mode): static
{
$this->mode = $mode;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['nested_path'] = $this->nestedPath;
diff --git a/src/Sorter/RawSorter.php b/src/Sorter/RawSorter.php
index 8715e60..f8b0176 100644
--- a/src/Sorter/RawSorter.php
+++ b/src/Sorter/RawSorter.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html
* @see RawSorterTest
*/
class RawSorter extends RawFragment implements SorterInterface
diff --git a/src/Sorter/ScriptSorter.php b/src/Sorter/ScriptSorter.php
index e4dd01f..a1ffb8e 100644
--- a/src/Sorter/ScriptSorter.php
+++ b/src/Sorter/ScriptSorter.php
@@ -5,27 +5,17 @@
use Gskema\ElasticSearchQueryDSL\Model\Script\ScriptInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html#_script_based_sorting
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#_script_based_sorting
* @see ScriptSorterTest
*/
class ScriptSorter implements SorterInterface
{
- /** @var string */
- protected $type;
-
- /** @var ScriptInterface */
- protected $script;
-
- /** @var string|null 'asc', 'desc' */
- protected $order;
-
- /** @var string|null 'min', 'max', 'sum', 'avg', 'median' */
- protected $mode;
-
- public function __construct(string $type, ScriptInterface $script)
- {
- $this->type = $type;
- $this->script = $script;
+ public function __construct(
+ protected string $type,
+ protected ScriptInterface $script, // 'asc', 'desc'
+ protected ?string $order = null,
+ protected ?string $mode = null, // 'min', 'max', 'sum', 'avg', 'median'
+ ) {
}
public function __clone()
@@ -43,50 +33,32 @@ public function getScript(): ScriptInterface
return $this->script;
}
- /**
- * @return string|null
- */
- public function getOrder()
+ public function getOrder(): ?string
{
return $this->order;
}
- /**
- * @param string|null $order
- *
- * @return $this
- */
- public function setOrder(string $order = null): ScriptSorter
+ public function setOrder(?string $order): static
{
$this->order = $order;
-
return $this;
}
- /**
- * @return string|null
- */
- public function getMode()
+ public function getMode(): ?string
{
return $this->mode;
}
- /**
- * @param string|null $mode
- *
- * @return $this
- */
- public function setMode(string $mode = null): ScriptSorter
+ public function setMode(?string $mode): static
{
$this->mode = $mode;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['type'] = $this->type;
diff --git a/src/Sorter/SorterInterface.php b/src/Sorter/SorterInterface.php
index 85efab5..e7ddb3b 100644
--- a/src/Sorter/SorterInterface.php
+++ b/src/Sorter/SorterInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-sort.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html
*/
interface SorterInterface extends JsonSerializable
{
diff --git a/src/SourceFilter/DisabledSourceFilter.php b/src/SourceFilter/DisabledSourceFilter.php
index 9171054..b91ef73 100644
--- a/src/SourceFilter/DisabledSourceFilter.php
+++ b/src/SourceFilter/DisabledSourceFilter.php
@@ -3,15 +3,15 @@
namespace Gskema\ElasticSearchQueryDSL\SourceFilter;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html
* @see DisabledSourceFilterTest
*/
class DisabledSourceFilter implements SourceFilterInterface
{
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
return false;
}
diff --git a/src/SourceFilter/RawSourceFilter.php b/src/SourceFilter/RawSourceFilter.php
index 4308c3e..84d96e8 100644
--- a/src/SourceFilter/RawSourceFilter.php
+++ b/src/SourceFilter/RawSourceFilter.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html
* @see RawSourceFilterTest
*/
class RawSourceFilter extends RawFragment implements SourceFilterInterface
diff --git a/src/SourceFilter/SourceFilter.php b/src/SourceFilter/SourceFilter.php
index cfb498a..6b04a96 100644
--- a/src/SourceFilter/SourceFilter.php
+++ b/src/SourceFilter/SourceFilter.php
@@ -5,16 +5,18 @@
use stdClass;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html
* @see SourceFilterTest
*/
class SourceFilter implements SourceFilterInterface
{
- /** @var string[] */
- protected $includes = [];
-
- /** @var string[] */
- protected $excludes = [];
+ public function __construct(
+ /** @var string[] */
+ protected array $includes = [],
+ /** @var string[] */
+ protected array $excludes = [],
+ ) {
+ }
/**
* @return string[]
@@ -26,25 +28,16 @@ public function getIncludes(): array
/**
* @param string[] $includes
- *
- * @return SourceFilter
*/
- public function setIncludes(array $includes): SourceFilter
+ public function setIncludes(array $includes): static
{
$this->includes = $includes;
-
return $this;
}
- /**
- * @param string $includedField
- *
- * @return SourceFilter
- */
- public function addInclude(string $includedField): SourceFilter
+ public function addInclude(string $includedField): static
{
$this->includes[] = $includedField;
-
return $this;
}
@@ -58,32 +51,23 @@ public function getExcludes(): array
/**
* @param string[] $excludes
- *
- * @return SourceFilter
*/
- public function setExcludes(array $excludes): SourceFilter
+ public function setExcludes(array $excludes): static
{
$this->excludes = $excludes;
-
return $this;
}
- /**
- * @param string $excludedField
- *
- * @return SourceFilter
- */
- public function addExclude(string $excludedField): SourceFilter
+ public function addExclude(string $excludedField): static
{
$this->excludes[] = $excludedField;
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$includes = 1 === count($this->includes) ? $this->includes[0] : $this->includes;
$excludes = 1 === count($this->excludes) ? $this->excludes[0] : $this->excludes;
diff --git a/src/SourceFilter/SourceFilterInterface.php b/src/SourceFilter/SourceFilterInterface.php
index dbc8320..30dfe7a 100644
--- a/src/SourceFilter/SourceFilterInterface.php
+++ b/src/SourceFilter/SourceFilterInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-source-filtering.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-source-filtering.html
*/
interface SourceFilterInterface extends JsonSerializable
{
diff --git a/src/Suggester/CandidateGenerator/CandidateGeneratorInterface.php b/src/Suggester/CandidateGenerator/CandidateGeneratorInterface.php
index 147e778..d113a5a 100644
--- a/src/Suggester/CandidateGenerator/CandidateGeneratorInterface.php
+++ b/src/Suggester/CandidateGenerator/CandidateGeneratorInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-phrase.html#_candidate_generators
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html#_candidate_generators
*/
interface CandidateGeneratorInterface extends JsonSerializable
{
diff --git a/src/Suggester/CandidateGenerator/DirectCandidateGenerator.php b/src/Suggester/CandidateGenerator/DirectCandidateGenerator.php
index 5b148b5..d567b46 100644
--- a/src/Suggester/CandidateGenerator/DirectCandidateGenerator.php
+++ b/src/Suggester/CandidateGenerator/DirectCandidateGenerator.php
@@ -3,40 +3,42 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester\CandidateGenerator;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-phrase.html#_direct_generators
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html#_direct_generators
* @see DirectCandidateGeneratorTest
- *
- * @options 'size' => 1,
- * 'suggest_mode' => 'missing', 'always', 'popular',
- * 'max_edits' => 2,
- * 'prefix_length' => 1,
- * 'min_word_length' => 4,
- * 'max_inspections' => 5,
- * 'min_doc_freq' => 0,
- * 'max_term_freq' => 0.01,
- * 'pre_filter' => 'reverse',
- * 'post_filter' => 'reverse',
- *
*/
+#[Options([
+ 'size' => 1,
+ 'suggest_mode' => 'missing', // 'always', 'popular',
+ 'max_edits' => 2,
+ 'prefix_length' => 1,
+ 'min_word_length' => 4,
+ 'max_inspections' => 5,
+ 'min_doc_freq' => 0,
+ 'max_term_freq' => 0.01,
+ 'pre_filter' => 'reverse',
+ 'post_filter' => 'reverse',
+])]
class DirectCandidateGenerator implements CandidateGeneratorInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- public function __construct(string $field, array $options = [])
- {
- $this->field = $field;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['field'] = $this->field;
diff --git a/src/Suggester/CompletionSuggester.php b/src/Suggester/CompletionSuggester.php
index 18b4cc3..d718f0e 100644
--- a/src/Suggester/CompletionSuggester.php
+++ b/src/Suggester/CompletionSuggester.php
@@ -3,67 +3,74 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
+use InvalidArgumentException;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-completion.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-completion.html
* @see CompletionSuggesterTest
- *
- * @options 'size' => 5,
- * 'fuzzy' => ['fuzziness' => ?, 'transpositions' => true, 'min_length' => 3, 'prefix_length' => 1, 'unicode_aware' => false],
- * 'flags' => 'ANYSTRING', 'COMPLEMENT', 'EMPTY', 'INTERSECTION', 'INTERVAL', 'NONE',
- * 'max_determinized_states' => 10000,
*/
+#[Options([
+ 'size' => 5,
+ 'fuzzy' => [
+ 'fuzziness' => '?',
+ 'transpositions' => true,
+ 'min_length' => 3,
+ 'prefix_length' => 1,
+ 'unicode_aware' => false
+ ],
+ 'flags' => 'ANYSTRING',// 'COMPLEMENT', 'EMPTY', 'INTERSECTION', 'INTERVAL', 'NONE',
+ 'max_determinized_states' => 10000,
+ 'skip_duplicates' => true,
+])]
class CompletionSuggester implements SuggesterInterface
{
use HasOptionsTrait;
- /** @var array */
- protected $body;
-
- protected function __construct(array $body, array $options = [])
- {
- $this->body = $body;
+ /**
+ * @param array $options
+ */
+ protected function __construct(
+ protected string $field,
+ protected ?string $prefix,
+ protected ?string $regex,
+ array $options = [],
+ ) {
+ if (null === $prefix && null === $regex) {
+ throw new InvalidArgumentException('Expected at least one to be not null: prefix of regex.');
+ }
$this->options = $options;
}
/**
- * @param string $field
- * @param string $prefix
- * @param array $options
- *
- * @return static
+ * @param array $options
*/
- public static function fromPrefix(string $field, string $prefix, array $options = [])
+ public static function fromPrefix(string $field, string $prefix, array $options = []): static
{
- $body = [];
- $body['prefix'] = $prefix;
- $body['completion']['field'] = $field;
-
- return new static($body, $options);
+ return new static($field, $prefix, null, $options);
}
/**
- * @param string $field
- * @param string $regex
- * @param array $options
- *
- * @return static
+ * @param array $options
*/
- public static function fromRegex(string $field, string $regex, array $options = [])
+ public static function fromRegex(string $field, string $regex, array $options = []): static
{
- $body = [];
- $body['regex'] = $regex;
- $body['completion']['field'] = $field;
-
- return new static($body, $options);
+ return new static($field, null, $regex, $options);
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
- $body = $this->body;
+ $body = [];
+ if (null !== $this->prefix) {
+ $body['prefix'] = $this->prefix;
+ }
+ if (null !== $this->regex) {
+ $body['regex'] = $this->regex;
+ }
+ $body['completion']['field'] = $this->field;
$body['completion'] += $this->options;
return $body;
diff --git a/src/Suggester/ContextQuery/CategoryContextQuery.php b/src/Suggester/ContextQuery/CategoryContextQuery.php
index 4f78e19..4e9cb79 100644
--- a/src/Suggester/ContextQuery/CategoryContextQuery.php
+++ b/src/Suggester/ContextQuery/CategoryContextQuery.php
@@ -3,15 +3,15 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester\ContextQuery;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/suggester-context.html#suggester-context-category
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html#suggester-context-category
* @see CategoryContextQueryTest
*/
class CategoryContextQuery implements ContextQueryInterface
{
- /** @var array[] */
- protected $clauses = [];
+ /** @var mixed[][] */
+ protected array $clauses = [];
- public function addCategory(string $category, float $boost = null, bool $prefix = null): CategoryContextQuery
+ public function addCategory(string $category, ?float $boost = null, ?bool $prefix = null): static
{
$clause = [];
$clause['context'] = $category;
@@ -28,9 +28,9 @@ public function addCategory(string $category, float $boost = null, bool $prefix
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$hasParameters = false;
foreach ($this->clauses as $clause) {
diff --git a/src/Suggester/ContextQuery/ContextQueryInterface.php b/src/Suggester/ContextQuery/ContextQueryInterface.php
index 0e51940..c3bc762 100644
--- a/src/Suggester/ContextQuery/ContextQueryInterface.php
+++ b/src/Suggester/ContextQuery/ContextQueryInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/suggester-context.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html
*/
interface ContextQueryInterface extends JsonSerializable
{
diff --git a/src/Suggester/ContextQuery/GeoLocationContextQuery.php b/src/Suggester/ContextQuery/GeoLocationContextQuery.php
index 418122f..55687db 100644
--- a/src/Suggester/ContextQuery/GeoLocationContextQuery.php
+++ b/src/Suggester/ContextQuery/GeoLocationContextQuery.php
@@ -5,20 +5,23 @@
use Gskema\ElasticSearchQueryDSL\Model\GeoPointInterface;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/suggester-context.html#_category_query
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html#_category_query
* @see GeoLocationContextQueryTest
*/
class GeoLocationContextQuery implements ContextQueryInterface
{
- /** @var array[] */
- protected $clauses = [];
+ /** @var mixed[][] */
+ protected array $clauses = [];
+ /**
+ * @param mixed[] $neighbours
+ */
public function addGeoPoint(
GeoPointInterface $point,
- int $precision = null,
- float $boost = null,
- array $neighbours = []
- ): GeoLocationContextQuery {
+ ?int $precision = null,
+ ?float $boost = null,
+ array $neighbours = [],
+ ): static {
$clause = [];
$clause['context'] = $point->jsonSerialize();
if (null !== $precision) {
@@ -37,9 +40,9 @@ public function addGeoPoint(
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$hasParameters = false;
foreach ($this->clauses as $clause) {
diff --git a/src/Suggester/ContextQuery/RawContextQuery.php b/src/Suggester/ContextQuery/RawContextQuery.php
index 9d6d5f3..d7bb568 100644
--- a/src/Suggester/ContextQuery/RawContextQuery.php
+++ b/src/Suggester/ContextQuery/RawContextQuery.php
@@ -5,7 +5,7 @@
use Gskema\ElasticSearchQueryDSL\RawFragment;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/suggester-context.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html
* @see RawContextQueryTest
*/
class RawContextQuery extends RawFragment implements ContextQueryInterface
diff --git a/src/Suggester/ContextSuggester.php b/src/Suggester/ContextSuggester.php
index 0e38196..7928e0d 100644
--- a/src/Suggester/ContextSuggester.php
+++ b/src/Suggester/ContextSuggester.php
@@ -2,30 +2,34 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
+use Gskema\ElasticSearchQueryDSL\Options;
use Gskema\ElasticSearchQueryDSL\Suggester\ContextQuery\ContextQueryInterface;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+use function Gskema\ElasticSearchQueryDSL\obj_array_json_serialize;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/suggester-context.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/suggester-context.html
* @see ContextSuggesterTest
- *
- * @options 'gram_size' => 3,
- * 'real_word_error_likelihood' => 0.95,
- * 'confidence' => 1.0,
- * 'max_errors' => 1.0,
- * 'separator' => ' ',
- * 'size' => 5,
- * 'analyzer' => 'standard',
- * 'shard_size' => 5,
- * 'highlight' => ['pre_tag' => '', 'post_tag' => '']
- * 'smoothing' => ['stupid_backoff' => ['discount' => 0.4]],
- * ['laplace' => ['alpha ' => 0.5]],
- * ['linear_interpolation' => ['trigram_lambda' => ?, 'bigram_lambda' => ?, 'unigram_lambda' => ?]],
*/
+#[Options([
+ 'gram_size' => 3,
+ 'real_word_error_likelihood' => 0.95,
+ 'confidence' => 1.0,
+ 'max_errors' => 1.0,
+ 'separator' => ' ',
+ 'size' => 5,
+ 'analyzer' => 'standard',
+ 'shard_size' => 5,
+ 'highlight' => ['pre_tag' => '', 'post_tag' => ''],
+ 'smoothing' => ['stupid_backoff' => ['discount' => 0.4]],
+ // ['laplace' => ['alpha ' => 0.5]],
+ // ['linear_interpolation' => ['trigram_lambda' => '?', 'bigram_lambda' => '?', 'unigram_lambda' => '?']],
+])]
class ContextSuggester extends CompletionSuggester
{
/** @var ContextQueryInterface[] */
- protected $contexts = [];
+ protected array $contexts = [];
public function __clone()
{
@@ -40,64 +44,41 @@ public function getContexts(): array
return $this->contexts;
}
- /**
- * @param string $contextName
- *
- * @return ContextQueryInterface|null
- */
- public function getContext(string $contextName)
+ public function getContext(string $contextName): ?ContextQueryInterface
{
return $this->contexts[$contextName] ?? null;
}
/**
* @param ContextQueryInterface[] $queriesByContextName
- *
- * @return $this
*/
- public function setContexts(array $queriesByContextName): ContextSuggester
+ public function setContexts(array $queriesByContextName): static
{
$this->contexts = $queriesByContextName;
-
return $this;
}
- /**
- * @param string $contextName
- * @param ContextQueryInterface $query
- *
- * @return ContextSuggester
- */
- public function setContext(string $contextName, ContextQueryInterface $query): ContextSuggester
+ public function setContext(string $contextName, ContextQueryInterface $query): static
{
$this->contexts[$contextName] = $query;
-
return $this;
}
- /**
- * @param string $contextName
- *
- * @return $this
- */
- public function removeContext(string $contextName): ContextSuggester
+ public function removeContext(string $contextName): static
{
unset($this->contexts[$contextName]);
-
return $this;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = parent::jsonSerialize();
if (!empty($this->contexts)) {
- $body['completion']['contexts'] = array_map(function (ContextQueryInterface $query) {
- return $query->jsonSerialize();
- }, $this->contexts);
+ $body['completion']['contexts'] = obj_array_json_serialize($this->contexts);
}
return $body;
diff --git a/src/Suggester/PhraseSuggester.php b/src/Suggester/PhraseSuggester.php
index 827bf4c..3992726 100644
--- a/src/Suggester/PhraseSuggester.php
+++ b/src/Suggester/PhraseSuggester.php
@@ -2,48 +2,48 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
-use function Gskema\ElasticSearchQueryDSL\array_clone;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
use Gskema\ElasticSearchQueryDSL\Matcher\MatcherInterface;
+use Gskema\ElasticSearchQueryDSL\Options;
use Gskema\ElasticSearchQueryDSL\Suggester\CandidateGenerator\CandidateGeneratorInterface;
+use function Gskema\ElasticSearchQueryDSL\array_clone;
+
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-phrase.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-phrase.html
* @see PhraseSuggesterTest
- *
- * @options 'gram_size' => 3,
- * 'real_word_error_likelihood' => 0.95,
- * 'confidence' => 1.0,
- * 'max_errors' => 1.0,
- * 'separator' => ' ',
- * 'size' => 5,
- * 'analyzer' => 'standard',
- * 'shard_size' => 5,
- * 'highlight' => ['pre_tag' => '', 'post_tag' => ''],
- * 'smoothing' => ['stupid_backoff' => ['discount' => 0.4]],
- * ['laplace' => ['alpha ' => 0.5]],
- * ['linear_interpolation' => ['trigram_lambda' => ?, 'bigram_lambda' => ?, 'unigram_lambda' => ?]],
*/
+#[Options([
+ 'gram_size' => 3,
+ 'real_word_error_likelihood' => 0.95,
+ 'confidence' => 1.0,
+ 'max_errors' => 1.0,
+ 'separator' => ' ',
+ 'size' => 5,
+ 'analyzer' => 'standard',
+ 'shard_size' => 5,
+ 'highlight' => ['pre_tag' => '', 'post_tag' => ''],
+ 'smoothing' => ['stupid_backoff' => ['discount' => 0.4]],
+ // ['laplace' => ['alpha ' => 0.5]],
+ // ['linear_interpolation' => ['trigram_lambda' => ?, 'bigram_lambda' => ?, 'unigram_lambda' => ?]],
+])]
class PhraseSuggester implements SuggesterInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $text;
-
/** @var CandidateGeneratorInterface[] */
- protected $directGenerators = [];
-
- /** @var array|null */
- protected $collate;
+ protected array $directGenerators = [];
+ /** @var mixed[]|null */
+ protected ?array $collate = null;
- public function __construct(string $field, string $text, array $options = [])
- {
- $this->field = $field;
- $this->text = $text;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $text,
+ array $options = [],
+ ) {
$this->options = $options;
}
@@ -63,36 +63,23 @@ public function getDirectGenerators(): array
/**
* @param CandidateGeneratorInterface[] $candidateGenerators
- *
- * @return $this
*/
- public function setDirectGenerators(array $candidateGenerators): PhraseSuggester
+ public function setDirectGenerators(array $candidateGenerators): static
{
$this->directGenerators = $candidateGenerators;
-
return $this;
}
- /**
- * @param CandidateGeneratorInterface $candidateGenerator
- *
- * @return $this
- */
- public function addDirectGenerator(CandidateGeneratorInterface $candidateGenerator): PhraseSuggester
+ public function addDirectGenerator(CandidateGeneratorInterface $candidateGenerator): static
{
$this->directGenerators[] = $candidateGenerator;
-
return $this;
}
/**
- * @param MatcherInterface $query
- * @param array $params
- * @param bool|null $prune
- *
- * @return $this
+ * @param array $params
*/
- public function setCollate(MatcherInterface $query, array $params = [], bool $prune = null): PhraseSuggester
+ public function setCollate(MatcherInterface $query, array $params = [], ?bool $prune = null): static
{
$rawCollate = [];
$rawCollate['query'] = $query->jsonSerialize();
@@ -109,9 +96,9 @@ public function setCollate(MatcherInterface $query, array $params = [], bool $pr
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['text'] = $this->text;
diff --git a/src/Suggester/SuggesterInterface.php b/src/Suggester/SuggesterInterface.php
index d4a183f..b22c00c 100644
--- a/src/Suggester/SuggesterInterface.php
+++ b/src/Suggester/SuggesterInterface.php
@@ -5,7 +5,7 @@
use JsonSerializable;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters.html
*/
interface SuggesterInterface extends JsonSerializable
{
diff --git a/src/Suggester/TermSuggester.php b/src/Suggester/TermSuggester.php
index b760b38..72396d6 100644
--- a/src/Suggester/TermSuggester.php
+++ b/src/Suggester/TermSuggester.php
@@ -3,46 +3,46 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
use Gskema\ElasticSearchQueryDSL\HasOptionsTrait;
+use Gskema\ElasticSearchQueryDSL\Options;
/**
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-suggesters-term.html
+ * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters-term.html
* @see TermSuggesterTest
- *
- * @options 'analyzer' => 'standard',
- * 'size' => 5,
- * 'sort' => 'score', 'frequency',
- * 'suggest_mode' => 'missing', 'popular', 'always',
- * 'lowercase_terms' => true,
- * 'max_edits' => 2,
- * 'prefix_length' => 1,
- * 'min_word_length' => 4,
- * 'shard_size' => 5,
- * 'max_inspections' => 5,
- * 'min_doc_freq' => 0,
- * 'max_term_freq' => 0.01,
- * 'string_distance' => 'internal', 'damerau_levenshtein', 'levenstein', 'jarowinkler', 'ngram',
*/
+#[Options([
+ 'analyzer' => 'standard',
+ 'size' => 5,
+ 'sort' => 'score', // 'frequency',
+ 'suggest_mode' => 'missing', // 'popular', 'always',
+ 'lowercase_terms' => true,
+ 'max_edits' => 2,
+ 'prefix_length' => 1,
+ 'min_word_length' => 4,
+ 'shard_size' => 5,
+ 'max_inspections' => 5,
+ 'min_doc_freq' => 0,
+ 'max_term_freq' => 0.01,
+ 'string_distance' => 'internal', // 'damerau_levenshtein', 'levenstein', 'jarowinkler', 'ngram',
+])]
class TermSuggester implements SuggesterInterface
{
use HasOptionsTrait;
- /** @var string */
- protected $field;
-
- /** @var string */
- protected $text;
-
- public function __construct(string $field, string $text, array $options = [])
- {
- $this->field = $field;
- $this->text = $text;
+ /**
+ * @param array $options
+ */
+ public function __construct(
+ protected string $field,
+ protected string $text,
+ array $options = [],
+ ) {
$this->options = $options;
}
/**
- * @inheritdoc
+ * @inheritDoc
*/
- public function jsonSerialize()
+ public function jsonSerialize(): mixed
{
$body = [];
$body['text'] = $this->text;
diff --git a/src/functions.php b/src/functions.php
index ead6934..0145dd1 100644
--- a/src/functions.php
+++ b/src/functions.php
@@ -2,10 +2,16 @@
namespace Gskema\ElasticSearchQueryDSL;
+use JsonSerializable;
+
+/**
+ * @param mixed[] $array
+ * @return mixed[]
+ */
function array_clone(array $array): array
{
$clone = $array;
- foreach ($clone as $key => &$value) {
+ foreach ($clone as &$value) {
if (is_object($value)) {
$value = clone $value;
} elseif (is_array($value)) {
@@ -15,3 +21,12 @@ function array_clone(array $array): array
return $clone;
}
+
+/**
+ * @param JsonSerializable[] $objects
+ * @return mixed[]
+ */
+function obj_array_json_serialize(array $objects): array
+{
+ return array_map(fn (JsonSerializable $object) => $object->jsonSerialize(), $objects);
+}
diff --git a/tests/AbstractJsonSerializeTest.php b/tests/AbstractJsonSerializeTest.php
deleted file mode 100644
index b40cf95..0000000
--- a/tests/AbstractJsonSerializeTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-assertJsonStringEqualsJsonString($expectedJson, json_encode($givenJsonObj));
- }
-
- /**
- * @dataProvider dataTestJsonSerialize
- *
- * @param string $expectedJson
- * @param JsonSerializable $givenJsonObj
- * @throws ReflectionException
- */
- public function testClone(string $expectedJson, JsonSerializable $givenJsonObj)
- {
- $obj0 = $givenJsonObj;
- $obj1 = clone $givenJsonObj;
-
- $ref = (new ReflectionClass($obj0));
- $className = $ref->getName();
- $shortClassName = $ref->getShortName();
- $properties = $ref->getProperties();
-
- if (empty($properties)) {
- $this->assertTrue(true);
- }
-
- foreach ($properties as $property) {
- $property->setAccessible(true);
- $propName = $property->getName();
-
- $val0 = $property->getValue($obj0);
- $val1 = $property->getValue($obj1);
-
- $this->assertEquals($val0, $val1, sprintf(
- 'Expected %s:$%s to be equal after cloning',
- $className,
- $propName
- ));
- $this->assertNotHashEquals($val0, $val1, sprintf('property "%s"', $propName));
- if (is_array($val0) && is_array($val1)) {
- $this->assertNotArrayHashEquals($val0, $val1, $shortClassName.'::$'.$propName);
- }
- }
- }
-
- protected function assertNotHashEquals($value1, $value2, string $propertyText)
- {
- $hash0 = is_object($value1) ? md5(spl_object_hash($value1)) : null;
- $hash1 = is_object($value2) ? md5(spl_object_hash($value2)) : null;
-
- if ($hash0 && $hash1) {
- $this->assertNotEquals($hash0, $hash1, sprintf(
- 'Expected %s to have different spl_object_hash()',
- $propertyText
- ));
- }
- }
-
- protected function assertNotArrayHashEquals(array $array1, array $array2, string $path)
- {
- foreach ($array1 as $key => $val1) {
- $subPath = $path ? $path.'['.$key.']' : null;
- $val2 = $array2[$key] ?? null;
- if (is_array($val1) && is_array($val2)) {
- $this->assertNotArrayHashEquals($val1, $val2, $subPath);
- } elseif (is_object($val1) && is_object($val2)) {
- $this->assertNotHashEquals($val1, $val2, sprintf('array property "%s"', $subPath));
- }
- }
- }
-}
diff --git a/tests/AbstractJsonSerializeTestCase.php b/tests/AbstractJsonSerializeTestCase.php
new file mode 100644
index 0000000..ce0a35e
--- /dev/null
+++ b/tests/AbstractJsonSerializeTestCase.php
@@ -0,0 +1,90 @@
+getName();
+ $shortClassName = $ref->getShortName();
+ $properties = $ref->getProperties();
+
+ if (empty($properties)) {
+ self::assertTrue(true);
+ }
+
+ foreach ($properties as $property) {
+ $propName = $property->getName();
+
+ $val0 = $property->getValue($obj0);
+ $val1 = $property->getValue($obj1);
+
+ self::assertEquals(
+ $val0,
+ $val1,
+ sprintf(
+ 'Expected %s:$%s to be equal after cloning',
+ $className,
+ $propName
+ )
+ );
+ self::assertNotHashEquals($val0, $val1, sprintf('property "%s"', $propName));
+ if (is_array($val0) && is_array($val1)) {
+ self::assertNotArrayHashEquals($val0, $val1, $shortClassName . '::$' . $propName);
+ }
+ }
+ }
+
+ protected static function assertNotHashEquals(mixed $value1, mixed $value2, string $propertyText): void
+ {
+ $hash0 = is_object($value1) ? md5(spl_object_hash($value1)) : null;
+ $hash1 = is_object($value2) ? md5(spl_object_hash($value2)) : null;
+
+ if ($hash0 && $hash1) {
+ static::assertNotEquals(
+ $hash0,
+ $hash1,
+ sprintf(
+ 'Expected %s to have different spl_object_hash()',
+ $propertyText
+ )
+ );
+ }
+ }
+
+ /**
+ * @param mixed[] $array1
+ * @param mixed[] $array2
+ */
+ protected static function assertNotArrayHashEquals(array $array1, array $array2, string $path): void
+ {
+ foreach ($array1 as $key => $val1) {
+ $subPath = $path ? $path . '[' . $key . ']' : null;
+ $val2 = $array2[$key] ?? null;
+ if (is_array($val1) && is_array($val2)) {
+ self::assertNotArrayHashEquals($val1, $val2, $subPath);
+ } elseif (is_object($val1) && is_object($val2)) {
+ self::assertNotHashEquals($val1, $val2, sprintf('array property "%s"', $subPath));
+ }
+ }
+ }
+}
diff --git a/tests/AbstractRawFragmentTest.php b/tests/AbstractRawFragmentTestCase.php
similarity index 85%
rename from tests/AbstractRawFragmentTest.php
rename to tests/AbstractRawFragmentTestCase.php
index 3816635..1fb5b97 100644
--- a/tests/AbstractRawFragmentTest.php
+++ b/tests/AbstractRawFragmentTestCase.php
@@ -5,11 +5,11 @@
use ReflectionClass;
use stdClass;
-abstract class AbstractRawFragmentTest extends AbstractJsonSerializeTest
+abstract class AbstractRawFragmentTestCase extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
- $className = substr((new ReflectionClass($this))->getName(), 0, -4);
+ $className = substr((new ReflectionClass(static::class))->getName(), 0, -4);
$dataSets = [];
diff --git a/tests/Aggregation/Bucket/AdjacencyMatrixAggregationTest.php b/tests/Aggregation/Bucket/AdjacencyMatrixAggregationTest.php
index decb93f..59c409f 100644
--- a/tests/Aggregation/Bucket/AdjacencyMatrixAggregationTest.php
+++ b/tests/Aggregation/Bucket/AdjacencyMatrixAggregationTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
use InvalidArgumentException;
-class AdjacencyMatrixAggregationTest extends AbstractJsonSerializeTest
+final class AdjacencyMatrixAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -54,13 +54,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new AdjacencyMatrixAggregation([
new TermMatcher('field1', 'value1'),
new TermMatcher('field2', 'value2'),
]);
- $this->assertInstanceOf(AdjacencyMatrixAggregation::class, $agg);
+ self::assertInstanceOf(AdjacencyMatrixAggregation::class, $agg);
$this->expectException(InvalidArgumentException::class);
new AdjacencyMatrixAggregation([]);
diff --git a/tests/Aggregation/Bucket/AutoIntervalDateHistogramAggregationTest.php b/tests/Aggregation/Bucket/AutoIntervalDateHistogramAggregationTest.php
new file mode 100644
index 0000000..2b7ce55
--- /dev/null
+++ b/tests/Aggregation/Bucket/AutoIntervalDateHistogramAggregationTest.php
@@ -0,0 +1,83 @@
+ 'yyyy-MM-dd']))
+ ->setAgg('agg1', new GlobalAggregation())
+ ];
+
+ // #1
+ $dataSets[] = [
+ // language=JSON
+ '{
+ "auto_date_histogram": {
+ "field": "field1",
+ "script": "script1",
+ "buckets": 10,
+ "format": "yyyy-MM-dd"
+ },
+ "aggs": {
+ "agg1": {
+ "global": {}
+ }
+ }
+ }',
+ AutoIntervalDateHistogramAggregation::fromField(
+ 'field1',
+ 10,
+ ['format' => 'yyyy-MM-dd'],
+ new InlineScript('script1'),
+ )->setAgg('agg1', new GlobalAggregation())
+ ];
+
+
+ // #2
+ $dataSets[] = [
+ // language=JSON
+ '{
+ "auto_date_histogram": {
+
+ "script": "script1",
+ "buckets": 10,
+ "format": "yyyy-MM-dd"
+ },
+ "aggs": {
+ "agg1": {
+ "global": {}
+ }
+ }
+ }',
+ AutoIntervalDateHistogramAggregation::fromScript(
+ new InlineScript('script1'),
+ 10,
+ ['format' => 'yyyy-MM-dd'],
+ )->setAgg('agg1', new GlobalAggregation())
+ ];
+
+ return $dataSets;
+ }
+}
diff --git a/tests/Aggregation/Bucket/ChildrenAggregationTest.php b/tests/Aggregation/Bucket/ChildrenAggregationTest.php
index 7e2b74f..467df7c 100644
--- a/tests/Aggregation/Bucket/ChildrenAggregationTest.php
+++ b/tests/Aggregation/Bucket/ChildrenAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class ChildrenAggregationTest extends AbstractJsonSerializeTest
+final class ChildrenAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -30,9 +30,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new ChildrenAggregation('childrenType1');
- $this->assertInstanceOf(ChildrenAggregation::class, $agg);
+ self::assertInstanceOf(ChildrenAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/CompositeAggregationTest.php b/tests/Aggregation/Bucket/CompositeAggregationTest.php
new file mode 100644
index 0000000..21dab47
--- /dev/null
+++ b/tests/Aggregation/Bucket/CompositeAggregationTest.php
@@ -0,0 +1,39 @@
+ TermsAggregation::fromField('field1')],
+ ['agg2' => TermsAggregation::fromField('field2')]
+ ], ['size' => 10]))
+ ->setAgg('agg1', new GlobalAggregation())
+ ];
+
+ return $dataSets;
+ }
+}
diff --git a/tests/Aggregation/Bucket/DateHistogramAggregationTest.php b/tests/Aggregation/Bucket/DateHistogramAggregationTest.php
index 12fdcdb..3b780ab 100644
--- a/tests/Aggregation/Bucket/DateHistogramAggregationTest.php
+++ b/tests/Aggregation/Bucket/DateHistogramAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class DateHistogramAggregationTest extends AbstractJsonSerializeTest
+final class DateHistogramAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -58,12 +58,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = DateHistogramAggregation::fromField('field1', '1day', [], new InlineScript('source1'));
- $this->assertInstanceOf(DateHistogramAggregation::class, $agg1);
+ self::assertInstanceOf(DateHistogramAggregation::class, $agg1);
$agg2 = DateHistogramAggregation::fromScript(new InlineScript('source1'), '1day');
- $this->assertInstanceOf(DateHistogramAggregation::class, $agg2);
+ self::assertInstanceOf(DateHistogramAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Bucket/DateRangeAggregationTest.php b/tests/Aggregation/Bucket/DateRangeAggregationTest.php
index 5fa819e..e74a46f 100644
--- a/tests/Aggregation/Bucket/DateRangeAggregationTest.php
+++ b/tests/Aggregation/Bucket/DateRangeAggregationTest.php
@@ -2,25 +2,27 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class DateRangeAggregationTest extends AbstractJsonSerializeTest
+final class DateRangeAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
// #0
$dataSets[] = [
// language=JSON
- '{
+ '{
"date_range": {
"field": "field1",
- "ranges": {
+ "ranges": [
+ {
"from": "2016/02/01",
"to": "now/d",
"key": "custom_bucket_key"
- }
+ }
+ ]
},
"aggs": {
"key1": {
@@ -31,9 +33,11 @@ public function dataTestJsonSerialize(): array
(new DateRangeAggregation(
'field1',
[
- 'from' => '2016/02/01',
- 'to' => 'now/d',
- 'key' => 'custom_bucket_key'
+ [
+ 'from' => '2016/02/01',
+ 'to' => 'now/d',
+ 'key' => 'custom_bucket_key'
+ ]
]
))->setAgg('key1', new GlobalAggregation()),
];
@@ -41,16 +45,18 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new DateRangeAggregation(
'field1',
[
- 'from' => '2016/02/01',
- 'to' => 'now/d',
- 'key' => 'custom_bucket_key'
+ [
+ 'from' => '2016/02/01',
+ 'to' => 'now/d',
+ 'key' => 'custom_bucket_key'
+ ]
]
);
- $this->assertInstanceOf(DateRangeAggregation::class, $agg);
+ self::assertInstanceOf(DateRangeAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/DayOfWeekAggregationTest.php b/tests/Aggregation/Bucket/DayOfWeekAggregationTest.php
index 7ff5982..6248c09 100644
--- a/tests/Aggregation/Bucket/DayOfWeekAggregationTest.php
+++ b/tests/Aggregation/Bucket/DayOfWeekAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class DayOfWeekAggregationTest extends AbstractJsonSerializeTest
+final class DayOfWeekAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -16,8 +16,8 @@ public function dataTestJsonSerialize(): array
'{
"terms": {
"script": {
- "source": "doc[\'field1\'].date.dayOfWeek",
- "lang": "expression"
+ "source": "doc[\'field1\'].value.dayOfWeekEnum.value",
+ "lang": "painless"
}
},
"aggs": {
@@ -33,9 +33,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new DayOfWeekAggregation('field1');
- $this->assertInstanceOf(DayOfWeekAggregation::class, $agg);
+ self::assertInstanceOf(DayOfWeekAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/DiversifiedSamplerAggregationTest.php b/tests/Aggregation/Bucket/DiversifiedSamplerAggregationTest.php
index d278361..0ab2687 100644
--- a/tests/Aggregation/Bucket/DiversifiedSamplerAggregationTest.php
+++ b/tests/Aggregation/Bucket/DiversifiedSamplerAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class DiversifiedSamplerAggregationTest extends AbstractJsonSerializeTest
+final class DiversifiedSamplerAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -31,12 +31,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = DiversifiedSamplerAggregation::fromField('field1');
- $this->assertInstanceOf(DiversifiedSamplerAggregation::class, $agg1);
+ self::assertInstanceOf(DiversifiedSamplerAggregation::class, $agg1);
$agg2 = DiversifiedSamplerAggregation::fromScript(new InlineScript('source1'));
- $this->assertInstanceOf(DiversifiedSamplerAggregation::class, $agg2);
+ self::assertInstanceOf(DiversifiedSamplerAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Bucket/FilterAggregationTest.php b/tests/Aggregation/Bucket/FilterAggregationTest.php
index 878cea9..65c0b1e 100644
--- a/tests/Aggregation/Bucket/FilterAggregationTest.php
+++ b/tests/Aggregation/Bucket/FilterAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
-class FilterAggregationTest extends AbstractJsonSerializeTest
+final class FilterAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -31,9 +31,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new FilterAggregation(new MatchAllMatcher());
- $this->assertInstanceOf(FilterAggregation::class, $agg);
+ self::assertInstanceOf(FilterAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/FiltersAggregationTest.php b/tests/Aggregation/Bucket/FiltersAggregationTest.php
index 0c0ea39..a099095 100644
--- a/tests/Aggregation/Bucket/FiltersAggregationTest.php
+++ b/tests/Aggregation/Bucket/FiltersAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
-class FiltersAggregationTest extends AbstractJsonSerializeTest
+final class FiltersAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,12 +36,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new FiltersAggregation([
'filter1' => new TermMatcher('field1', 'value1'),
'filter2' => new TermMatcher('field2', 'value2'),
]);
- $this->assertInstanceOf(FiltersAggregation::class, $agg);
+ self::assertInstanceOf(FiltersAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/GeoDistanceAggregationTest.php b/tests/Aggregation/Bucket/GeoDistanceAggregationTest.php
index 19ac0f4..b35bff0 100644
--- a/tests/Aggregation/Bucket/GeoDistanceAggregationTest.php
+++ b/tests/Aggregation/Bucket/GeoDistanceAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoPoint;
-class GeoDistanceAggregationTest extends AbstractJsonSerializeTest
+final class GeoDistanceAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -18,9 +18,11 @@ public function dataTestJsonSerialize(): array
"geo_distance": {
"field": "field1",
"origin": { "lat": 1, "lon": 1 },
- "ranges": {
+ "ranges": [
+ {
"from": 10
- }
+ }
+ ]
},
"aggs": {
"key1": {
@@ -32,7 +34,9 @@ public function dataTestJsonSerialize(): array
'field1',
new GeoPoint(1, 1),
[
- 'from' => 10,
+ [
+ 'from' => 10,
+ ]
]
))->setAgg('key1', new GlobalAggregation()),
];
@@ -40,15 +44,17 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new GeoDistanceAggregation(
'field1',
new GeoPoint(1, 1),
[
- 'from' => 10,
+ [
+ 'from' => 10,
+ ]
]
);
- $this->assertInstanceOf(GeoDistanceAggregation::class, $agg);
+ self::assertInstanceOf(GeoDistanceAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/GeoHashGridAggregationTest.php b/tests/Aggregation/Bucket/GeoHashGridAggregationTest.php
index 4c16d8a..4a737d1 100644
--- a/tests/Aggregation/Bucket/GeoHashGridAggregationTest.php
+++ b/tests/Aggregation/Bucket/GeoHashGridAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class GeoHashGridAggregationTest extends AbstractJsonSerializeTest
+final class GeoHashGridAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -30,9 +30,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new GeoHashGridAggregation('field1');
- $this->assertInstanceOf(GeoHashGridAggregation::class, $agg);
+ self::assertInstanceOf(GeoHashGridAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/GlobalAggregationTest.php b/tests/Aggregation/Bucket/GlobalAggregationTest.php
index c3432f2..615b900 100644
--- a/tests/Aggregation/Bucket/GlobalAggregationTest.php
+++ b/tests/Aggregation/Bucket/GlobalAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class GlobalAggregationTest extends AbstractJsonSerializeTest
+final class GlobalAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -28,9 +28,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new GlobalAggregation();
- $this->assertInstanceOf(GlobalAggregation::class, $agg);
+ self::assertInstanceOf(GlobalAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/HistogramAggregationTest.php b/tests/Aggregation/Bucket/HistogramAggregationTest.php
index 06cb03d..00366d3 100644
--- a/tests/Aggregation/Bucket/HistogramAggregationTest.php
+++ b/tests/Aggregation/Bucket/HistogramAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class HistogramAggregationTest extends AbstractJsonSerializeTest
+final class HistogramAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -47,12 +47,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = HistogramAggregation::fromField('field1', 5.0, [], new InlineScript('source1'));
- $this->assertInstanceOf(HistogramAggregation::class, $agg1);
+ self::assertInstanceOf(HistogramAggregation::class, $agg1);
$agg2 = HistogramAggregation::fromScript(new InlineScript('source1'), 5.0);
- $this->assertInstanceOf(HistogramAggregation::class, $agg2);
+ self::assertInstanceOf(HistogramAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Bucket/IpRangeAggregationTest.php b/tests/Aggregation/Bucket/IpRangeAggregationTest.php
index 1e453dc..9f865d4 100644
--- a/tests/Aggregation/Bucket/IpRangeAggregationTest.php
+++ b/tests/Aggregation/Bucket/IpRangeAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class IpRangeAggregationTest extends AbstractJsonSerializeTest
+final class IpRangeAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,12 +36,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new IpRangeAggregation('field1', [
['from' => '10.0.0.5', 'to' => '10.0.0.5', 'key' => 'custom_bucket_key'],
['mask' => '10.0.0.0/25', 'key' => 'custom_bucket_key'],
]);
- $this->assertInstanceOf(IpRangeAggregation::class, $agg);
+ self::assertInstanceOf(IpRangeAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/MissingAggregationTest.php b/tests/Aggregation/Bucket/MissingAggregationTest.php
index 5754172..ac05950 100644
--- a/tests/Aggregation/Bucket/MissingAggregationTest.php
+++ b/tests/Aggregation/Bucket/MissingAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MissingAggregationTest extends AbstractJsonSerializeTest
+final class MissingAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -29,9 +29,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new MissingAggregation('field1');
- $this->assertInstanceOf(MissingAggregation::class, $agg);
+ self::assertInstanceOf(MissingAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/NestedAggregationTest.php b/tests/Aggregation/Bucket/NestedAggregationTest.php
index 3898b38..76bee5e 100644
--- a/tests/Aggregation/Bucket/NestedAggregationTest.php
+++ b/tests/Aggregation/Bucket/NestedAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class NestedAggregationTest extends AbstractJsonSerializeTest
+final class NestedAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -24,7 +24,7 @@ public function dataTestJsonSerialize(): array
}
}
}
-
+
}',
(new NestedAggregation('path1'))
->setAgg('key1', TermsAggregation::fromField('path1.field1')),
@@ -33,9 +33,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new NestedAggregation('path1');
- $this->assertInstanceOf(NestedAggregation::class, $agg);
+ self::assertInstanceOf(NestedAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/ParentAggregationTest.php b/tests/Aggregation/Bucket/ParentAggregationTest.php
new file mode 100644
index 0000000..fa4918d
--- /dev/null
+++ b/tests/Aggregation/Bucket/ParentAggregationTest.php
@@ -0,0 +1,31 @@
+setAgg('agg1', new GlobalAggregation())
+ ];
+
+ return $dataSets;
+ }
+}
diff --git a/tests/Aggregation/Bucket/RangeAggregationTest.php b/tests/Aggregation/Bucket/RangeAggregationTest.php
index bed8e14..7fac9f5 100644
--- a/tests/Aggregation/Bucket/RangeAggregationTest.php
+++ b/tests/Aggregation/Bucket/RangeAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class RangeAggregationTest extends AbstractJsonSerializeTest
+final class RangeAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -58,7 +58,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = RangeAggregation::fromField(
'field1',
@@ -68,11 +68,11 @@ public function testMethods()
[],
new InlineScript('source1')
);
- $this->assertInstanceOf(RangeAggregation::class, $agg);
+ self::assertInstanceOf(RangeAggregation::class, $agg);
$agg = RangeAggregation::fromScript(new InlineScript('source1'), [
['from' => 5, 'to' => 5, 'key' => 'custom_bucket_key'],
]);
- $this->assertInstanceOf(RangeAggregation::class, $agg);
+ self::assertInstanceOf(RangeAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/RawBucketAggregationTest.php b/tests/Aggregation/Bucket/RawBucketAggregationTest.php
index c48ede2..0b612ec 100644
--- a/tests/Aggregation/Bucket/RawBucketAggregationTest.php
+++ b/tests/Aggregation/Bucket/RawBucketAggregationTest.php
@@ -4,13 +4,14 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\RawAggregation;
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
+use stdClass;
-class RawBucketAggregationTest extends RawFragmentTest
+final class RawBucketAggregationTest extends RawFragmentTest
{
- public function testJsonSerializeWithAggs()
+ public function testJsonSerializeWithAggs(): void
{
- $agg = new RawBucketAggregation(['agg_type_1' => new \stdClass()]);
- $agg->setAgg('agg1', new RawAggregation(['agg_type_2' => new \stdClass()]));
+ $agg = new RawBucketAggregation(['agg_type_1' => new stdClass()]);
+ $agg->setAgg('agg1', new RawAggregation(['agg_type_2' => new stdClass()]));
$actualJson = json_encode($agg->jsonSerialize());
@@ -24,14 +25,14 @@ public function testJsonSerializeWithAggs()
}
}';
- $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson);
+ self::assertJsonStringEqualsJsonString($expectedJson, $actualJson);
$this->testClone('', $agg);
}
- public function testMethods()
+ public function testMethods(): void
{
- $agg = new RawBucketAggregation(['agg_type_1' => new \stdClass()]);
- $this->assertInstanceOf(RawBucketAggregation::class, $agg);
+ $agg = new RawBucketAggregation(['agg_type_1' => new stdClass()]);
+ self::assertInstanceOf(RawBucketAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/ReverseNestedAggregationTest.php b/tests/Aggregation/Bucket/ReverseNestedAggregationTest.php
index 4cd252d..fc145c3 100644
--- a/tests/Aggregation/Bucket/ReverseNestedAggregationTest.php
+++ b/tests/Aggregation/Bucket/ReverseNestedAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class ReverseNestedAggregationTest extends AbstractJsonSerializeTest
+final class ReverseNestedAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -39,12 +39,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = new ReverseNestedAggregation('path1');
- $this->assertInstanceOf(ReverseNestedAggregation::class, $agg1);
+ self::assertInstanceOf(ReverseNestedAggregation::class, $agg1);
$agg2 = new ReverseNestedAggregation();
- $this->assertInstanceOf(ReverseNestedAggregation::class, $agg2);
+ self::assertInstanceOf(ReverseNestedAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Bucket/SamplerAggregationTest.php b/tests/Aggregation/Bucket/SamplerAggregationTest.php
index cc331f6..e96caf1 100644
--- a/tests/Aggregation/Bucket/SamplerAggregationTest.php
+++ b/tests/Aggregation/Bucket/SamplerAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SamplerAggregationTest extends AbstractJsonSerializeTest
+final class SamplerAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -38,9 +38,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new SamplerAggregation();
- $this->assertInstanceOf(SamplerAggregation::class, $agg);
+ self::assertInstanceOf(SamplerAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/SignificantTermsAggregationTest.php b/tests/Aggregation/Bucket/SignificantTermsAggregationTest.php
index aeae06e..2094521 100644
--- a/tests/Aggregation/Bucket/SignificantTermsAggregationTest.php
+++ b/tests/Aggregation/Bucket/SignificantTermsAggregationTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class SignificantTermsAggregationTest extends AbstractJsonSerializeTest
+final class SignificantTermsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -41,13 +41,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = (new SignificantTermsAggregation('field1'))
->setOption('mutual_information', ['include_negatives' => false, 'background_is_superset' => false])
->setOption('background_filter', new MatchAllMatcher())
->setOption('scripted_heuristic', new InlineScript('source1'))
->setAgg('key1', new GlobalAggregation());
- $this->assertInstanceOf(SignificantTermsAggregation::class, $agg);
+ self::assertInstanceOf(SignificantTermsAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Bucket/SignificantTextAggregationTest.php b/tests/Aggregation/Bucket/SignificantTextAggregationTest.php
new file mode 100644
index 0000000..4fc28e1
--- /dev/null
+++ b/tests/Aggregation/Bucket/SignificantTextAggregationTest.php
@@ -0,0 +1,33 @@
+ 3]))
+ ->setAgg('agg1', new GlobalAggregation())
+ ];
+
+ return $dataSets;
+ }
+}
diff --git a/tests/Aggregation/Bucket/TermsAggregationTest.php b/tests/Aggregation/Bucket/TermsAggregationTest.php
index 63f475c..d5c99ca 100644
--- a/tests/Aggregation/Bucket/TermsAggregationTest.php
+++ b/tests/Aggregation/Bucket/TermsAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Bucket;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class TermsAggregationTest extends AbstractJsonSerializeTest
+final class TermsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -49,12 +49,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = TermsAggregation::fromField('field1', ['order' => ['_count' => 'asc']], new InlineScript('source1'));
- $this->assertInstanceOf(TermsAggregation::class, $agg1);
+ self::assertInstanceOf(TermsAggregation::class, $agg1);
$agg2 = TermsAggregation::fromScript(new InlineScript('source1'), ['order' => ['_count' => 'asc']]);
- $this->assertInstanceOf(TermsAggregation::class, $agg2);
+ self::assertInstanceOf(TermsAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/EmptyAggregationTest.php b/tests/Aggregation/EmptyAggregationTest.php
index 4e3ec5d..a045ac3 100644
--- a/tests/Aggregation/EmptyAggregationTest.php
+++ b/tests/Aggregation/EmptyAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class EmptyAggregationTest extends AbstractJsonSerializeTest
+final class EmptyAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Matrix/MatrixStatsAggregationTest.php b/tests/Aggregation/Matrix/MatrixStatsAggregationTest.php
index 07cac1e..b481ac2 100644
--- a/tests/Aggregation/Matrix/MatrixStatsAggregationTest.php
+++ b/tests/Aggregation/Matrix/MatrixStatsAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Matrix;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MatrixStatsAggregationTest extends AbstractJsonSerializeTest
+final class MatrixStatsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -40,13 +40,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new MatrixStatsAggregation(
'field1',
'field2'
);
- $this->assertInstanceOf(MatrixStatsAggregation::class, $agg);
+ self::assertInstanceOf(MatrixStatsAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Matrix/RawMatrixAggregationTest.php b/tests/Aggregation/Matrix/RawMatrixAggregationTest.php
index 58877e3..2e13c1c 100644
--- a/tests/Aggregation/Matrix/RawMatrixAggregationTest.php
+++ b/tests/Aggregation/Matrix/RawMatrixAggregationTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawMatrixAggregationTest extends RawFragmentTest
+final class RawMatrixAggregationTest extends RawFragmentTest
{
}
diff --git a/tests/Aggregation/Metric/AvgAggregationTest.php b/tests/Aggregation/Metric/AvgAggregationTest.php
index cf250b6..694e987 100644
--- a/tests/Aggregation/Metric/AvgAggregationTest.php
+++ b/tests/Aggregation/Metric/AvgAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class AvgAggregationTest extends AbstractJsonSerializeTest
+final class AvgAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -49,12 +49,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = AvgAggregation::fromField('field1', ['missing' => 0], new InlineScript('source1'));
- $this->assertInstanceOf(AvgAggregation::class, $agg1);
+ self::assertInstanceOf(AvgAggregation::class, $agg1);
$agg2 = AvgAggregation::fromScript(new InlineScript('source1'));
- $this->assertInstanceOf(AvgAggregation::class, $agg2);
+ self::assertInstanceOf(AvgAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Metric/CardinalityAggregationTest.php b/tests/Aggregation/Metric/CardinalityAggregationTest.php
index 6510e91..a8db51e 100644
--- a/tests/Aggregation/Metric/CardinalityAggregationTest.php
+++ b/tests/Aggregation/Metric/CardinalityAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class CardinalityAggregationTest extends AbstractJsonSerializeTest
+final class CardinalityAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,12 +36,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = CardinalityAggregation::fromField('field1', ['precision_threshold' => 3000]);
- $this->assertInstanceOf(CardinalityAggregation::class, $agg1);
+ self::assertInstanceOf(CardinalityAggregation::class, $agg1);
$agg2 = CardinalityAggregation::fromScript(new InlineScript('source1'));
- $this->assertInstanceOf(CardinalityAggregation::class, $agg2);
+ self::assertInstanceOf(CardinalityAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Metric/ExtendedStatsAggregationTest.php b/tests/Aggregation/Metric/ExtendedStatsAggregationTest.php
index 3321e2c..0cca818 100644
--- a/tests/Aggregation/Metric/ExtendedStatsAggregationTest.php
+++ b/tests/Aggregation/Metric/ExtendedStatsAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class ExtendedStatsAggregationTest extends AbstractJsonSerializeTest
+final class ExtendedStatsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Metric/GeoBoundsAggregationTest.php b/tests/Aggregation/Metric/GeoBoundsAggregationTest.php
index 33c77f3..94df9de 100644
--- a/tests/Aggregation/Metric/GeoBoundsAggregationTest.php
+++ b/tests/Aggregation/Metric/GeoBoundsAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class GeoBoundsAggregationTest extends AbstractJsonSerializeTest
+final class GeoBoundsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -24,10 +24,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new GeoBoundsAggregation('field1');
- $this->assertInstanceOf(GeoBoundsAggregation::class, $agg);
+ self::assertInstanceOf(GeoBoundsAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Metric/GeoCentroidAggregationTest.php b/tests/Aggregation/Metric/GeoCentroidAggregationTest.php
index 8e10f64..f600279 100644
--- a/tests/Aggregation/Metric/GeoCentroidAggregationTest.php
+++ b/tests/Aggregation/Metric/GeoCentroidAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class GeoCentroidAggregationTest extends AbstractJsonSerializeTest
+final class GeoCentroidAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -24,10 +24,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new GeoCentroidAggregation('field1');
- $this->assertInstanceOf(GeoCentroidAggregation::class, $agg);
+ self::assertInstanceOf(GeoCentroidAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Metric/MaxAggregationTest.php b/tests/Aggregation/Metric/MaxAggregationTest.php
index 463630d..944e653 100644
--- a/tests/Aggregation/Metric/MaxAggregationTest.php
+++ b/tests/Aggregation/Metric/MaxAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MaxAggregationTest extends AbstractJsonSerializeTest
+final class MaxAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Metric/MedianAbsoluteDeviationAggregationTest.php b/tests/Aggregation/Metric/MedianAbsoluteDeviationAggregationTest.php
new file mode 100644
index 0000000..49bab58
--- /dev/null
+++ b/tests/Aggregation/Metric/MedianAbsoluteDeviationAggregationTest.php
@@ -0,0 +1,40 @@
+ 1])
+ ];
+
+ // #1
+ $dataSets[] = [
+ // language=JSON
+ '{
+ "median_absolute_deviation": {
+ "script": "script1",
+ "missing": 1
+ }
+ }',
+ new MedianAbsoluteDeviationAggregation(new InlineScript('script1'), ['missing' => 1])
+ ];
+
+ return $dataSets;
+ }
+}
diff --git a/tests/Aggregation/Metric/MinAggregationTest.php b/tests/Aggregation/Metric/MinAggregationTest.php
index 3674702..cee3100 100644
--- a/tests/Aggregation/Metric/MinAggregationTest.php
+++ b/tests/Aggregation/Metric/MinAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MinAggregationTest extends AbstractJsonSerializeTest
+final class MinAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Metric/PercentileRanksAggregationTest.php b/tests/Aggregation/Metric/PercentileRanksAggregationTest.php
index 9c638bc..7675de3 100644
--- a/tests/Aggregation/Metric/PercentileRanksAggregationTest.php
+++ b/tests/Aggregation/Metric/PercentileRanksAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class PercentileRanksAggregationTest extends AbstractJsonSerializeTest
+final class PercentileRanksAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -65,7 +65,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = PercentileRanksAggregation::fromField(
'field1',
@@ -73,13 +73,13 @@ public function testMethods()
['keyed' => true],
new InlineScript('source1')
);
- $this->assertInstanceOf(PercentileRanksAggregation::class, $agg1);
+ self::assertInstanceOf(PercentileRanksAggregation::class, $agg1);
$agg2 = PercentileRanksAggregation::fromScript(
['value1', 'value2'],
new InlineScript('source1'),
['keyed' => true]
);
- $this->assertInstanceOf(PercentileRanksAggregation::class, $agg2);
+ self::assertInstanceOf(PercentileRanksAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Metric/PercentilesAggregationTest.php b/tests/Aggregation/Metric/PercentilesAggregationTest.php
index 827861f..42500d2 100644
--- a/tests/Aggregation/Metric/PercentilesAggregationTest.php
+++ b/tests/Aggregation/Metric/PercentilesAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class PercentilesAggregationTest extends AbstractJsonSerializeTest
+final class PercentilesAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -26,12 +26,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = PercentilesAggregation::fromField('field1', ['percents' => [1, 2, 3]], new InlineScript('source1'));
- $this->assertInstanceOf(PercentilesAggregation::class, $agg1);
+ self::assertInstanceOf(PercentilesAggregation::class, $agg1);
$agg2 = PercentilesAggregation::fromScript(new InlineScript('source1'), ['percents' => [1, 2, 3]]);
- $this->assertInstanceOf(PercentilesAggregation::class, $agg2);
+ self::assertInstanceOf(PercentilesAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Metric/RawMetricAggregationTest.php b/tests/Aggregation/Metric/RawMetricAggregationTest.php
index 755a783..a81eed5 100644
--- a/tests/Aggregation/Metric/RawMetricAggregationTest.php
+++ b/tests/Aggregation/Metric/RawMetricAggregationTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawMetricAggregationTest extends RawFragmentTest
+final class RawMetricAggregationTest extends RawFragmentTest
{
}
diff --git a/tests/Aggregation/Metric/ScriptedMetricAggregationTest.php b/tests/Aggregation/Metric/ScriptedMetricAggregationTest.php
index eaa3db6..663c414 100644
--- a/tests/Aggregation/Metric/ScriptedMetricAggregationTest.php
+++ b/tests/Aggregation/Metric/ScriptedMetricAggregationTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use UnexpectedValueException;
-class ScriptedMetricAggregationTest extends AbstractJsonSerializeTest
+final class ScriptedMetricAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -43,7 +43,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = (new ScriptedMetricAggregation())
->setInitScript(new InlineScript('source1'))
@@ -57,16 +57,16 @@ public function testMethods()
->setParam('param3', 'value3')
->removeParam('param1');
- $this->assertEquals(new InlineScript('source1'), $agg->getInitScript());
- $this->assertEquals(new InlineScript('source2'), $agg->getMapScript());
- $this->assertEquals(new InlineScript('source3'), $agg->getCombineScript());
- $this->assertEquals(new InlineScript('source4'), $agg->getReduceScript());
- $this->assertEquals([
+ self::assertEquals(new InlineScript('source1'), $agg->getInitScript());
+ self::assertEquals(new InlineScript('source2'), $agg->getMapScript());
+ self::assertEquals(new InlineScript('source3'), $agg->getCombineScript());
+ self::assertEquals(new InlineScript('source4'), $agg->getReduceScript());
+ self::assertEquals([
'param2' => 'value2',
'param3' => 'value3',
], $agg->getParams());
- $this->assertEquals(null, $agg->getParam('param1'));
- $this->assertEquals('value2', $agg->getParam('param2'));
+ self::assertEquals(null, $agg->getParam('param1'));
+ self::assertEquals('value2', $agg->getParam('param2'));
$this->expectException(UnexpectedValueException::class);
(new ScriptedMetricAggregation())->jsonSerialize();
diff --git a/tests/Aggregation/Metric/StatsAggregationTest.php b/tests/Aggregation/Metric/StatsAggregationTest.php
index 762c1cc..7f6cfc3 100644
--- a/tests/Aggregation/Metric/StatsAggregationTest.php
+++ b/tests/Aggregation/Metric/StatsAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class StatsAggregationTest extends AbstractJsonSerializeTest
+final class StatsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Metric/SumAggregationTest.php b/tests/Aggregation/Metric/SumAggregationTest.php
index 92dc086..e800232 100644
--- a/tests/Aggregation/Metric/SumAggregationTest.php
+++ b/tests/Aggregation/Metric/SumAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SumAggregationTest extends AbstractJsonSerializeTest
+final class SumAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Metric/TopHitsAggregationTest.php b/tests/Aggregation/Metric/TopHitsAggregationTest.php
index c0cff0f..7f05423 100644
--- a/tests/Aggregation/Metric/TopHitsAggregationTest.php
+++ b/tests/Aggregation/Metric/TopHitsAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\SearchRequest\TopHitsRequest;
-class TopHitsAggregationTest extends AbstractJsonSerializeTest
+final class TopHitsAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,12 +36,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$req = new TopHitsAggregation(
(new TopHitsRequest())->setSize(1)
);
- $this->assertInstanceOf(TopHitsAggregation::class, $req);
+ self::assertInstanceOf(TopHitsAggregation::class, $req);
}
}
diff --git a/tests/Aggregation/Metric/ValueCountAggregationTest.php b/tests/Aggregation/Metric/ValueCountAggregationTest.php
index 69c9b71..ace8e8b 100644
--- a/tests/Aggregation/Metric/ValueCountAggregationTest.php
+++ b/tests/Aggregation/Metric/ValueCountAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Metric;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class ValueCountAggregationTest extends AbstractJsonSerializeTest
+final class ValueCountAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,12 +36,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg1 = ValueCountAggregation::fromField('field1');
- $this->assertInstanceOf(ValueCountAggregation::class, $agg1);
+ self::assertInstanceOf(ValueCountAggregation::class, $agg1);
$agg2 = ValueCountAggregation::fromScript(new InlineScript('source1'));
- $this->assertInstanceOf(ValueCountAggregation::class, $agg2);
+ self::assertInstanceOf(ValueCountAggregation::class, $agg2);
}
}
diff --git a/tests/Aggregation/Metric/WeightedAvgAggregationTest.php b/tests/Aggregation/Metric/WeightedAvgAggregationTest.php
new file mode 100644
index 0000000..7b28bba
--- /dev/null
+++ b/tests/Aggregation/Metric/WeightedAvgAggregationTest.php
@@ -0,0 +1,66 @@
+ 'yyyy']
+ )
+ ];
+
+ // #1
+ $dataSets[] = [
+ // language=JSON
+ '{
+ "weighted_avg": {
+ "value": {
+ "script": "value1",
+ "missing": "missing1"
+ },
+ "weight": {
+ "script": "weight1",
+ "missing": "missing2"
+ },
+ "format": "yyyy"
+ }
+ }',
+ new WeightedAvgAggregation(
+ new InlineScript('value1'),
+ new InlineScript('weight1'),
+ 'missing1',
+ 'missing2',
+ ['format' => 'yyyy']
+ )
+ ];
+
+ return $dataSets;
+ }
+}
diff --git a/tests/Aggregation/Pipeline/Parent/BucketScriptAggregationTest.php b/tests/Aggregation/Pipeline/Parent/BucketScriptAggregationTest.php
index 484636e..29f796b 100644
--- a/tests/Aggregation/Pipeline/Parent/BucketScriptAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Parent/BucketScriptAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Parent;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class BucketScriptAggregationTest extends AbstractJsonSerializeTest
+final class BucketScriptAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -35,7 +35,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new BucketScriptAggregation(
[
@@ -45,6 +45,6 @@ public function testMethods()
new InlineScript('params.var1 / params.var2')
);
- $this->assertInstanceOf(BucketScriptAggregation::class, $agg);
+ self::assertInstanceOf(BucketScriptAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Pipeline/Parent/BucketSelectorAggregationTest.php b/tests/Aggregation/Pipeline/Parent/BucketSelectorAggregationTest.php
index f7fb0c6..342220f 100644
--- a/tests/Aggregation/Pipeline/Parent/BucketSelectorAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Parent/BucketSelectorAggregationTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Parent;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class BucketSelectorAggregationTest extends AbstractJsonSerializeTest
+final class BucketSelectorAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -35,7 +35,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$agg = new BucketSelectorAggregation(
[
@@ -45,6 +45,6 @@ public function testMethods()
new InlineScript('params.var1 > params.var2')
);
- $this->assertInstanceOf(BucketSelectorAggregation::class, $agg);
+ self::assertInstanceOf(BucketSelectorAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Pipeline/Parent/BucketSortAggregationTest.php b/tests/Aggregation/Pipeline/Parent/BucketSortAggregationTest.php
new file mode 100644
index 0000000..f4d6959
--- /dev/null
+++ b/tests/Aggregation/Pipeline/Parent/BucketSortAggregationTest.php
@@ -0,0 +1,29 @@
+setOption('key1', 'value1');
- $this->assertInstanceOf(AvgBucketAggregation::class, $agg);
+ self::assertInstanceOf(AvgBucketAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregationTest.php
index 1b4c93d..f95f20e 100644
--- a/tests/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Sibling/ExtendedStatsBucketAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class ExtendedStatsBucketAggregationTest extends AbstractJsonSerializeTest
+final class ExtendedStatsBucketAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Pipeline/Sibling/MaxBucketAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/MaxBucketAggregationTest.php
index 7cb0d08..7c6c1a2 100644
--- a/tests/Aggregation/Pipeline/Sibling/MaxBucketAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Sibling/MaxBucketAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MaxBucketAggregationTest extends AbstractJsonSerializeTest
+final class MaxBucketAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Pipeline/Sibling/MinBucketAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/MinBucketAggregationTest.php
index c3a656c..2f7e861 100644
--- a/tests/Aggregation/Pipeline/Sibling/MinBucketAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Sibling/MinBucketAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MinBucketAggregationTest extends AbstractJsonSerializeTest
+final class MinBucketAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Pipeline/Sibling/MovingAvgAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/MovingAvgAggregationTest.php
index 0557884..684fc41 100644
--- a/tests/Aggregation/Pipeline/Sibling/MovingAvgAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Sibling/MovingAvgAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MovingAvgAggregationTest extends AbstractJsonSerializeTest
+final class MovingAvgAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Pipeline/Sibling/MovingFunctionAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/MovingFunctionAggregationTest.php
new file mode 100644
index 0000000..85e970a
--- /dev/null
+++ b/tests/Aggregation/Pipeline/Sibling/MovingFunctionAggregationTest.php
@@ -0,0 +1,29 @@
+ 'insert_zeros',
]);
- $this->assertInstanceOf(SerialDifferencingBucketAggregation::class, $agg);
+ self::assertInstanceOf(SerialDifferencingBucketAggregation::class, $agg);
}
}
diff --git a/tests/Aggregation/Pipeline/Sibling/StatsBucketAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/StatsBucketAggregationTest.php
index a09fe7f..086fb03 100644
--- a/tests/Aggregation/Pipeline/Sibling/StatsBucketAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Sibling/StatsBucketAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class StatsBucketAggregationTest extends AbstractJsonSerializeTest
+final class StatsBucketAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/Pipeline/Sibling/SumBucketAggregationTest.php b/tests/Aggregation/Pipeline/Sibling/SumBucketAggregationTest.php
index 3cdbe84..598c8ac 100644
--- a/tests/Aggregation/Pipeline/Sibling/SumBucketAggregationTest.php
+++ b/tests/Aggregation/Pipeline/Sibling/SumBucketAggregationTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Aggregation\Pipeline\Sibling;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SumBucketAggregationTest extends AbstractJsonSerializeTest
+final class SumBucketAggregationTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Aggregation/RawAggregationTest.php b/tests/Aggregation/RawAggregationTest.php
index 1b3b0c6..886f92c 100644
--- a/tests/Aggregation/RawAggregationTest.php
+++ b/tests/Aggregation/RawAggregationTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawAggregationTest extends RawFragmentTest
+final class RawAggregationTest extends RawFragmentTest
{
}
diff --git a/tests/FieldCollapser/FieldCollapserTest.php b/tests/FieldCollapser/FieldCollapserTest.php
index 7e86e62..9c1f617 100644
--- a/tests/FieldCollapser/FieldCollapserTest.php
+++ b/tests/FieldCollapser/FieldCollapserTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\FieldCollapser;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
-class FieldCollapserTest extends AbstractJsonSerializeTest
+final class FieldCollapserTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -43,12 +43,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$givenCollapser = new FieldCollapser('field1');
- $this->assertEquals('field1', $givenCollapser->getField());
- $this->assertEquals([], $givenCollapser->getInnerHits());
+ self::assertEquals('field1', $givenCollapser->getField());
+ self::assertEquals([], $givenCollapser->getInnerHits());
$givenCollapser->setInnerHits([
(new InnerHitsRequest())->setName('name1'),
@@ -56,7 +56,7 @@ public function testMethods()
]);
$givenCollapser->addInnerHits((new InnerHitsRequest())->setName('name3'));
- $this->assertEquals([
+ self::assertEquals([
(new InnerHitsRequest())->setName('name1'),
(new InnerHitsRequest())->setName('name2'),
(new InnerHitsRequest())->setName('name3'),
diff --git a/tests/FieldCollapser/RawFieldCollapserTest.php b/tests/FieldCollapser/RawFieldCollapserTest.php
index 8ac7c84..135f58b 100644
--- a/tests/FieldCollapser/RawFieldCollapserTest.php
+++ b/tests/FieldCollapser/RawFieldCollapserTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawFieldCollapserTest extends RawFragmentTest
+final class RawFieldCollapserTest extends RawFragmentTest
{
}
diff --git a/tests/HasAggsTraitTest.php b/tests/HasAggsTraitTest.php
index e7ba0d3..5b23970 100644
--- a/tests/HasAggsTraitTest.php
+++ b/tests/HasAggsTraitTest.php
@@ -6,38 +6,37 @@
use Gskema\ElasticSearchQueryDSL\Aggregation\EmptyAggregation;
use PHPUnit\Framework\TestCase;
-class HasAggsTraitTest extends TestCase
+final class HasAggsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasAggsTrait $givenObject */
- $givenObject = $this
- ->getMockBuilder(HasAggsTrait::class)
- ->setMethods(null)
- ->getMockForTrait();
+ $givenObject = new class {
+ use HasAggsTrait;
+ };
- $this->assertEquals(false, $givenObject->hasAggs());
- $this->assertEquals(false, $givenObject->hasAgg('key1'));
+ self::assertEquals(false, $givenObject->hasAggs());
+ self::assertEquals(false, $givenObject->hasAgg('key1'));
$givenObject->setAggs(['key1' => new GlobalAggregation()]);
$givenObject->setAgg('key2', new EmptyAggregation('stats'));
- $this->assertEquals(true, $givenObject->hasAggs());
- $this->assertEquals(true, $givenObject->hasAgg('key1'));
- $this->assertEquals(true, $givenObject->hasAgg('key2'));
- $this->assertEquals(false, $givenObject->hasAgg('key3'));
+ self::assertEquals(true, $givenObject->hasAggs());
+ self::assertEquals(true, $givenObject->hasAgg('key1'));
+ self::assertEquals(true, $givenObject->hasAgg('key2'));
+ self::assertEquals(false, $givenObject->hasAgg('key3'));
- $this->assertEquals(new GlobalAggregation(), $givenObject->getAgg('key1'));
- $this->assertEquals(new EmptyAggregation('stats'), $givenObject->getAgg('key2'));
- $this->assertEquals([
+ self::assertEquals(new GlobalAggregation(), $givenObject->getAgg('key1'));
+ self::assertEquals(new EmptyAggregation('stats'), $givenObject->getAgg('key2'));
+ self::assertEquals([
'key1' => new GlobalAggregation(),
'key2' => new EmptyAggregation('stats'),
], $givenObject->getAggs());
$givenObject->removeAgg('key2');
- $this->assertEquals(['key1' => new GlobalAggregation()], $givenObject->getAggs());
+ self::assertEquals(['key1' => new GlobalAggregation()], $givenObject->getAggs());
$givenObject->removeAggs();
- $this->assertEquals([], $givenObject->getAggs());
+ self::assertEquals([], $givenObject->getAggs());
}
}
diff --git a/tests/HasOptionsTraitTest.php b/tests/HasOptionsTraitTest.php
index 3dff234..c03acdc 100644
--- a/tests/HasOptionsTraitTest.php
+++ b/tests/HasOptionsTraitTest.php
@@ -4,38 +4,37 @@
use PHPUnit\Framework\TestCase;
-class HasOptionsTraitTest extends TestCase
+final class HasOptionsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasOptionsTrait $givenObject */
- $givenObject = $this
- ->getMockBuilder(HasOptionsTrait::class)
- ->setMethods(null)
- ->getMockForTrait();
+ $givenObject = new class {
+ use HasOptionsTrait;
+ };
- $this->assertEquals(false, $givenObject->hasOptions());
- $this->assertEquals(false, $givenObject->hasOption('key1'));
+ self::assertEquals(false, $givenObject->hasOptions());
+ self::assertEquals(false, $givenObject->hasOption('key1'));
$givenObject->setOptions(['key1' => 'value1']);
$givenObject->setOption('key2', 'value2');
- $this->assertEquals(true, $givenObject->hasOptions());
- $this->assertEquals(true, $givenObject->hasOption('key1'));
- $this->assertEquals(true, $givenObject->hasOption('key2'));
- $this->assertEquals(false, $givenObject->hasOption('key3'));
+ self::assertEquals(true, $givenObject->hasOptions());
+ self::assertEquals(true, $givenObject->hasOption('key1'));
+ self::assertEquals(true, $givenObject->hasOption('key2'));
+ self::assertEquals(false, $givenObject->hasOption('key3'));
- $this->assertEquals('value1', $givenObject->getOption('key1'));
- $this->assertEquals('value2', $givenObject->getOption('key2'));
- $this->assertEquals([
+ self::assertEquals('value1', $givenObject->getOption('key1'));
+ self::assertEquals('value2', $givenObject->getOption('key2'));
+ self::assertEquals([
'key1' => 'value1',
'key2' => 'value2',
], $givenObject->getOptions());
$givenObject->removeOption('key2');
- $this->assertEquals(['key1' => 'value1'], $givenObject->getOptions());
+ self::assertEquals(['key1' => 'value1'], $givenObject->getOptions());
$givenObject->removeOptions();
- $this->assertEquals([], $givenObject->getOptions());
+ self::assertEquals([], $givenObject->getOptions());
}
}
diff --git a/tests/HasParametersTraitTest.php b/tests/HasParametersTraitTest.php
index 9229a17..7bdcf03 100644
--- a/tests/HasParametersTraitTest.php
+++ b/tests/HasParametersTraitTest.php
@@ -4,38 +4,37 @@
use PHPUnit\Framework\TestCase;
-class HasParametersTraitTest extends TestCase
+final class HasParametersTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasParametersTrait $givenObject */
- $givenObject = $this
- ->getMockBuilder(HasParametersTrait::class)
- ->setMethods(null)
- ->getMockForTrait();
+ $givenObject = new class {
+ use HasParametersTrait;
+ };
- $this->assertEquals(false, $givenObject->hasParameters());
- $this->assertEquals(false, $givenObject->hasParameter('key1'));
+ self::assertEquals(false, $givenObject->hasParameters());
+ self::assertEquals(false, $givenObject->hasParameter('key1'));
$givenObject->setParameters(['key1' => 'value1']);
$givenObject->setParameter('key2', 'value2');
- $this->assertEquals(true, $givenObject->hasParameters());
- $this->assertEquals(true, $givenObject->hasParameter('key1'));
- $this->assertEquals(true, $givenObject->hasParameter('key2'));
- $this->assertEquals(false, $givenObject->hasParameter('key3'));
+ self::assertEquals(true, $givenObject->hasParameters());
+ self::assertEquals(true, $givenObject->hasParameter('key1'));
+ self::assertEquals(true, $givenObject->hasParameter('key2'));
+ self::assertEquals(false, $givenObject->hasParameter('key3'));
- $this->assertEquals('value1', $givenObject->getParameter('key1'));
- $this->assertEquals('value2', $givenObject->getParameter('key2'));
- $this->assertEquals([
+ self::assertEquals('value1', $givenObject->getParameter('key1'));
+ self::assertEquals('value2', $givenObject->getParameter('key2'));
+ self::assertEquals([
'key1' => 'value1',
'key2' => 'value2',
], $givenObject->getParameters());
$givenObject->removeParameter('key2');
- $this->assertEquals(['key1' => 'value1'], $givenObject->getParameters());
+ self::assertEquals(['key1' => 'value1'], $givenObject->getParameters());
$givenObject->removeParameters();
- $this->assertEquals([], $givenObject->getParameters());
+ self::assertEquals([], $givenObject->getParameters());
}
}
diff --git a/tests/Highlighter/HighlighterTest.php b/tests/Highlighter/HighlighterTest.php
index bad45f6..0321d5c 100644
--- a/tests/Highlighter/HighlighterTest.php
+++ b/tests/Highlighter/HighlighterTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Highlighter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchNoneMatcher;
-class HighlighterTest extends AbstractJsonSerializeTest
+final class HighlighterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -32,7 +32,7 @@ public function dataTestJsonSerialize(): array
"field1": {}
}
}',
- (new Highlighter(['type' => 'plain']))->setField('field1'),
+ (new Highlighter(options: ['type' => 'plain']))->setField('field1'),
];
//# 2
@@ -46,7 +46,7 @@ public function dataTestJsonSerialize(): array
}
}
}',
- (new Highlighter(['type' => 'plain']))->setField('field1', ['order' => 'score']),
+ (new Highlighter(options: ['type' => 'plain']))->setField('field1', ['order' => 'score']),
];
// #3
@@ -66,7 +66,7 @@ public function dataTestJsonSerialize(): array
}
}
}',
- (new Highlighter([
+ (new Highlighter(options: [
'type' => 'plain',
'highlight_query' => new MatchAllMatcher(),
]))->setField('field1', ['order' => 'score', 'highlight_query' => new MatchNoneMatcher()]),
@@ -75,13 +75,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$highlighter = (new Highlighter([
'type' => 'plain',
'highlight_query' => new MatchAllMatcher(),
]))->setField('field1', ['order' => 'score', 'highlight_query' => new MatchNoneMatcher()]);
- $this->assertInstanceOf(Highlighter::class, $highlighter);
+ self::assertInstanceOf(Highlighter::class, $highlighter);
}
}
diff --git a/tests/Highlighter/RawHighlighterTest.php b/tests/Highlighter/RawHighlighterTest.php
index c116bfe..66ea40d 100644
--- a/tests/Highlighter/RawHighlighterTest.php
+++ b/tests/Highlighter/RawHighlighterTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawHighlighterTest extends RawFragmentTest
+final class RawHighlighterTest extends RawFragmentTest
{
}
diff --git a/tests/Matcher/Compound/BoolMatcherTest.php b/tests/Matcher/Compound/BoolMatcherTest.php
index 4bcaa43..297107e 100644
--- a/tests/Matcher/Compound/BoolMatcherTest.php
+++ b/tests/Matcher/Compound/BoolMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
-class BoolMatcherTest extends AbstractJsonSerializeTest
+final class BoolMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -63,7 +63,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher = (new BoolMatcher())
->setFilters([new TermMatcher('field1', 'value1')])
@@ -76,26 +76,26 @@ public function testMethods()
->addShould(new TermMatcher('field8', 'value8'))
->setMinimumShouldMatch(1);
- $this->assertEquals([
+ self::assertEquals([
new TermMatcher('field1', 'value1'),
new TermMatcher('field2', 'value2'),
], $matcher->getFilters());
- $this->assertEquals([
+ self::assertEquals([
new TermMatcher('field3', 'value3'),
new TermMatcher('field4', 'value4'),
], $matcher->getMusts());
- $this->assertEquals([
+ self::assertEquals([
new TermMatcher('field5', 'value5'),
new TermMatcher('field6', 'value6'),
], $matcher->getMustNots());
- $this->assertEquals([
+ self::assertEquals([
new TermMatcher('field7', 'value7'),
new TermMatcher('field8', 'value8'),
], $matcher->getShoulds());
- $this->assertEquals(1, $matcher->getMinimumShouldMatch());
+ self::assertEquals(1, $matcher->getMinimumShouldMatch());
}
}
diff --git a/tests/Matcher/Compound/BoostingMatcherTest.php b/tests/Matcher/Compound/BoostingMatcherTest.php
index 08a8367..4aa3bce 100644
--- a/tests/Matcher/Compound/BoostingMatcherTest.php
+++ b/tests/Matcher/Compound/BoostingMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\WildcardMatcher;
-class BoostingMatcherTest extends AbstractJsonSerializeTest
+final class BoostingMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -32,13 +32,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new BoostingMatcher(
new WildcardMatcher('field1', 'value1*'),
new TermMatcher('field1', "value1"),
0.5
);
- $this->assertInstanceOf(BoostingMatcher::class, $matcher1);
+ self::assertInstanceOf(BoostingMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Compound/ConstantScoreMatcherTest.php b/tests/Matcher/Compound/ConstantScoreMatcherTest.php
index 8cda531..47e2793 100644
--- a/tests/Matcher/Compound/ConstantScoreMatcherTest.php
+++ b/tests/Matcher/Compound/ConstantScoreMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
-class ConstantScoreMatcherTest extends AbstractJsonSerializeTest
+final class ConstantScoreMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -29,12 +29,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new ConstantScoreMatcher(
new MatchAllMatcher(),
5
);
- $this->assertInstanceOf(ConstantScoreMatcher::class, $matcher1);
+ self::assertInstanceOf(ConstantScoreMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Compound/DisMaxScoreMatcherTest.php b/tests/Matcher/Compound/DisMaxScoreMatcherTest.php
index ad64565..008d68d 100644
--- a/tests/Matcher/Compound/DisMaxScoreMatcherTest.php
+++ b/tests/Matcher/Compound/DisMaxScoreMatcherTest.php
@@ -2,14 +2,14 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermsMatcher;
use InvalidArgumentException;
-class DisMaxScoreMatcherTest extends AbstractJsonSerializeTest
+final class DisMaxScoreMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -41,7 +41,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new DisMaxScoreMatcher(
[
@@ -53,7 +53,7 @@ public function testMethods()
'tie_breaker' => 5
]
);
- $this->assertInstanceOf(DisMaxScoreMatcher::class, $matcher1);
+ self::assertInstanceOf(DisMaxScoreMatcher::class, $matcher1);
$this->expectException(InvalidArgumentException::class);
new DisMaxScoreMatcher([]);
diff --git a/tests/Matcher/Compound/FunctionScoreMatcherTest.php b/tests/Matcher/Compound/FunctionScoreMatcherTest.php
index b782d02..1312888 100644
--- a/tests/Matcher/Compound/FunctionScoreMatcherTest.php
+++ b/tests/Matcher/Compound/FunctionScoreMatcherTest.php
@@ -2,15 +2,15 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
use Gskema\ElasticSearchQueryDSL\ScoreFunction\LinearDecayScoreFunction;
use Gskema\ElasticSearchQueryDSL\ScoreFunction\RandomScoreFunction;
-class FunctionScoreMatcherTest extends AbstractJsonSerializeTest
+final class FunctionScoreMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -33,7 +33,7 @@ public function dataTestJsonSerialize(): array
"query": {
"term": {
"field1": "term1"
- }
+ }
},
"score_mode": "avg",
"functions": [
@@ -66,13 +66,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = (new FunctionScoreMatcher(
new TermMatcher('field1', 'term1'),
['score_mode' => 'avg']
))
->addScoreFunction(new RandomScoreFunction(99), new MatchAllMatcher(), 5);
- $this->assertInstanceOf(FunctionScoreMatcher::class, $matcher1);
+ self::assertInstanceOf(FunctionScoreMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Compound/IndicesMatcherTest.php b/tests/Matcher/Compound/IndicesMatcherTest.php
deleted file mode 100644
index 24ed96c..0000000
--- a/tests/Matcher/Compound/IndicesMatcherTest.php
+++ /dev/null
@@ -1,44 +0,0 @@
-assertInstanceOf(IndicesMatcher::class, $matcher1);
- }
-}
diff --git a/tests/Matcher/Compound/NotMatcherTest.php b/tests/Matcher/Compound/NotMatcherTest.php
index aa675fc..7ab48d8 100644
--- a/tests/Matcher/Compound/NotMatcherTest.php
+++ b/tests/Matcher/Compound/NotMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Compound;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
-class NotMatcherTest extends AbstractJsonSerializeTest
+final class NotMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -27,9 +27,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new NotMatcher(new MatchAllMatcher());
- $this->assertInstanceOf(NotMatcher::class, $matcher1);
+ self::assertInstanceOf(NotMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/CommonTermsMatcherTest.php b/tests/Matcher/FullText/CommonTermsMatcherTest.php
index d8380ed..15d85c2 100644
--- a/tests/Matcher/FullText/CommonTermsMatcherTest.php
+++ b/tests/Matcher/FullText/CommonTermsMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class CommonTermsMatcherTest extends AbstractJsonSerializeTest
+final class CommonTermsMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -27,9 +27,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new CommonTermsMatcher('field1', 'query1', 0.1);
- $this->assertInstanceOf(CommonTermsMatcher::class, $matcher1);
+ self::assertInstanceOf(CommonTermsMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/MatchMatcherTest.php b/tests/Matcher/FullText/MatchMatcherTest.php
index 8d463f6..09a0ba8 100644
--- a/tests/Matcher/FullText/MatchMatcherTest.php
+++ b/tests/Matcher/FullText/MatchMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MatchMatcherTest extends AbstractJsonSerializeTest
+final class MatchMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -26,9 +26,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new MatchMatcher('field1', 'query1');
- $this->assertInstanceOf(MatchMatcher::class, $matcher1);
+ self::assertInstanceOf(MatchMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/MatchPhraseMatcherTest.php b/tests/Matcher/FullText/MatchPhraseMatcherTest.php
index 9abe744..9624ca8 100644
--- a/tests/Matcher/FullText/MatchPhraseMatcherTest.php
+++ b/tests/Matcher/FullText/MatchPhraseMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MatchPhraseMatcherTest extends AbstractJsonSerializeTest
+final class MatchPhraseMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -26,9 +26,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new MatchPhraseMatcher('field1', 'query1');
- $this->assertInstanceOf(MatchPhraseMatcher::class, $matcher1);
+ self::assertInstanceOf(MatchPhraseMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/MatchPhrasePrefixMatcherTest.php b/tests/Matcher/FullText/MatchPhrasePrefixMatcherTest.php
index cef4c91..52020af 100644
--- a/tests/Matcher/FullText/MatchPhrasePrefixMatcherTest.php
+++ b/tests/Matcher/FullText/MatchPhrasePrefixMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MatchPhrasePrefixMatcherTest extends AbstractJsonSerializeTest
+final class MatchPhrasePrefixMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -27,9 +27,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new MatchPhrasePrefixMatcher('field1', 'query1', ['max_expansions' => 10]);
- $this->assertInstanceOf(MatchPhrasePrefixMatcher::class, $matcher1);
+ self::assertInstanceOf(MatchPhrasePrefixMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/MultiMatchMatcherTest.php b/tests/Matcher/FullText/MultiMatchMatcherTest.php
index fe86fdf..6c096a6 100644
--- a/tests/Matcher/FullText/MultiMatchMatcherTest.php
+++ b/tests/Matcher/FullText/MultiMatchMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MultiMatchMatcherTest extends AbstractJsonSerializeTest
+final class MultiMatchMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -26,9 +26,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new MultiMatchMatcher(['field1', 'field2'], 'query1', ['minimum_should_match' => 2]);
- $this->assertInstanceOf(MultiMatchMatcher::class, $matcher1);
+ self::assertInstanceOf(MultiMatchMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/QueryStringMatcherTest.php b/tests/Matcher/FullText/QueryStringMatcherTest.php
index 333f997..810f2c0 100644
--- a/tests/Matcher/FullText/QueryStringMatcherTest.php
+++ b/tests/Matcher/FullText/QueryStringMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class QueryStringMatcherTest extends AbstractJsonSerializeTest
+final class QueryStringMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -25,9 +25,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new QueryStringMatcher('this AND that OR thus', ['default_field' => 'body']);
- $this->assertInstanceOf(QueryStringMatcher::class, $matcher1);
+ self::assertInstanceOf(QueryStringMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/FullText/SimpleQueryStringMatcherTest.php b/tests/Matcher/FullText/SimpleQueryStringMatcherTest.php
index 3aa6064..0e5399e 100644
--- a/tests/Matcher/FullText/SimpleQueryStringMatcherTest.php
+++ b/tests/Matcher/FullText/SimpleQueryStringMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\FullText;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SimpleQueryStringMatcherTest extends AbstractJsonSerializeTest
+final class SimpleQueryStringMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -16,18 +16,18 @@ public function dataTestJsonSerialize(): array
'{
"simple_query_string": {
"query": "this AND that OR thus",
- "all_fields": true
+ "analyze_wildcard": true
}
}',
- new SimpleQueryStringMatcher('this AND that OR thus', ['all_fields' => true]),
+ new SimpleQueryStringMatcher('this AND that OR thus', ['analyze_wildcard' => true]),
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
- $matcher1 = new SimpleQueryStringMatcher('this AND that OR thus', ['all_fields' => true]);
- $this->assertInstanceOf(SimpleQueryStringMatcher::class, $matcher1);
+ $matcher1 = new SimpleQueryStringMatcher('this AND that OR thus', ['analyze_wildcard' => true]);
+ self::assertInstanceOf(SimpleQueryStringMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Geo/GeoBoundingBoxMatcherTest.php b/tests/Matcher/Geo/GeoBoundingBoxMatcherTest.php
index 8d1772b..e537b01 100644
--- a/tests/Matcher/Geo/GeoBoundingBoxMatcherTest.php
+++ b/tests/Matcher/Geo/GeoBoundingBoxMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Geo;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoPoint;
-class GeoBoundingBoxMatcherTest extends AbstractJsonSerializeTest
+final class GeoBoundingBoxMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -54,7 +54,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = GeoBoundingBoxMatcher::fromTopLeft(
'field1',
@@ -62,7 +62,7 @@ public function testMethods()
new GeoPoint(2, 2),
['type' => 'indexed']
);
- $this->assertInstanceOf(GeoBoundingBoxMatcher::class, $matcher1);
+ self::assertInstanceOf(GeoBoundingBoxMatcher::class, $matcher1);
$matcher2 = GeoBoundingBoxMatcher::fromTopRight(
'field1',
@@ -70,6 +70,6 @@ public function testMethods()
new GeoPoint(2, 2),
['type' => 'indexed']
);
- $this->assertInstanceOf(GeoBoundingBoxMatcher::class, $matcher2);
+ self::assertInstanceOf(GeoBoundingBoxMatcher::class, $matcher2);
}
}
diff --git a/tests/Matcher/Geo/GeoDistanceMatcherTest.php b/tests/Matcher/Geo/GeoDistanceMatcherTest.php
index 24aac61..24d9f41 100644
--- a/tests/Matcher/Geo/GeoDistanceMatcherTest.php
+++ b/tests/Matcher/Geo/GeoDistanceMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Geo;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoPoint;
-class GeoDistanceMatcherTest extends AbstractJsonSerializeTest
+final class GeoDistanceMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -32,7 +32,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new GeoDistanceMatcher(
'field1',
@@ -40,6 +40,6 @@ public function testMethods()
'50km',
['validation_method' => 'IGNORE_MALFORMED']
);
- $this->assertInstanceOf(GeoDistanceMatcher::class, $matcher1);
+ self::assertInstanceOf(GeoDistanceMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Geo/GeoDistanceRangeMatcherTest.php b/tests/Matcher/Geo/GeoDistanceRangeMatcherTest.php
deleted file mode 100644
index 9d75568..0000000
--- a/tests/Matcher/Geo/GeoDistanceRangeMatcherTest.php
+++ /dev/null
@@ -1,43 +0,0 @@
- '1km', 'lte' => "10km"]
- ),
- ];
-
- return $dataSets;
- }
-
- public function testMethods()
- {
- $matcher1 = new GeoDistanceRangeMatcher(
- 'field1',
- new GeoPoint(1, 1),
- ['gt' => '1km', 'lte' => "10km"]
- );
- $this->assertInstanceOf(GeoDistanceRangeMatcher::class, $matcher1);
- }
-}
diff --git a/tests/Matcher/Geo/GeoPolygonMatcherTest.php b/tests/Matcher/Geo/GeoPolygonMatcherTest.php
index aae407d..ac2a3e4 100644
--- a/tests/Matcher/Geo/GeoPolygonMatcherTest.php
+++ b/tests/Matcher/Geo/GeoPolygonMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Geo;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoPoint;
use InvalidArgumentException;
-class GeoPolygonMatcherTest extends AbstractJsonSerializeTest
+final class GeoPolygonMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -39,7 +39,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new GeoPolygonMatcher(
'field1',
@@ -49,7 +49,7 @@ public function testMethods()
new GeoPoint(3, 3),
]
);
- $this->assertInstanceOf(GeoPolygonMatcher::class, $matcher1);
+ self::assertInstanceOf(GeoPolygonMatcher::class, $matcher1);
$this->expectException(InvalidArgumentException::class);
new GeoPolygonMatcher(
diff --git a/tests/Matcher/Geo/GeoShapeMatcherTest.php b/tests/Matcher/Geo/GeoShapeMatcherTest.php
index 41043d7..d720907 100644
--- a/tests/Matcher/Geo/GeoShapeMatcherTest.php
+++ b/tests/Matcher/Geo/GeoShapeMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Geo;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoShape\IndexedGeoShape;
use Gskema\ElasticSearchQueryDSL\Model\GeoShape\RawGeoShape;
-class GeoShapeMatcherTest extends AbstractJsonSerializeTest
+final class GeoShapeMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -66,7 +66,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new GeoShapeMatcher(
'field1',
@@ -79,6 +79,6 @@ public function testMethods()
'INTERSECTS',
['ignore_unmapped' => true]
);
- $this->assertInstanceOf(GeoShapeMatcher::class, $matcher1);
+ self::assertInstanceOf(GeoShapeMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Joining/HasChildMatcherTest.php b/tests/Matcher/Joining/HasChildMatcherTest.php
index ef43bdc..02c63b7 100644
--- a/tests/Matcher/Joining/HasChildMatcherTest.php
+++ b/tests/Matcher/Joining/HasChildMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Joining;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
-class HasChildMatcherTest extends AbstractJsonSerializeTest
+final class HasChildMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -43,9 +43,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new HasChildMatcher('childType1', new MatchAllMatcher());
- $this->assertInstanceOf(HasChildMatcher::class, $matcher1);
+ self::assertInstanceOf(HasChildMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Joining/HasInnerHitsTraitTest.php b/tests/Matcher/Joining/HasInnerHitsTraitTest.php
index 6c0c1de..7b37c62 100644
--- a/tests/Matcher/Joining/HasInnerHitsTraitTest.php
+++ b/tests/Matcher/Joining/HasInnerHitsTraitTest.php
@@ -5,17 +5,19 @@
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
use PHPUnit\Framework\TestCase;
-class HasInnerHitsTraitTest extends TestCase
+final class HasInnerHitsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasInnerHitsTrait $object */
- $object = $this->getMockForTrait(HasInnerHitsTrait::class);
+ $object = new class {
+ use HasInnerHitsTrait;
+ };
$object->setInnerHits((new InnerHitsRequest())->setName('name1'));
- $this->assertEquals(true, $object->hasInnerHits());
- $this->assertEquals(
+ self::assertEquals(true, $object->hasInnerHits());
+ self::assertEquals(
(new InnerHitsRequest())->setName('name1'),
$object->getInnerHits()
);
diff --git a/tests/Matcher/Joining/HasParentMatcherTest.php b/tests/Matcher/Joining/HasParentMatcherTest.php
index f0d6ce9..c362417 100644
--- a/tests/Matcher/Joining/HasParentMatcherTest.php
+++ b/tests/Matcher/Joining/HasParentMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Joining;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
-class HasParentMatcherTest extends AbstractJsonSerializeTest
+final class HasParentMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -43,9 +43,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new HasParentMatcher('parentType1', new MatchAllMatcher());
- $this->assertInstanceOf(HasParentMatcher::class, $matcher1);
+ self::assertInstanceOf(HasParentMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Joining/NestedMatcherTest.php b/tests/Matcher/Joining/NestedMatcherTest.php
index 73fa1e1..1a2ff2a 100644
--- a/tests/Matcher/Joining/NestedMatcherTest.php
+++ b/tests/Matcher/Joining/NestedMatcherTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Joining;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
-class NestedMatcherTest extends AbstractJsonSerializeTest
+final class NestedMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -43,9 +43,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new NestedMatcher('path1', new MatchAllMatcher());
- $this->assertInstanceOf(NestedMatcher::class, $matcher1);
+ self::assertInstanceOf(NestedMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Joining/ParentIdMatcherTest.php b/tests/Matcher/Joining/ParentIdMatcherTest.php
index 5e2e731..cb050ee 100644
--- a/tests/Matcher/Joining/ParentIdMatcherTest.php
+++ b/tests/Matcher/Joining/ParentIdMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Joining;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\SearchRequest\InnerHitsRequest;
-class ParentIdMatcherTest extends AbstractJsonSerializeTest
+final class ParentIdMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -42,9 +42,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new ParentIdMatcher('childType1', 'parentId1');
- $this->assertInstanceOf(ParentIdMatcher::class, $matcher1);
+ self::assertInstanceOf(ParentIdMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/MatchAllMatcherTest.php b/tests/Matcher/MatchAllMatcherTest.php
index 63d1f97..97cf3cb 100644
--- a/tests/Matcher/MatchAllMatcherTest.php
+++ b/tests/Matcher/MatchAllMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MatchAllMatcherTest extends AbstractJsonSerializeTest
+final class MatchAllMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Matcher/MatchNoneMatcherTest.php b/tests/Matcher/MatchNoneMatcherTest.php
index 6a74bfd..9a5c114 100644
--- a/tests/Matcher/MatchNoneMatcherTest.php
+++ b/tests/Matcher/MatchNoneMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MatchNoneMatcherTest extends AbstractJsonSerializeTest
+final class MatchNoneMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/Matcher/RawMatcherTest.php b/tests/Matcher/RawMatcherTest.php
index 30a6b3e..67512a5 100644
--- a/tests/Matcher/RawMatcherTest.php
+++ b/tests/Matcher/RawMatcherTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawMatcherTest extends RawFragmentTest
+final class RawMatcherTest extends RawFragmentTest
{
}
diff --git a/tests/Matcher/RawMultiTermMatcherTest.php b/tests/Matcher/RawMultiTermMatcherTest.php
index 4a2bf91..cf2ab1b 100644
--- a/tests/Matcher/RawMultiTermMatcherTest.php
+++ b/tests/Matcher/RawMultiTermMatcherTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawMultiTermMatcherTest extends RawFragmentTest
+final class RawMultiTermMatcherTest extends RawFragmentTest
{
}
diff --git a/tests/Matcher/Span/RawSpanMatcherTest.php b/tests/Matcher/Span/RawSpanMatcherTest.php
index 74ce4c3..5948a02 100644
--- a/tests/Matcher/Span/RawSpanMatcherTest.php
+++ b/tests/Matcher/Span/RawSpanMatcherTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawSpanMatcherTest extends RawFragmentTest
+final class RawSpanMatcherTest extends RawFragmentTest
{
}
diff --git a/tests/Matcher/Span/SpanContainingMatcherTest.php b/tests/Matcher/Span/SpanContainingMatcherTest.php
index 19c50b0..076162c 100644
--- a/tests/Matcher/Span/SpanContainingMatcherTest.php
+++ b/tests/Matcher/Span/SpanContainingMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SpanContainingMatcherTest extends AbstractJsonSerializeTest
+final class SpanContainingMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -28,12 +28,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanContainingMatcher(
new SpanTermMatcher('field1', 'value1'),
new SpanTermMatcher('field2', 'value2')
);
- $this->assertInstanceOf(SpanContainingMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanContainingMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Span/SpanFieldMaskingMatcherTest.php b/tests/Matcher/Span/SpanFieldMaskingMatcherTest.php
index 86ef122..0989e10 100644
--- a/tests/Matcher/Span/SpanFieldMaskingMatcherTest.php
+++ b/tests/Matcher/Span/SpanFieldMaskingMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SpanFieldMaskingMatcherTest extends AbstractJsonSerializeTest
+final class SpanFieldMaskingMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -30,12 +30,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanFieldMaskingMatcher(
'field1',
new SpanTermMatcher('field2', 'value2')
);
- $this->assertInstanceOf(SpanFieldMaskingMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanFieldMaskingMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Span/SpanFirstMatcherTest.php b/tests/Matcher/Span/SpanFirstMatcherTest.php
index 4d680e3..a6b5c30 100644
--- a/tests/Matcher/Span/SpanFirstMatcherTest.php
+++ b/tests/Matcher/Span/SpanFirstMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SpanFirstMatcherTest extends AbstractJsonSerializeTest
+final class SpanFirstMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -28,12 +28,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanFirstMatcher(
new SpanTermMatcher('field1', 'value1'),
3
);
- $this->assertInstanceOf(SpanFirstMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanFirstMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Span/SpanMultiMatcherTest.php b/tests/Matcher/Span/SpanMultiMatcherTest.php
index 318553e..1d41076 100644
--- a/tests/Matcher/Span/SpanMultiMatcherTest.php
+++ b/tests/Matcher/Span/SpanMultiMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\PrefixMatcher;
-class SpanMultiMatcherTest extends AbstractJsonSerializeTest
+final class SpanMultiMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -27,11 +27,11 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanMultiMatcher(
new PrefixMatcher('field1', 'prefix1')
);
- $this->assertInstanceOf(SpanMultiMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanMultiMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Span/SpanNearMatcherTest.php b/tests/Matcher/Span/SpanNearMatcherTest.php
index 84a11cf..54d293a 100644
--- a/tests/Matcher/Span/SpanNearMatcherTest.php
+++ b/tests/Matcher/Span/SpanNearMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use InvalidArgumentException;
-class SpanNearMatcherTest extends AbstractJsonSerializeTest
+final class SpanNearMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -37,7 +37,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanNearMatcher(
[
@@ -47,7 +47,7 @@ public function testMethods()
5,
false
);
- $this->assertInstanceOf(SpanNearMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanNearMatcher::class, $matcher1);
$this->expectException(InvalidArgumentException::class);
new SpanNearMatcher([], 5, false);
diff --git a/tests/Matcher/Span/SpanNotMatcherTest.php b/tests/Matcher/Span/SpanNotMatcherTest.php
index cc8f7c1..54febdc 100644
--- a/tests/Matcher/Span/SpanNotMatcherTest.php
+++ b/tests/Matcher/Span/SpanNotMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SpanNotMatcherTest extends AbstractJsonSerializeTest
+final class SpanNotMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -30,13 +30,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanNotMatcher(
new SpanTermMatcher('field1', 'value1'),
new SpanTermMatcher('field2', 'value2'),
['pre' => 1]
);
- $this->assertInstanceOf(SpanNotMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanNotMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Span/SpanOrMatcherTest.php b/tests/Matcher/Span/SpanOrMatcherTest.php
index 9ea8cee..eb626fb 100644
--- a/tests/Matcher/Span/SpanOrMatcherTest.php
+++ b/tests/Matcher/Span/SpanOrMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use InvalidArgumentException;
-class SpanOrMatcherTest extends AbstractJsonSerializeTest
+final class SpanOrMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -31,13 +31,13 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanOrMatcher([
new SpanTermMatcher('field1', 'value1'),
new SpanTermMatcher('field2', 'value2'),
]);
- $this->assertInstanceOf(SpanOrMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanOrMatcher::class, $matcher1);
$this->expectException(InvalidArgumentException::class);
new SpanOrMatcher([]);
diff --git a/tests/Matcher/Span/SpanTermMatcherTest.php b/tests/Matcher/Span/SpanTermMatcherTest.php
index 0aa3926..568301c 100644
--- a/tests/Matcher/Span/SpanTermMatcherTest.php
+++ b/tests/Matcher/Span/SpanTermMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SpanTermMatcherTest extends AbstractJsonSerializeTest
+final class SpanTermMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -40,9 +40,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanTermMatcher('field1', 'value1');
- $this->assertInstanceOf(SpanTermMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanTermMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Span/SpanWithinMatcherTest.php b/tests/Matcher/Span/SpanWithinMatcherTest.php
index 2efcf87..45ef97c 100644
--- a/tests/Matcher/Span/SpanWithinMatcherTest.php
+++ b/tests/Matcher/Span/SpanWithinMatcherTest.php
@@ -2,18 +2,18 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Span;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SpanWithinMatcherTest extends AbstractJsonSerializeTest
+final class SpanWithinMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
// #0
$dataSets[] = [
// language=JSON
- '{
+ '{
"span_within": {
"little": { "span_term" : { "field1": "value1" } },
"big": { "span_term" : { "field2": "value2" } }
@@ -28,12 +28,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new SpanWithinMatcher(
new SpanTermMatcher('field1', 'value1'),
new SpanTermMatcher('field2', 'value2')
);
- $this->assertInstanceOf(SpanWithinMatcher::class, $matcher1);
+ self::assertInstanceOf(SpanWithinMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Specialized/MoreLikeThisMatcherTest.php b/tests/Matcher/Specialized/MoreLikeThisMatcherTest.php
index 9c9c2bc..fe5d963 100644
--- a/tests/Matcher/Specialized/MoreLikeThisMatcherTest.php
+++ b/tests/Matcher/Specialized/MoreLikeThisMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Specialized;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MoreLikeThisMatcherTest extends AbstractJsonSerializeTest
+final class MoreLikeThisMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -34,7 +34,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new MoreLikeThisMatcher(
['field1', 'field2'],
@@ -44,6 +44,6 @@ public function testMethods()
'max_doc_freq' => 0,
]
);
- $this->assertInstanceOf(MoreLikeThisMatcher::class, $matcher1);
+ self::assertInstanceOf(MoreLikeThisMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Specialized/PercolateMatcherTest.php b/tests/Matcher/Specialized/PercolateMatcherTest.php
index 359fd03..0cf2811 100644
--- a/tests/Matcher/Specialized/PercolateMatcherTest.php
+++ b/tests/Matcher/Specialized/PercolateMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Specialized;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class PercolateMatcherTest extends AbstractJsonSerializeTest
+final class PercolateMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -16,16 +16,14 @@ public function dataTestJsonSerialize(): array
'{
"percolate": {
"field": "queryField1",
- "document_type": "docType1",
"document": {
"body": "body1"
}
}
-
+
}',
PercolateMatcher::fromDocSource(
'queryField1',
- 'docType1',
[
'body' => 'body1'
]
@@ -38,43 +36,61 @@ public function dataTestJsonSerialize(): array
'{
"percolate": {
"field": "queryField1",
- "document_type": "docType1",
"index": "index1",
"type": "type1",
"id": "id1"
}
-
+
}',
PercolateMatcher::fromIndexedDoc(
'queryField1',
- 'docType1',
'index1',
'type1',
'id1'
),
];
+ // #2
+ $dataSets[] = [
+ // language=JSON
+ '{
+ "percolate": {
+ "field": "queryField1",
+ "documents": [
+ { "body": "body1" },
+ { "body": "body2" }
+ ]
+ }
+
+ }',
+ PercolateMatcher::fromDocSources(
+ 'queryField1',
+ [
+ ['body' => 'body1'],
+ ['body' => 'body2'],
+ ]
+ ),
+ ];
+
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = PercolateMatcher::fromDocSource(
'queryField1',
- 'docType1',
[
'body' => 'body1'
]
);
- $this->assertInstanceOf(PercolateMatcher::class, $matcher1);
+ self::assertInstanceOf(PercolateMatcher::class, $matcher1);
$matcher2 = PercolateMatcher::fromIndexedDoc(
'queryField1',
- 'docType1',
'index1',
'type1',
'id1'
);
- $this->assertInstanceOf(PercolateMatcher::class, $matcher2);
+ self::assertInstanceOf(PercolateMatcher::class, $matcher2);
}
}
diff --git a/tests/Matcher/Specialized/ScriptMatcherTest.php b/tests/Matcher/Specialized/ScriptMatcherTest.php
index 7e62e19..8960ad9 100644
--- a/tests/Matcher/Specialized/ScriptMatcherTest.php
+++ b/tests/Matcher/Specialized/ScriptMatcherTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\Specialized;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class ScriptMatcherTest extends AbstractJsonSerializeTest
+final class ScriptMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -34,7 +34,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new ScriptMatcher(
new InlineScript(
@@ -43,6 +43,6 @@ public function testMethods()
'painless'
)
);
- $this->assertInstanceOf(ScriptMatcher::class, $matcher1);
+ self::assertInstanceOf(ScriptMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/Specialized/TemplateMatcherTest.php b/tests/Matcher/Specialized/TemplateMatcherTest.php
deleted file mode 100644
index aefb4c5..0000000
--- a/tests/Matcher/Specialized/TemplateMatcherTest.php
+++ /dev/null
@@ -1,99 +0,0 @@
- 'value1'
- ]
- ),
- ];
-
- // #1
- $dataSets[] = [
- // language=JSON
- '{
- "template": {
- "file": "file1",
- "params": {
- "param1": "value1"
- }
- }
- }',
- TemplateMatcher::fromFile(
- 'file1',
- [
- 'param1' => 'value1'
- ]
- ),
- ];
-
- // #2
- $dataSets[] = [
- // language=JSON
- '{
- "template": {
- "id": "templateId1",
- "params": {
- "param1": "value1"
- }
- }
- }',
- TemplateMatcher::fromId(
- 'templateId1',
- [
- 'param1' => 'value1'
- ]
- ),
- ];
-
- return $dataSets;
- }
-
- public function testMethods()
- {
- $matcher1 = TemplateMatcher::fromId(
- 'templateId1',
- [
- 'param1' => 'value1'
- ]
- );
- $this->assertInstanceOf(TemplateMatcher::class, $matcher1);
-
- $matcher2 = TemplateMatcher::fromFile(
- 'file1',
- [
- 'param1' => 'value1'
- ]
- );
- $this->assertInstanceOf(TemplateMatcher::class, $matcher2);
-
- $matcher3 = TemplateMatcher::fromSource(
- 'source1',
- [
- 'param1' => 'value1'
- ]
- );
- $this->assertInstanceOf(TemplateMatcher::class, $matcher3);
- }
-}
diff --git a/tests/Matcher/Specialized/WrapperMatcherTest.php b/tests/Matcher/Specialized/WrapperMatcherTest.php
new file mode 100644
index 0000000..4095669
--- /dev/null
+++ b/tests/Matcher/Specialized/WrapperMatcherTest.php
@@ -0,0 +1,32 @@
+assertInstanceOf(ExistsMatcher::class, $matcher1);
+ self::assertInstanceOf(ExistsMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/FuzzyMatcherTest.php b/tests/Matcher/TermLevel/FuzzyMatcherTest.php
index 4b7de40..771b079 100644
--- a/tests/Matcher/TermLevel/FuzzyMatcherTest.php
+++ b/tests/Matcher/TermLevel/FuzzyMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class FuzzyMatcherTest extends AbstractJsonSerializeTest
+final class FuzzyMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -40,9 +40,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new FuzzyMatcher('field1', 'value1');
- $this->assertInstanceOf(FuzzyMatcher::class, $matcher1);
+ self::assertInstanceOf(FuzzyMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/IdsMatcherTest.php b/tests/Matcher/TermLevel/IdsMatcherTest.php
index e28684a..28f6027 100644
--- a/tests/Matcher/TermLevel/IdsMatcherTest.php
+++ b/tests/Matcher/TermLevel/IdsMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class IdsMatcherTest extends AbstractJsonSerializeTest
+final class IdsMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,9 +36,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new IdsMatcher(['id1', 'id2'], 'type1');
- $this->assertInstanceOf(IdsMatcher::class, $matcher1);
+ self::assertInstanceOf(IdsMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/LookupTermsMatcherTest.php b/tests/Matcher/TermLevel/LookupTermsMatcherTest.php
index be6f03d..88d3c45 100644
--- a/tests/Matcher/TermLevel/LookupTermsMatcherTest.php
+++ b/tests/Matcher/TermLevel/LookupTermsMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class LookupTermsMatcherTest extends AbstractJsonSerializeTest
+final class LookupTermsMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -59,7 +59,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new LookupTermsMatcher(
'field1',
@@ -68,6 +68,6 @@ public function testMethods()
'id1',
'path1'
);
- $this->assertInstanceOf(LookupTermsMatcher::class, $matcher1);
+ self::assertInstanceOf(LookupTermsMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/MissingMatcherTest.php b/tests/Matcher/TermLevel/MissingMatcherTest.php
index 708dd5a..68400f2 100644
--- a/tests/Matcher/TermLevel/MissingMatcherTest.php
+++ b/tests/Matcher/TermLevel/MissingMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class MissingMatcherTest extends AbstractJsonSerializeTest
+final class MissingMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -28,9 +28,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new MissingMatcher('field1');
- $this->assertInstanceOf(MissingMatcher::class, $matcher1);
+ self::assertInstanceOf(MissingMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/PrefixMatcherTest.php b/tests/Matcher/TermLevel/PrefixMatcherTest.php
index 29ac42c..8c19d10 100644
--- a/tests/Matcher/TermLevel/PrefixMatcherTest.php
+++ b/tests/Matcher/TermLevel/PrefixMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class PrefixMatcherTest extends AbstractJsonSerializeTest
+final class PrefixMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -38,9 +38,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new PrefixMatcher('field1', 'prefix1');
- $this->assertInstanceOf(PrefixMatcher::class, $matcher1);
+ self::assertInstanceOf(PrefixMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/RangeMatcherTest.php b/tests/Matcher/TermLevel/RangeMatcherTest.php
index 58bea02..cdeb7a2 100644
--- a/tests/Matcher/TermLevel/RangeMatcherTest.php
+++ b/tests/Matcher/TermLevel/RangeMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class RangeMatcherTest extends AbstractJsonSerializeTest
+final class RangeMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -33,7 +33,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new RangeMatcher(
'field1',
@@ -42,6 +42,6 @@ public function testMethods()
'lte' => 10
]
);
- $this->assertInstanceOf(RangeMatcher::class, $matcher1);
+ self::assertInstanceOf(RangeMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/RegexMatcherTest.php b/tests/Matcher/TermLevel/RegexpMatcherTest.php
similarity index 55%
rename from tests/Matcher/TermLevel/RegexMatcherTest.php
rename to tests/Matcher/TermLevel/RegexpMatcherTest.php
index a8c6716..eb53267 100644
--- a/tests/Matcher/TermLevel/RegexMatcherTest.php
+++ b/tests/Matcher/TermLevel/RegexpMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class RegexMatcherTest extends AbstractJsonSerializeTest
+final class RegexpMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -21,7 +21,7 @@ public function dataTestJsonSerialize(): array
}
}
}',
- new RegexMatcher('field1', 'regexp1', ['flags' => 'COMPLEMENT']),
+ new RegexpMatcher('field1', 'regexp1', ['flags' => 'COMPLEMENT']),
];
// #1
@@ -32,15 +32,15 @@ public function dataTestJsonSerialize(): array
"field1": "regexp1"
}
}',
- new RegexMatcher('field1', 'regexp1'),
+ new RegexpMatcher('field1', 'regexp1'),
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
- $matcher1 = new RegexMatcher('field1', 'regexp1', ['flags' => 'COMPLEMENT']);
- $this->assertInstanceOf(RegexMatcher::class, $matcher1);
+ $matcher1 = new RegexpMatcher('field1', 'regexp1', ['flags' => 'COMPLEMENT']);
+ self::assertInstanceOf(RegexpMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/TermMatcherTest.php b/tests/Matcher/TermLevel/TermMatcherTest.php
index a6ebf11..09d43a1 100644
--- a/tests/Matcher/TermLevel/TermMatcherTest.php
+++ b/tests/Matcher/TermLevel/TermMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class TermMatcherTest extends AbstractJsonSerializeTest
+final class TermMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -38,9 +38,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new TermMatcher('field1', 'value1');
- $this->assertInstanceOf(TermMatcher::class, $matcher1);
+ self::assertInstanceOf(TermMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/TermsMatcherTest.php b/tests/Matcher/TermLevel/TermsMatcherTest.php
index f698a81..6074944 100644
--- a/tests/Matcher/TermLevel/TermsMatcherTest.php
+++ b/tests/Matcher/TermLevel/TermsMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class TermsMatcherTest extends AbstractJsonSerializeTest
+final class TermsMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -24,9 +24,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new TermsMatcher('field1', ['value1', 'value2']);
- $this->assertInstanceOf(TermsMatcher::class, $matcher1);
+ self::assertInstanceOf(TermsMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/TermsSetMatcherTest.php b/tests/Matcher/TermLevel/TermsSetMatcherTest.php
new file mode 100644
index 0000000..6074fa6
--- /dev/null
+++ b/tests/Matcher/TermLevel/TermsSetMatcherTest.php
@@ -0,0 +1,50 @@
+assertInstanceOf(TypeMatcher::class, $matcher1);
+ self::assertInstanceOf(TypeMatcher::class, $matcher1);
}
}
diff --git a/tests/Matcher/TermLevel/WildcardMatcherTest.php b/tests/Matcher/TermLevel/WildcardMatcherTest.php
index 02aab51..75e0ea5 100644
--- a/tests/Matcher/TermLevel/WildcardMatcherTest.php
+++ b/tests/Matcher/TermLevel/WildcardMatcherTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Matcher\TermLevel;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class WildcardMatcherTest extends AbstractJsonSerializeTest
+final class WildcardMatcherTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -38,9 +38,9 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$matcher1 = new WildcardMatcher('field1', 'value1*');
- $this->assertInstanceOf(WildcardMatcher::class, $matcher1);
+ self::assertInstanceOf(WildcardMatcher::class, $matcher1);
}
}
diff --git a/tests/Model/GeoHashTest.php b/tests/Model/GeoHashTest.php
index c59c1a8..b0369f6 100644
--- a/tests/Model/GeoHashTest.php
+++ b/tests/Model/GeoHashTest.php
@@ -4,15 +4,15 @@
use PHPUnit\Framework\TestCase;
-class GeoHashTest extends TestCase
+final class GeoHashTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
$geoHash = new GeoHash('abc123');
- $this->assertEquals('abc123', $geoHash->getValue());
- $this->assertEquals('abc123', $geoHash->__toString());
- $this->assertEquals('abc123', (string)$geoHash);
- $this->assertEquals('abc123', $geoHash->jsonSerialize());
+ self::assertEquals('abc123', $geoHash->getValue());
+ self::assertEquals('abc123', $geoHash->__toString());
+ self::assertEquals('abc123', (string)$geoHash);
+ self::assertEquals('abc123', $geoHash->jsonSerialize());
}
}
diff --git a/tests/Model/GeoPointTest.php b/tests/Model/GeoPointTest.php
index 99b52b6..5fe1331 100644
--- a/tests/Model/GeoPointTest.php
+++ b/tests/Model/GeoPointTest.php
@@ -4,14 +4,14 @@
use PHPUnit\Framework\TestCase;
-class GeoPointTest extends TestCase
+final class GeoPointTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
$geoPoint = new GeoPoint(1, 2);
- $this->assertEquals(1, $geoPoint->getLat());
- $this->assertEquals(2, $geoPoint->getLon());
- $this->assertEquals(['lat' => 1, 'lon' => 2], $geoPoint->jsonSerialize());
+ self::assertEquals(1, $geoPoint->getLat());
+ self::assertEquals(2, $geoPoint->getLon());
+ self::assertEquals(['lat' => 1, 'lon' => 2], $geoPoint->jsonSerialize());
}
}
diff --git a/tests/Model/GeoShape/IndexedGeoShapeTest.php b/tests/Model/GeoShape/IndexedGeoShapeTest.php
index 0958ce5..535e4e2 100644
--- a/tests/Model/GeoShape/IndexedGeoShapeTest.php
+++ b/tests/Model/GeoShape/IndexedGeoShapeTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Model\GeoShape;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class IndexedGeoShapeTest extends AbstractJsonSerializeTest
+final class IndexedGeoShapeTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -25,10 +25,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$shape = new IndexedGeoShape('index1', 'type1', 'id1', 'path1');
- $this->assertInstanceOf(IndexedGeoShape::class, $shape);
+ self::assertInstanceOf(IndexedGeoShape::class, $shape);
}
}
diff --git a/tests/Model/GeoShape/RawGeoShapeTest.php b/tests/Model/GeoShape/RawGeoShapeTest.php
index ac40a8c..95b4d35 100644
--- a/tests/Model/GeoShape/RawGeoShapeTest.php
+++ b/tests/Model/GeoShape/RawGeoShapeTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawGeoShapeTest extends RawFragmentTest
+final class RawGeoShapeTest extends RawFragmentTest
{
}
diff --git a/tests/Model/Script/FileScriptTest.php b/tests/Model/Script/FileScriptTest.php
index 7cdbd63..11503e4 100644
--- a/tests/Model/Script/FileScriptTest.php
+++ b/tests/Model/Script/FileScriptTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Model\Script;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class FileScriptTest extends AbstractJsonSerializeTest
+final class FileScriptTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -51,12 +51,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$script = new FileScript('file1', [
'param1' => 'value1',
], 'painless');
- $this->assertInstanceOf(FileScript::class, $script);
+ self::assertInstanceOf(FileScript::class, $script);
}
}
diff --git a/tests/Model/Script/IndexedScriptTest.php b/tests/Model/Script/IndexedScriptTest.php
index 5576c2d..0ed39d5 100644
--- a/tests/Model/Script/IndexedScriptTest.php
+++ b/tests/Model/Script/IndexedScriptTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Model\Script;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class IndexedScriptTest extends AbstractJsonSerializeTest
+final class IndexedScriptTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -50,12 +50,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$script = new IndexedScript('id1', [
'param1' => 'value1',
]);
- $this->assertInstanceOf(IndexedScript::class, $script);
+ self::assertInstanceOf(IndexedScript::class, $script);
}
}
diff --git a/tests/Model/Script/InlineScriptTest.php b/tests/Model/Script/InlineScriptTest.php
index decb0d9..0f5ae69 100644
--- a/tests/Model/Script/InlineScriptTest.php
+++ b/tests/Model/Script/InlineScriptTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Model\Script;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class InlineScriptTest extends AbstractJsonSerializeTest
+final class InlineScriptTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -49,12 +49,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$script = new InlineScript('source1', [
'param1' => 'value1',
], 'painless');
- $this->assertInstanceOf(InlineScript::class, $script);
+ self::assertInstanceOf(InlineScript::class, $script);
}
}
diff --git a/tests/Model/Script/RawScriptTest.php b/tests/Model/Script/RawScriptTest.php
index 34dda43..4a5d59a 100644
--- a/tests/Model/Script/RawScriptTest.php
+++ b/tests/Model/Script/RawScriptTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawScriptTest extends RawFragmentTest
+final class RawScriptTest extends RawFragmentTest
{
}
diff --git a/tests/RawFragmentTest.php b/tests/RawFragmentTest.php
index 6f8af42..a71bd51 100644
--- a/tests/RawFragmentTest.php
+++ b/tests/RawFragmentTest.php
@@ -2,6 +2,6 @@
namespace Gskema\ElasticSearchQueryDSL;
-class RawFragmentTest extends AbstractRawFragmentTest
+class RawFragmentTest extends AbstractRawFragmentTestCase
{
}
diff --git a/tests/Rescorer/QueryRescorerTest.php b/tests/Rescorer/QueryRescorerTest.php
index 9c651df..b320fd3 100644
--- a/tests/Rescorer/QueryRescorerTest.php
+++ b/tests/Rescorer/QueryRescorerTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Rescorer;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\TermLevel\TermMatcher;
-class QueryRescorerTest extends AbstractJsonSerializeTest
+final class QueryRescorerTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -36,7 +36,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$rescorer = (new QueryRescorer(new TermMatcher('field1', 'value1')))
->setQueryWeight(1.0)
@@ -44,10 +44,10 @@ public function testMethods()
->setScoreMode('avg')
->setWindowSize(10);
- $this->assertEquals(new TermMatcher('field1', 'value1'), $rescorer->getQuery());
- $this->assertEquals(1.0, $rescorer->getQueryWeight());
- $this->assertEquals(2.0, $rescorer->getRescoreQueryWeight());
- $this->assertEquals('avg', $rescorer->getScoreMode());
- $this->assertEquals(10, $rescorer->getWindowSize());
+ self::assertEquals(new TermMatcher('field1', 'value1'), $rescorer->getQuery());
+ self::assertEquals(1.0, $rescorer->getQueryWeight());
+ self::assertEquals(2.0, $rescorer->getRescoreQueryWeight());
+ self::assertEquals('avg', $rescorer->getScoreMode());
+ self::assertEquals(10, $rescorer->getWindowSize());
}
}
diff --git a/tests/Rescorer/RawRescorerTest.php b/tests/Rescorer/RawRescorerTest.php
index 4ad9a69..94ac2af 100644
--- a/tests/Rescorer/RawRescorerTest.php
+++ b/tests/Rescorer/RawRescorerTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawRescorerTest extends RawFragmentTest
+final class RawRescorerTest extends RawFragmentTest
{
}
diff --git a/tests/ScoreFunction/ExpDecayScoreFunctionTest.php b/tests/ScoreFunction/ExpDecayScoreFunctionTest.php
index c81635d..8c2b00d 100644
--- a/tests/ScoreFunction/ExpDecayScoreFunctionTest.php
+++ b/tests/ScoreFunction/ExpDecayScoreFunctionTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class ExpDecayScoreFunctionTest extends AbstractJsonSerializeTest
+final class ExpDecayScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -23,22 +23,30 @@ public function dataTestJsonSerialize(): array
"multi_value_mode": "mvm1"
}
}',
- (new ExpDecayScoreFunction('field1', 'origin1', 'scale1'))
- ->setOption('offset', 'offset1')
- ->setOption('decay', 'decay1')
- ->setOption('multi_value_mode', 'mvm1'),
+ new ExpDecayScoreFunction(
+ 'field1',
+ 'origin1',
+ 'scale1',
+ 'offset1',
+ 'decay1',
+ 'mvm1'
+ ),
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
- $function = (new ExpDecayScoreFunction('field1', 'origin1', 'scale1'))
- ->setOption('offset', 'offset1')
- ->setOption('decay', 'decay1')
- ->setOption('multi_value_mode', 'mvm1');
+ $function = new ExpDecayScoreFunction(
+ 'field1',
+ 'origin1',
+ 'scale1',
+ 'offset1',
+ 'decay1',
+ 'mvm1'
+ );
- $this->assertInstanceOf(ExpDecayScoreFunction::class, $function);
+ self::assertInstanceOf(ExpDecayScoreFunction::class, $function);
}
}
diff --git a/tests/ScoreFunction/FieldValueFactorScoreFunctionTest.php b/tests/ScoreFunction/FieldValueFactorScoreFunctionTest.php
index f4721b4..331417c 100644
--- a/tests/ScoreFunction/FieldValueFactorScoreFunctionTest.php
+++ b/tests/ScoreFunction/FieldValueFactorScoreFunctionTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class FieldValueFactorScoreFunctionTest extends AbstractJsonSerializeTest
+final class FieldValueFactorScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -18,7 +18,7 @@ public function dataTestJsonSerialize(): array
"field" : "field1"
}
}',
- (new FieldValueFactorScoreFunction('field1')),
+ new FieldValueFactorScoreFunction('field1'),
];
// #1
@@ -30,16 +30,16 @@ public function dataTestJsonSerialize(): array
"factor": 1
}
}',
- (new FieldValueFactorScoreFunction('field1'))->setOption('factor', 1),
+ new FieldValueFactorScoreFunction('field1', 1)
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
- $function = (new FieldValueFactorScoreFunction('field1'))->setOption('factor', 1);
+ $function = new FieldValueFactorScoreFunction('field1', 1);
- $this->assertInstanceOf(FieldValueFactorScoreFunction::class, $function);
+ self::assertInstanceOf(FieldValueFactorScoreFunction::class, $function);
}
}
diff --git a/tests/ScoreFunction/GaussDecayScoreFunctionTest.php b/tests/ScoreFunction/GaussDecayScoreFunctionTest.php
index a722a32..e203f7d 100644
--- a/tests/ScoreFunction/GaussDecayScoreFunctionTest.php
+++ b/tests/ScoreFunction/GaussDecayScoreFunctionTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class GaussDecayScoreFunctionTest extends AbstractJsonSerializeTest
+final class GaussDecayScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -23,23 +23,31 @@ public function dataTestJsonSerialize(): array
"multi_value_mode": "mvm1"
}
}',
- (new GaussDecayScoreFunction('field1', 'origin1', 'scale1'))
- ->setOption('offset', 'offset1')
- ->setOption('decay', 'decay1')
- ->setOption('multi_value_mode', 'mvm1'),
+ new GaussDecayScoreFunction(
+ 'field1',
+ 'origin1',
+ 'scale1',
+ 'offset1',
+ 'decay1',
+ 'mvm1'
+ ),
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
- $function = (new GaussDecayScoreFunction('field1', 'origin1', 'scale1'))
- ->setOption('offset', 'offset1')
- ->setOption('decay', 'decay1')
- ->setOption('multi_value_mode', 'mvm1');
-
- $this->assertInstanceOf(GaussDecayScoreFunction::class, $function);
+ $function = new GaussDecayScoreFunction(
+ 'field1',
+ 'origin1',
+ 'scale1',
+ 'offset1',
+ 'decay1',
+ 'mvm1'
+ );
+
+ self::assertInstanceOf(GaussDecayScoreFunction::class, $function);
}
}
diff --git a/tests/ScoreFunction/LinearDecayScoreFunctionTest.php b/tests/ScoreFunction/LinearDecayScoreFunctionTest.php
index e8cf87b..1950077 100644
--- a/tests/ScoreFunction/LinearDecayScoreFunctionTest.php
+++ b/tests/ScoreFunction/LinearDecayScoreFunctionTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class LinearDecayScoreFunctionTest extends AbstractJsonSerializeTest
+final class LinearDecayScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -23,22 +23,30 @@ public function dataTestJsonSerialize(): array
"multi_value_mode": "mvm1"
}
}',
- (new LinearDecayScoreFunction('field1', 'origin1', 'scale1'))
- ->setOption('offset', 'offset1')
- ->setOption('decay', 'decay1')
- ->setOption('multi_value_mode', 'mvm1'),
+ new LinearDecayScoreFunction(
+ 'field1',
+ 'origin1',
+ 'scale1',
+ 'offset1',
+ 'decay1',
+ 'mvm1'
+ ),
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
- $function = (new LinearDecayScoreFunction('field1', 'origin1', 'scale1'))
- ->setOption('offset', 'offset1')
- ->setOption('decay', 'decay1')
- ->setOption('multi_value_mode', 'mvm1');
+ $function = new LinearDecayScoreFunction(
+ 'field1',
+ 'origin1',
+ 'scale1',
+ 'offset1',
+ 'decay1',
+ 'mvm1'
+ );
- $this->assertInstanceOf(LinearDecayScoreFunction::class, $function);
+ self::assertInstanceOf(LinearDecayScoreFunction::class, $function);
}
}
diff --git a/tests/ScoreFunction/RandomScoreFunctionTest.php b/tests/ScoreFunction/RandomScoreFunctionTest.php
index 75b65aa..36fd579 100644
--- a/tests/ScoreFunction/RandomScoreFunctionTest.php
+++ b/tests/ScoreFunction/RandomScoreFunctionTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class RandomScoreFunctionTest extends AbstractJsonSerializeTest
+final class RandomScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -33,10 +33,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$function = (new RandomScoreFunction(1));
- $this->assertInstanceOf(RandomScoreFunction::class, $function);
+ self::assertInstanceOf(RandomScoreFunction::class, $function);
}
}
diff --git a/tests/ScoreFunction/RawScoreFunctionTest.php b/tests/ScoreFunction/RawScoreFunctionTest.php
index 85bf288..8118371 100644
--- a/tests/ScoreFunction/RawScoreFunctionTest.php
+++ b/tests/ScoreFunction/RawScoreFunctionTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawScoreFunctionTest extends RawFragmentTest
+final class RawScoreFunctionTest extends RawFragmentTest
{
}
diff --git a/tests/ScoreFunction/ScriptScoreFunctionTest.php b/tests/ScoreFunction/ScriptScoreFunctionTest.php
index c0d3012..08235f0 100644
--- a/tests/ScoreFunction/ScriptScoreFunctionTest.php
+++ b/tests/ScoreFunction/ScriptScoreFunctionTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class ScriptScoreFunctionTest extends AbstractJsonSerializeTest
+final class ScriptScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -26,10 +26,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$function = (new ScriptScoreFunction(new InlineScript('script1')))->setOption('boost_mode', 'replace');
- $this->assertInstanceOf(ScriptScoreFunction::class, $function);
+ self::assertInstanceOf(ScriptScoreFunction::class, $function);
}
}
diff --git a/tests/ScoreFunction/WeightScoreFunctionTest.php b/tests/ScoreFunction/WeightScoreFunctionTest.php
index e078ff3..49fe075 100644
--- a/tests/ScoreFunction/WeightScoreFunctionTest.php
+++ b/tests/ScoreFunction/WeightScoreFunctionTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\ScoreFunction;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class WeightScoreFunctionTest extends AbstractJsonSerializeTest
+final class WeightScoreFunctionTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -22,10 +22,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$function = (new WeightScoreFunction(5));
- $this->assertInstanceOf(WeightScoreFunction::class, $function);
+ self::assertInstanceOf(WeightScoreFunction::class, $function);
}
}
diff --git a/tests/SearchRequest/HasDocValueFieldsTraitTest.php b/tests/SearchRequest/HasDocValueFieldsTraitTest.php
index 98e8b43..43e94dd 100644
--- a/tests/SearchRequest/HasDocValueFieldsTraitTest.php
+++ b/tests/SearchRequest/HasDocValueFieldsTraitTest.php
@@ -4,15 +4,17 @@
use PHPUnit\Framework\TestCase;
-class HasDocValueFieldsTraitTest extends TestCase
+final class HasDocValueFieldsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasDocValueFieldsTrait $object */
- $object = $this->getMockBuilder(HasDocValueFieldsTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasDocValueFieldsTrait;
+ };
$object->setDocValueFields(['field1', 'field2']);
- $this->assertEquals(['field1', 'field2'], $object->getDocValueFields());
+ self::assertEquals(['field1', 'field2'], $object->getDocValueFields());
}
}
diff --git a/tests/SearchRequest/HasFieldCollapserTraitTest.php b/tests/SearchRequest/HasFieldCollapserTraitTest.php
index 2e92b67..fb5275d 100644
--- a/tests/SearchRequest/HasFieldCollapserTraitTest.php
+++ b/tests/SearchRequest/HasFieldCollapserTraitTest.php
@@ -5,15 +5,17 @@
use Gskema\ElasticSearchQueryDSL\FieldCollapser\FieldCollapser;
use PHPUnit\Framework\TestCase;
-class HasFieldCollapserTraitTest extends TestCase
+final class HasFieldCollapserTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasFieldCollapserTrait $object */
- $object = $this->getMockBuilder(HasFieldCollapserTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasFieldCollapserTrait;
+ };
$object->setFieldCollapser(new FieldCollapser('field1'));
- $this->assertEquals(new FieldCollapser('field1'), $object->getFieldCollapser());
+ self::assertEquals(new FieldCollapser('field1'), $object->getFieldCollapser());
}
}
diff --git a/tests/SearchRequest/HasFromTraitTest.php b/tests/SearchRequest/HasFromTraitTest.php
index 18e5875..5153a77 100644
--- a/tests/SearchRequest/HasFromTraitTest.php
+++ b/tests/SearchRequest/HasFromTraitTest.php
@@ -4,15 +4,17 @@
use PHPUnit\Framework\TestCase;
-class HasFromTraitTest extends TestCase
+final class HasFromTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasFromTrait $object */
- $object = $this->getMockBuilder(HasFromTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasFromTrait;
+ };
$object->setFrom(10);
- $this->assertEquals(10, $object->getFrom());
+ self::assertEquals(10, $object->getFrom());
}
}
diff --git a/tests/SearchRequest/HasHighlighterTraitTest.php b/tests/SearchRequest/HasHighlighterTraitTest.php
index 20ea7da..9861b3a 100644
--- a/tests/SearchRequest/HasHighlighterTraitTest.php
+++ b/tests/SearchRequest/HasHighlighterTraitTest.php
@@ -5,15 +5,17 @@
use Gskema\ElasticSearchQueryDSL\Highlighter\Highlighter;
use PHPUnit\Framework\TestCase;
-class HasHighlighterTraitTest extends TestCase
+final class HasHighlighterTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasHighlighterTrait $object */
- $object = $this->getMockBuilder(HasHighlighterTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasHighlighterTrait;
+ };
- $object->setHighlighter(new Highlighter(['opt1' => 'val1']));
+ $object->setHighlighter(new Highlighter(options: ['opt1' => 'val1']));
- $this->assertEquals(new Highlighter(['opt1' => 'val1']), $object->getHighlighter());
+ self::assertEquals(new Highlighter(options: ['opt1' => 'val1']), $object->getHighlighter());
}
}
diff --git a/tests/SearchRequest/HasPostFilterTraitTest.php b/tests/SearchRequest/HasPostFilterTraitTest.php
index 4a33021..3421420 100644
--- a/tests/SearchRequest/HasPostFilterTraitTest.php
+++ b/tests/SearchRequest/HasPostFilterTraitTest.php
@@ -5,15 +5,17 @@
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use PHPUnit\Framework\TestCase;
-class HasPostFilterTraitTest extends TestCase
+final class HasPostFilterTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasPostFilterTrait $object */
- $object = $this->getMockBuilder(HasPostFilterTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasPostFilterTrait;
+ };
$object->setPostFilter(new MatchAllMatcher());
- $this->assertEquals(new MatchAllMatcher(), $object->getPostFilter());
+ self::assertEquals(new MatchAllMatcher(), $object->getPostFilter());
}
}
diff --git a/tests/SearchRequest/HasQueryTraitTest.php b/tests/SearchRequest/HasQueryTraitTest.php
index 788305b..4924ba1 100644
--- a/tests/SearchRequest/HasQueryTraitTest.php
+++ b/tests/SearchRequest/HasQueryTraitTest.php
@@ -5,15 +5,17 @@
use Gskema\ElasticSearchQueryDSL\Matcher\MatchNoneMatcher;
use PHPUnit\Framework\TestCase;
-class HasQueryTraitTest extends TestCase
+final class HasQueryTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasQueryTrait $object */
- $object = $this->getMockBuilder(HasQueryTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasQueryTrait;
+ };
$object->setQuery(new MatchNoneMatcher());
- $this->assertEquals(new MatchNoneMatcher(), $object->getQuery());
+ self::assertEquals(new MatchNoneMatcher(), $object->getQuery());
}
}
diff --git a/tests/SearchRequest/HasRescorersTraitTest.php b/tests/SearchRequest/HasRescorersTraitTest.php
index 10353cf..886a297 100644
--- a/tests/SearchRequest/HasRescorersTraitTest.php
+++ b/tests/SearchRequest/HasRescorersTraitTest.php
@@ -7,19 +7,21 @@
use Gskema\ElasticSearchQueryDSL\Rescorer\QueryRescorer;
use PHPUnit\Framework\TestCase;
-class HasRescorersTraitTest extends TestCase
+final class HasRescorersTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasRescorersTrait $object */
- $object = $this->getMockBuilder(HasRescorersTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasRescorersTrait;
+ };
$object->setRescorers([
new QueryRescorer(new MatchAllMatcher())
]);
$object->addRescorer(new QueryRescorer(new MatchNoneMatcher()));
- $this->assertEquals([
+ self::assertEquals([
new QueryRescorer(new MatchAllMatcher()),
new QueryRescorer(new MatchNoneMatcher()),
diff --git a/tests/SearchRequest/HasScriptFieldsTraitTest.php b/tests/SearchRequest/HasScriptFieldsTraitTest.php
index 18abdc0..09e4dbf 100644
--- a/tests/SearchRequest/HasScriptFieldsTraitTest.php
+++ b/tests/SearchRequest/HasScriptFieldsTraitTest.php
@@ -5,12 +5,14 @@
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use PHPUnit\Framework\TestCase;
-class HasScriptFieldsTraitTest extends TestCase
+final class HasScriptFieldsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasScriptFieldsTrait $object */
- $object = $this->getMockBuilder(HasScriptFieldsTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasScriptFieldsTrait;
+ };
$object->setScriptFields([
'field1' => new InlineScript('source1'),
@@ -19,11 +21,11 @@ public function testMethods()
$object->setScriptField('field3', new InlineScript('source3'));
$object->removeScriptField('field1');
- $this->assertEquals([
+ self::assertEquals([
'field2' => new InlineScript('source2'),
'field3' => new InlineScript('source3'),
], $object->getScriptFields());
- $this->assertEquals(new InlineScript('source3'), $object->getScriptField('field3'));
+ self::assertEquals(new InlineScript('source3'), $object->getScriptField('field3'));
}
}
diff --git a/tests/SearchRequest/HasSizeTraitTest.php b/tests/SearchRequest/HasSizeTraitTest.php
index 3ff1206..d244867 100644
--- a/tests/SearchRequest/HasSizeTraitTest.php
+++ b/tests/SearchRequest/HasSizeTraitTest.php
@@ -4,15 +4,17 @@
use PHPUnit\Framework\TestCase;
-class HasSizeTraitTest extends TestCase
+final class HasSizeTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasSizeTrait $object */
- $object = $this->getMockBuilder(HasSizeTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasSizeTrait;
+ };
$object->setSize(7);
- $this->assertEquals(7, $object->getSize());
+ self::assertEquals(7, $object->getSize());
}
}
diff --git a/tests/SearchRequest/HasSortersTraitTest.php b/tests/SearchRequest/HasSortersTraitTest.php
index adb8cdd..81007b5 100644
--- a/tests/SearchRequest/HasSortersTraitTest.php
+++ b/tests/SearchRequest/HasSortersTraitTest.php
@@ -6,19 +6,21 @@
use Gskema\ElasticSearchQueryDSL\Sorter\RawSorter;
use PHPUnit\Framework\TestCase;
-class HasSortersTraitTest extends TestCase
+final class HasSortersTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasSortersTrait $object */
- $object = $this->getMockBuilder(HasSortersTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasSortersTrait;
+ };
$object->setSorters([
new FieldSorter('field1')
]);
$object->addSorter(new RawSorter('field2'));
- $this->assertEquals([
+ self::assertEquals([
new FieldSorter('field1'),
new RawSorter('field2'),
], $object->getSorters());
diff --git a/tests/SearchRequest/HasSourceFieldsTraitTest.php b/tests/SearchRequest/HasSourceFieldsTraitTest.php
index 4f27826..53ecb4c 100644
--- a/tests/SearchRequest/HasSourceFieldsTraitTest.php
+++ b/tests/SearchRequest/HasSourceFieldsTraitTest.php
@@ -5,15 +5,17 @@
use Gskema\ElasticSearchQueryDSL\SourceFilter\DisabledSourceFilter;
use PHPUnit\Framework\TestCase;
-class HasSourceFieldsTraitTest extends TestCase
+final class HasSourceFieldsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasSourceFieldsTrait $object */
- $object = $this->getMockBuilder(HasSourceFieldsTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasSourceFieldsTrait;
+ };
$object->setSourceFields(new DisabledSourceFilter());
- $this->assertEquals(new DisabledSourceFilter(), $object->getSourceFields());
+ self::assertEquals(new DisabledSourceFilter(), $object->getSourceFields());
}
}
diff --git a/tests/SearchRequest/HasStatGroupsTraitTest.php b/tests/SearchRequest/HasStatGroupsTraitTest.php
index 7a5e723..a6f5509 100644
--- a/tests/SearchRequest/HasStatGroupsTraitTest.php
+++ b/tests/SearchRequest/HasStatGroupsTraitTest.php
@@ -4,17 +4,19 @@
use PHPUnit\Framework\TestCase;
-class HasStatGroupsTraitTest extends TestCase
+final class HasStatGroupsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasStatGroupsTrait $object */
- $object = $this->getMockBuilder(HasStatGroupsTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasStatGroupsTrait;
+ };
$object
->setStatGroups(['group1', 'group2'])
->addStatGroup('group3');
- $this->assertEquals(['group1', 'group2', 'group3'], $object->getStatGroups());
+ self::assertEquals(['group1', 'group2', 'group3'], $object->getStatGroups());
}
}
diff --git a/tests/SearchRequest/HasStoredFieldsTraitTest.php b/tests/SearchRequest/HasStoredFieldsTraitTest.php
index 67fc0a3..c70f7ac 100644
--- a/tests/SearchRequest/HasStoredFieldsTraitTest.php
+++ b/tests/SearchRequest/HasStoredFieldsTraitTest.php
@@ -4,15 +4,17 @@
use PHPUnit\Framework\TestCase;
-class HasStoredFieldsTraitTest extends TestCase
+final class HasStoredFieldsTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasStoredFieldsTrait $object */
- $object = $this->getMockBuilder(HasStoredFieldsTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasStoredFieldsTrait;
+ };
$object->setStoredFields(['field1', 'field2']);
- $this->assertEquals(['field1', 'field2'], $object->getStoredFields());
+ self::assertEquals(['field1', 'field2'], $object->getStoredFields());
}
}
diff --git a/tests/SearchRequest/HasSuggestersTraitTest.php b/tests/SearchRequest/HasSuggestersTraitTest.php
index 78ee41f..d6013c8 100644
--- a/tests/SearchRequest/HasSuggestersTraitTest.php
+++ b/tests/SearchRequest/HasSuggestersTraitTest.php
@@ -5,12 +5,14 @@
use Gskema\ElasticSearchQueryDSL\Suggester\TermSuggester;
use PHPUnit\Framework\TestCase;
-class HasSuggestersTraitTest extends TestCase
+final class HasSuggestersTraitTest extends TestCase
{
- public function testMethods()
+ public function testMethods(): void
{
/** @var HasSuggestersTrait $object */
- $object = $this->getMockBuilder(HasSuggestersTrait::class)->getMockForTrait();
+ $object = new class {
+ use HasSuggestersTrait;
+ };
$object
->setSuggesters([
@@ -20,9 +22,9 @@ public function testMethods()
->setSuggester('key3', new TermSuggester('field3', 'text3'))
->removeSuggester('key1');
- $this->assertEquals(null, $object->getSuggester('key1'));
- $this->assertEquals(new TermSuggester('field2', 'text2'), $object->getSuggester('key2'));
- $this->assertEquals([
+ self::assertEquals(null, $object->getSuggester('key1'));
+ self::assertEquals(new TermSuggester('field2', 'text2'), $object->getSuggester('key2'));
+ self::assertEquals([
'key2' => new TermSuggester('field2', 'text2'),
'key3' => new TermSuggester('field3', 'text3'),
], $object->getSuggesters());
diff --git a/tests/SearchRequest/InnerHitsRequestTest.php b/tests/SearchRequest/InnerHitsRequestTest.php
index 83cbe62..6dc44e2 100644
--- a/tests/SearchRequest/InnerHitsRequestTest.php
+++ b/tests/SearchRequest/InnerHitsRequestTest.php
@@ -2,16 +2,16 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Highlighter\Highlighter;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Sorter\FieldSorter;
use Gskema\ElasticSearchQueryDSL\Sorter\RawSorter;
use Gskema\ElasticSearchQueryDSL\SourceFilter\DisabledSourceFilter;
-class InnerHitsRequestTest extends AbstractJsonSerializeTest
+final class InnerHitsRequestTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -89,7 +89,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$req = (new InnerHitsRequest())
->setName('name1')
@@ -116,23 +116,23 @@ public function testMethods()
->setField('field6')
);
- $this->assertEquals('name1', $req->getName());
- $this->assertEquals(true, $req->getOption('explain'));
- $this->assertEquals(true, $req->getOption('version'));
- $this->assertEquals(new DisabledSourceFilter(), $req->getSourceFields());
- $this->assertEquals([
+ self::assertEquals('name1', $req->getName());
+ self::assertEquals(true, $req->getOption('explain'));
+ self::assertEquals(true, $req->getOption('version'));
+ self::assertEquals(new DisabledSourceFilter(), $req->getSourceFields());
+ self::assertEquals([
'scriptField1' => new InlineScript('script1'),
'scriptField2' => new InlineScript('script2'),
'scriptField3' => new InlineScript('script3'),
], $req->getScriptFields());
- $this->assertEquals(['docValueField1', 'docValueField2'], $req->getDocValueFields());
- $this->assertEquals(10, $req->getFrom());
- $this->assertEquals(5, $req->getSize());
- $this->assertEquals([
+ self::assertEquals(['docValueField1', 'docValueField2'], $req->getDocValueFields());
+ self::assertEquals(10, $req->getFrom());
+ self::assertEquals(5, $req->getSize());
+ self::assertEquals([
new FieldSorter('field3', 'desc'),
new RawSorter('field4')
], $req->getSorters());
- $this->assertEquals(
+ self::assertEquals(
(new Highlighter())
->setField('field5', ['order' => 'score'])
->setField('field6'),
diff --git a/tests/SearchRequest/RawSearchRequestTest.php b/tests/SearchRequest/RawSearchRequestTest.php
index 3f1d6a1..9382027 100644
--- a/tests/SearchRequest/RawSearchRequestTest.php
+++ b/tests/SearchRequest/RawSearchRequestTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawSearchRequestTest extends RawFragmentTest
+final class RawSearchRequestTest extends RawFragmentTest
{
}
diff --git a/tests/SearchRequest/SearchRequestTest.php b/tests/SearchRequest/SearchRequestTest.php
index 9eed778..5708fa3 100644
--- a/tests/SearchRequest/SearchRequestTest.php
+++ b/tests/SearchRequest/SearchRequestTest.php
@@ -2,7 +2,7 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Aggregation\Bucket\FilterAggregation;
use Gskema\ElasticSearchQueryDSL\Aggregation\Bucket\TermsAggregation;
use Gskema\ElasticSearchQueryDSL\Aggregation\Metric\MaxAggregation;
@@ -20,9 +20,9 @@
use Gskema\ElasticSearchQueryDSL\Suggester\PhraseSuggester;
use Gskema\ElasticSearchQueryDSL\Suggester\TermSuggester;
-class SearchRequestTest extends AbstractJsonSerializeTest
+final class SearchRequestTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -178,7 +178,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$req = (new SearchRequest())
->setOptions([
@@ -225,41 +225,41 @@ public function testMethods()
])
->setAgg('agg3', MaxAggregation::fromField('field11'));
- $this->assertEquals(true, $req->getOption('explain'));
- $this->assertEquals(true, $req->getOption('version'));
- $this->assertEquals(new DisabledSourceFilter(), $req->getSourceFields());
- $this->assertEquals(['storedField1', 'storedField2'], $req->getStoredFields());
- $this->assertEquals([
+ self::assertEquals(true, $req->getOption('explain'));
+ self::assertEquals(true, $req->getOption('version'));
+ self::assertEquals(new DisabledSourceFilter(), $req->getSourceFields());
+ self::assertEquals(['storedField1', 'storedField2'], $req->getStoredFields());
+ self::assertEquals([
'scriptField1' => new InlineScript('script1'),
'scriptField2' => new InlineScript('script2'),
'scriptField3' => new InlineScript('script3'),
], $req->getScriptFields());
- $this->assertEquals(['docValueField1', 'docValueField2'], $req->getDocValueFields());
- $this->assertEquals(10, $req->getFrom());
- $this->assertEquals(5, $req->getSize());
- $this->assertEquals(new TermMatcher('field1', 'value1'), $req->getQuery());
- $this->assertEquals(new WildcardMatcher('field2', 'value*'), $req->getPostFilter());
- $this->assertEquals([
+ self::assertEquals(['docValueField1', 'docValueField2'], $req->getDocValueFields());
+ self::assertEquals(10, $req->getFrom());
+ self::assertEquals(5, $req->getSize());
+ self::assertEquals(new TermMatcher('field1', 'value1'), $req->getQuery());
+ self::assertEquals(new WildcardMatcher('field2', 'value*'), $req->getPostFilter());
+ self::assertEquals([
new FieldSorter('field3', 'desc'),
new RawSorter('field4'),
], $req->getSorters());
- $this->assertEquals([
+ self::assertEquals([
(new QueryRescorer(new MatchAllMatcher()))->setScoreMode('avg'),
new QueryRescorer(new MatchNoneMatcher()),
], $req->getRescorers());
- $this->assertEquals(
+ self::assertEquals(
(new Highlighter())
->setField('field5', ['order' => 'score'])
->setField('field6'),
$req->getHighlighter()
);
- $this->assertEquals([
+ self::assertEquals([
'suggesterKey1' => new TermSuggester('field7', 'text1'),
'suggesterKey2' => new PhraseSuggester('field8', 'text2'),
], $req->getSuggesters());
- $this->assertEquals(['statGroup1', 'statGroup2', 'statGroup3'], $req->getStatGroups());
- $this->assertEquals(new FieldCollapser('field9'), $req->getFieldCollapser());
- $this->assertEquals([
+ self::assertEquals(['statGroup1', 'statGroup2', 'statGroup3'], $req->getStatGroups());
+ self::assertEquals(new FieldCollapser('field9'), $req->getFieldCollapser());
+ self::assertEquals([
'agg1' => (new FilterAggregation(new MatchAllMatcher()))
->setAgg('agg2', TermsAggregation::fromField('field10')),
'agg3' => MaxAggregation::fromField('field11')
diff --git a/tests/SearchRequest/TopHitsRequestTest.php b/tests/SearchRequest/TopHitsRequestTest.php
index 96d2a6d..1e7b1ba 100644
--- a/tests/SearchRequest/TopHitsRequestTest.php
+++ b/tests/SearchRequest/TopHitsRequestTest.php
@@ -2,16 +2,16 @@
namespace Gskema\ElasticSearchQueryDSL\SearchRequest;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Highlighter\Highlighter;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
use Gskema\ElasticSearchQueryDSL\Sorter\FieldSorter;
use Gskema\ElasticSearchQueryDSL\Sorter\RawSorter;
use Gskema\ElasticSearchQueryDSL\SourceFilter\DisabledSourceFilter;
-class TopHitsRequestTest extends AbstractJsonSerializeTest
+final class TopHitsRequestTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -90,7 +90,7 @@ public function dataTestJsonSerialize(): array
}
- public function testMethods()
+ public function testMethods(): void
{
$req = (new TopHitsRequest())
->setOptions([
@@ -117,23 +117,23 @@ public function testMethods()
->setField('field6')
);
- $this->assertEquals(true, $req->getOption('explain'));
- $this->assertEquals(true, $req->getOption('version'));
- $this->assertEquals(new DisabledSourceFilter(), $req->getSourceFields());
- $this->assertEquals([
+ self::assertEquals(true, $req->getOption('explain'));
+ self::assertEquals(true, $req->getOption('version'));
+ self::assertEquals(new DisabledSourceFilter(), $req->getSourceFields());
+ self::assertEquals([
'scriptField1' => new InlineScript('script1'),
'scriptField2' => new InlineScript('script2'),
'scriptField3' => new InlineScript('script3'),
], $req->getScriptFields());
- $this->assertEquals(['storedField1', 'storedField2'], $req->getStoredFields());
- $this->assertEquals(['docValueField1', 'docValueField2'], $req->getDocValueFields());
- $this->assertEquals(10, $req->getFrom());
- $this->assertEquals(5, $req->getSize());
- $this->assertEquals([
+ self::assertEquals(['storedField1', 'storedField2'], $req->getStoredFields());
+ self::assertEquals(['docValueField1', 'docValueField2'], $req->getDocValueFields());
+ self::assertEquals(10, $req->getFrom());
+ self::assertEquals(5, $req->getSize());
+ self::assertEquals([
new FieldSorter('field3', 'desc'),
new RawSorter('field4')
], $req->getSorters());
- $this->assertEquals(
+ self::assertEquals(
(new Highlighter())
->setField('field5', ['order' => 'score'])
->setField('field6'),
diff --git a/tests/Sorter/FieldSorterTest.php b/tests/Sorter/FieldSorterTest.php
index 495503f..d87e226 100644
--- a/tests/Sorter/FieldSorterTest.php
+++ b/tests/Sorter/FieldSorterTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Sorter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class FieldSorterTest extends AbstractJsonSerializeTest
+final class FieldSorterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -32,20 +32,20 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$sorter = new FieldSorter('field1', 'order1', 'mode1');
- $this->assertEquals('field1', $sorter->getField());
- $this->assertEquals('order1', $sorter->getOrder());
- $this->assertEquals('mode1', $sorter->getMode());
+ self::assertEquals('field1', $sorter->getField());
+ self::assertEquals('order1', $sorter->getOrder());
+ self::assertEquals('mode1', $sorter->getMode());
$sorter->setOrder('order2');
$sorter->setMode('mode2');
$sorter->setOption('key1', 'value1');
- $this->assertEquals('order2', $sorter->getOrder());
- $this->assertEquals('mode2', $sorter->getMode());
- $this->assertEquals('value1', $sorter->getOption('key1'));
+ self::assertEquals('order2', $sorter->getOrder());
+ self::assertEquals('mode2', $sorter->getMode());
+ self::assertEquals('value1', $sorter->getOption('key1'));
}
}
diff --git a/tests/Sorter/GeoDistanceSorterTest.php b/tests/Sorter/GeoDistanceSorterTest.php
index 6630cc9..5faf10d 100644
--- a/tests/Sorter/GeoDistanceSorterTest.php
+++ b/tests/Sorter/GeoDistanceSorterTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Sorter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoHash;
use Gskema\ElasticSearchQueryDSL\Model\GeoPoint;
-class GeoDistanceSorterTest extends AbstractJsonSerializeTest
+final class GeoDistanceSorterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -70,21 +70,21 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$sorter = new GeoDistanceSorter('field1', [new GeoHash('abc123')]);
- $this->assertEquals('field1', $sorter->getField());
- $this->assertEquals([new GeoHash('abc123')], $sorter->getOrigins());
+ self::assertEquals('field1', $sorter->getField());
+ self::assertEquals([new GeoHash('abc123')], $sorter->getOrigins());
$sorter->setOrder('order1');
$sorter->setMode('mode1');
$sorter->setUnit('km');
$sorter->setOption('key1', 'value1');
- $this->assertEquals('order1', $sorter->getOrder());
- $this->assertEquals('mode1', $sorter->getMode());
- $this->assertEquals('km', $sorter->getUnit());
- $this->assertEquals('value1', $sorter->getOption('key1'));
+ self::assertEquals('order1', $sorter->getOrder());
+ self::assertEquals('mode1', $sorter->getMode());
+ self::assertEquals('km', $sorter->getUnit());
+ self::assertEquals('value1', $sorter->getOption('key1'));
}
}
diff --git a/tests/Sorter/NestedSorterTest.php b/tests/Sorter/NestedSorterTest.php
index 8e8d6b9..fb9bfbb 100644
--- a/tests/Sorter/NestedSorterTest.php
+++ b/tests/Sorter/NestedSorterTest.php
@@ -2,12 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Sorter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
+use stdClass;
-class NestedSorterTest extends AbstractJsonSerializeTest
+final class NestedSorterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -40,27 +41,27 @@ public function dataTestJsonSerialize(): array
->setMode('max')
->setNestedFilter(new MatchAllMatcher())
->setOrder('desc'),
- new \stdClass(),
+ new stdClass(),
];
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$sorter = new NestedSorter('field1', 'path1');
- $this->assertEquals('field1', $sorter->getField());
- $this->assertEquals('path1', $sorter->getNestedPath());
+ self::assertEquals('field1', $sorter->getField());
+ self::assertEquals('path1', $sorter->getNestedPath());
$sorter->setOrder('order1');
$sorter->setMode('mode1');
$sorter->setNestedFilter(new MatchAllMatcher());
$sorter->setOption('key1', 'value1');
- $this->assertEquals('order1', $sorter->getOrder());
- $this->assertEquals('mode1', $sorter->getMode());
- $this->assertEquals(new MatchAllMatcher(), $sorter->getNestedFilter());
- $this->assertEquals('value1', $sorter->getOption('key1'));
+ self::assertEquals('order1', $sorter->getOrder());
+ self::assertEquals('mode1', $sorter->getMode());
+ self::assertEquals(new MatchAllMatcher(), $sorter->getNestedFilter());
+ self::assertEquals('value1', $sorter->getOption('key1'));
}
}
diff --git a/tests/Sorter/RawSorterTest.php b/tests/Sorter/RawSorterTest.php
index 017b5bb..dc28adc 100644
--- a/tests/Sorter/RawSorterTest.php
+++ b/tests/Sorter/RawSorterTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawSorterTest extends RawFragmentTest
+final class RawSorterTest extends RawFragmentTest
{
}
diff --git a/tests/Sorter/ScriptSorterTest.php b/tests/Sorter/ScriptSorterTest.php
index 80d244f..5baea08 100644
--- a/tests/Sorter/ScriptSorterTest.php
+++ b/tests/Sorter/ScriptSorterTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Sorter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\Script\FileScript;
use Gskema\ElasticSearchQueryDSL\Model\Script\InlineScript;
-class ScriptSorterTest extends AbstractJsonSerializeTest
+final class ScriptSorterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -20,7 +20,7 @@ public function dataTestJsonSerialize(): array
"type": "number",
"script": "script1",
"order": "asc"
- }
+ }
}',
(new ScriptSorter('number', new InlineScript('script1')))->setOrder('asc'),
];
@@ -37,7 +37,7 @@ public function dataTestJsonSerialize(): array
"order": "asc",
"mode": "avg"
}
-
+
}',
(new ScriptSorter('number', new FileScript('file1')))
->setOrder('asc')
@@ -47,17 +47,17 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$sorter = new ScriptSorter('type1', new InlineScript('source1'));
- $this->assertEquals('type1', $sorter->getType());
- $this->assertEquals(new InlineScript('source1'), $sorter->getScript());
+ self::assertEquals('type1', $sorter->getType());
+ self::assertEquals(new InlineScript('source1'), $sorter->getScript());
$sorter->setOrder('order1');
$sorter->setMode('mode1');
- $this->assertEquals('order1', $sorter->getOrder());
- $this->assertEquals('mode1', $sorter->getMode());
+ self::assertEquals('order1', $sorter->getOrder());
+ self::assertEquals('mode1', $sorter->getMode());
}
}
diff --git a/tests/SourceFilter/DisabledSourceFilterTest.php b/tests/SourceFilter/DisabledSourceFilterTest.php
index 07ee961..1bb9c3e 100644
--- a/tests/SourceFilter/DisabledSourceFilterTest.php
+++ b/tests/SourceFilter/DisabledSourceFilterTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\SourceFilter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class DisabledSourceFilterTest extends AbstractJsonSerializeTest
+final class DisabledSourceFilterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
diff --git a/tests/SourceFilter/RawSourceFilterTest.php b/tests/SourceFilter/RawSourceFilterTest.php
index f90d9c9..4e25c25 100644
--- a/tests/SourceFilter/RawSourceFilterTest.php
+++ b/tests/SourceFilter/RawSourceFilterTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawSourceFilterTest extends RawFragmentTest
+final class RawSourceFilterTest extends RawFragmentTest
{
}
diff --git a/tests/SourceFilter/SourceFilterTest.php b/tests/SourceFilter/SourceFilterTest.php
index a810f49..29aa833 100644
--- a/tests/SourceFilter/SourceFilterTest.php
+++ b/tests/SourceFilter/SourceFilterTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\SourceFilter;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class SourceFilterTest extends AbstractJsonSerializeTest
+final class SourceFilterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -53,7 +53,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$filter = (new SourceFilter())
->setIncludes(['inc1', 'inc2'])
@@ -61,7 +61,7 @@ public function testMethods()
->addInclude('inc3')
->addExclude('exc3');
- $this->assertEquals(['inc1', 'inc2', 'inc3'], $filter->getIncludes());
- $this->assertEquals(['exc1', 'exc2', 'exc3'], $filter->getExcludes());
+ self::assertEquals(['inc1', 'inc2', 'inc3'], $filter->getIncludes());
+ self::assertEquals(['exc1', 'exc2', 'exc3'], $filter->getExcludes());
}
}
diff --git a/tests/Suggester/CandidateGenerator/DirectCandidateGeneratorTest.php b/tests/Suggester/CandidateGenerator/DirectCandidateGeneratorTest.php
index 53e0718..c52ea32 100644
--- a/tests/Suggester/CandidateGenerator/DirectCandidateGeneratorTest.php
+++ b/tests/Suggester/CandidateGenerator/DirectCandidateGeneratorTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester\CandidateGenerator;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class DirectCandidateGeneratorTest extends AbstractJsonSerializeTest
+final class DirectCandidateGeneratorTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -32,10 +32,10 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$generator = new DirectCandidateGenerator('field1', ['size' => 1]);
- $this->assertInstanceOf(DirectCandidateGenerator::class, $generator);
+ self::assertInstanceOf(DirectCandidateGenerator::class, $generator);
}
}
diff --git a/tests/Suggester/CandidateGenerator/RawCandidateGeneratorTest.php b/tests/Suggester/CandidateGenerator/RawCandidateGeneratorTest.php
index 92da923..4d3a48f 100644
--- a/tests/Suggester/CandidateGenerator/RawCandidateGeneratorTest.php
+++ b/tests/Suggester/CandidateGenerator/RawCandidateGeneratorTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawCandidateGeneratorTest extends RawFragmentTest
+final class RawCandidateGeneratorTest extends RawFragmentTest
{
}
diff --git a/tests/Suggester/CompletionSuggesterTest.php b/tests/Suggester/CompletionSuggesterTest.php
index 6b0a0a9..09a19fc 100644
--- a/tests/Suggester/CompletionSuggesterTest.php
+++ b/tests/Suggester/CompletionSuggesterTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class CompletionSuggesterTest extends AbstractJsonSerializeTest
+final class CompletionSuggesterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -37,12 +37,12 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$suggester1 = CompletionSuggester::fromPrefix('field1', 'prefix1');
- $this->assertInstanceOf(CompletionSuggester::class, $suggester1);
+ self::assertInstanceOf(CompletionSuggester::class, $suggester1);
$suggester2 = CompletionSuggester::fromRegex('field1', 'regex1');
- $this->assertInstanceOf(CompletionSuggester::class, $suggester2);
+ self::assertInstanceOf(CompletionSuggester::class, $suggester2);
}
}
diff --git a/tests/Suggester/ContextQuery/CategoryContextQueryTest.php b/tests/Suggester/ContextQuery/CategoryContextQueryTest.php
index a411e44..40b9e89 100644
--- a/tests/Suggester/ContextQuery/CategoryContextQueryTest.php
+++ b/tests/Suggester/ContextQuery/CategoryContextQueryTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester\ContextQuery;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class CategoryContextQueryTest extends AbstractJsonSerializeTest
+final class CategoryContextQueryTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -41,11 +41,11 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$ctxQuery = (new CategoryContextQuery())
->addCategory('category1', 1.1, 'prefix1');
- $this->assertInstanceOf(CategoryContextQuery::class, $ctxQuery);
+ self::assertInstanceOf(CategoryContextQuery::class, $ctxQuery);
}
}
diff --git a/tests/Suggester/ContextQuery/GeoLocationContextQueryTest.php b/tests/Suggester/ContextQuery/GeoLocationContextQueryTest.php
index a25ed0f..2cead32 100644
--- a/tests/Suggester/ContextQuery/GeoLocationContextQueryTest.php
+++ b/tests/Suggester/ContextQuery/GeoLocationContextQueryTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester\ContextQuery;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Model\GeoPoint;
-class GeoLocationContextQueryTest extends AbstractJsonSerializeTest
+final class GeoLocationContextQueryTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -54,11 +54,11 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$ctxQuery = (new GeoLocationContextQuery())
->addGeoPoint(new GeoPoint(1.1, 1.1), 5, 1.0, ['1km', '2km']);
- $this->assertInstanceOf(GeoLocationContextQuery::class, $ctxQuery);
+ self::assertInstanceOf(GeoLocationContextQuery::class, $ctxQuery);
}
}
diff --git a/tests/Suggester/ContextQuery/RawContextQueryTest.php b/tests/Suggester/ContextQuery/RawContextQueryTest.php
index f327855..e777e94 100644
--- a/tests/Suggester/ContextQuery/RawContextQueryTest.php
+++ b/tests/Suggester/ContextQuery/RawContextQueryTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawContextQueryTest extends RawFragmentTest
+final class RawContextQueryTest extends RawFragmentTest
{
}
diff --git a/tests/Suggester/ContextSuggesterTest.php b/tests/Suggester/ContextSuggesterTest.php
index d9d14ec..684d470 100644
--- a/tests/Suggester/ContextSuggesterTest.php
+++ b/tests/Suggester/ContextSuggesterTest.php
@@ -2,12 +2,12 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Suggester\ContextQuery\CategoryContextQuery;
-class ContextSuggesterTest extends AbstractJsonSerializeTest
+final class ContextSuggesterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -59,7 +59,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$suggester1 = ContextSuggester::fromPrefix('field1', 'prefix1')
->setContexts([
@@ -69,13 +69,13 @@ public function testMethods()
->setContext('ctx3', (new CategoryContextQuery())->addCategory('cat3'))
->removeContext('ctx1');
- $this->assertInstanceOf(CompletionSuggester::class, $suggester1);
- $this->assertEquals(null, $suggester1->getContext('ctx1'));
- $this->assertEquals(
+ self::assertInstanceOf(CompletionSuggester::class, $suggester1);
+ self::assertEquals(null, $suggester1->getContext('ctx1'));
+ self::assertEquals(
(new CategoryContextQuery())->addCategory('cat2'),
$suggester1->getContext('ctx2')
);
- $this->assertEquals(
+ self::assertEquals(
[
'ctx2' => (new CategoryContextQuery())->addCategory('cat2'),
'ctx3' => (new CategoryContextQuery())->addCategory('cat3'),
@@ -84,6 +84,6 @@ public function testMethods()
);
$suggester2 = ContextSuggester::fromRegex('field1', 'regex1');
- $this->assertInstanceOf(CompletionSuggester::class, $suggester2);
+ self::assertInstanceOf(CompletionSuggester::class, $suggester2);
}
}
diff --git a/tests/Suggester/PhraseSuggesterTest.php b/tests/Suggester/PhraseSuggesterTest.php
index 303f5e4..98883cf 100644
--- a/tests/Suggester/PhraseSuggesterTest.php
+++ b/tests/Suggester/PhraseSuggesterTest.php
@@ -2,13 +2,13 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
use Gskema\ElasticSearchQueryDSL\Matcher\MatchAllMatcher;
use Gskema\ElasticSearchQueryDSL\Suggester\CandidateGenerator\DirectCandidateGenerator;
-class PhraseSuggesterTest extends AbstractJsonSerializeTest
+final class PhraseSuggesterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -51,7 +51,7 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$suggester = (new PhraseSuggester('field1', 'text1', ['key1' => 'value1']))
->setDirectGenerators([
@@ -60,8 +60,8 @@ public function testMethods()
->addDirectGenerator(new DirectCandidateGenerator('field2'))
->setCollate(new MatchAllMatcher(), ['param1' => 'value1'], true);
- $this->assertInstanceOf(PhraseSuggester::class, $suggester);
- $this->assertEquals([
+ self::assertInstanceOf(PhraseSuggester::class, $suggester);
+ self::assertEquals([
new DirectCandidateGenerator('field1'),
new DirectCandidateGenerator('field2'),
], $suggester->getDirectGenerators());
diff --git a/tests/Suggester/RawSuggesterTest.php b/tests/Suggester/RawSuggesterTest.php
index f56c4c1..715e643 100644
--- a/tests/Suggester/RawSuggesterTest.php
+++ b/tests/Suggester/RawSuggesterTest.php
@@ -4,6 +4,6 @@
use Gskema\ElasticSearchQueryDSL\RawFragmentTest;
-class RawSuggesterTest extends RawFragmentTest
+final class RawSuggesterTest extends RawFragmentTest
{
}
diff --git a/tests/Suggester/TermSuggesterTest.php b/tests/Suggester/TermSuggesterTest.php
index 5e4b5ad..fa57df3 100644
--- a/tests/Suggester/TermSuggesterTest.php
+++ b/tests/Suggester/TermSuggesterTest.php
@@ -2,11 +2,11 @@
namespace Gskema\ElasticSearchQueryDSL\Suggester;
-use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTest;
+use Gskema\ElasticSearchQueryDSL\AbstractJsonSerializeTestCase;
-class TermSuggesterTest extends AbstractJsonSerializeTest
+final class TermSuggesterTest extends AbstractJsonSerializeTestCase
{
- public function dataTestJsonSerialize(): array
+ public static function dataTestJsonSerialize(): iterable
{
$dataSets = [];
@@ -38,11 +38,11 @@ public function dataTestJsonSerialize(): array
return $dataSets;
}
- public function testMethods()
+ public function testMethods(): void
{
$suggester = (new TermSuggester('field1', 'text1'))->setOption('shard_size', 5);
- $this->assertInstanceOf(TermSuggester::class, $suggester);
- $this->assertEquals(5, $suggester->getOption('shard_size'));
+ self::assertInstanceOf(TermSuggester::class, $suggester);
+ self::assertEquals(5, $suggester->getOption('shard_size'));
}
}