From 034052be5a45237755c35214385fdb3f1ef7cd15 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Mon, 8 Jun 2026 23:33:14 +0800 Subject: [PATCH 01/24] =?UTF-8?q?feat(index):=20Rebuild=20=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E9=94=81=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=20Rebuild=20=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用 ES 文档 create (op_type=create) 实现分布式锁: - run() 自动加锁/解锁 (try/finally) - forceUnlock() 手动释放残留锁 - isLocked() 查询锁状态 - ensureLockIndex() 自动创建 .ek_locks 系统索引 Co-Authored-By: Claude Opus 4.8 --- CLAUDE.md | 16 +++ phpstan-baseline.neon | 25 +++- src/Index/Rebuild.php | 191 ++++++++++++++++++++++---- tests/Index/RebuildTest.php | 259 +++++++++++++++++++++++++++++++++++- 4 files changed, 456 insertions(+), 35 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 61b6b43..e3b8a61 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -36,6 +36,20 @@ Scope 可选:dsl / index / agg / query / docs。Breaking change 加 `!` 后缀 PSR-5 规范。 +## 待办 + +- [ ] **clone query 后 try-finally 恢复**:first() / paginate() 等方法 clone query 后修改状态,需 try-finally 确保恢复 +- [ ] **ClausesSupport API 统一**:废弃 addXXX() 方法,原 API(如 must())直接使用追加语义 +- [ ] **hasMore() 判断逻辑修复**:待确认(看代码) +- [ ] **Rebuild::rollback() 支持多索引别名**:当前只移除 `$currentList[0]`,应遍历全部 remove,参考 `doRun()` 循环写法 +- [ ] **Index::$name 空验证**:子类未设置 `$name` 时抛异常 +- [ ] **锁抽取为独立类**:通用分布式锁(acquire/release/forceUnlock/isLocked + ensureLockIndex),Bulk 等可复用 +- [ ] **$client 抽到 Registry 类**:新建 Registry 持有 client / pageResolver / paginatorResolver / listeners,Index 不再持有静态状态。旧 API 保留作 deprecated 代理,前期统一放 Registry,后续按需拆分 +- [ ] **Node 构造函数重构**:提取 applyValue,消除重复 +- [ ] **Bulk skipErrors() 设计**:参考 Rebuild 的 skipErrors 模式 +- [ ] **补核心路径的边界测试**:scroll、bulk 分批、rebuild 失败回滚 +- [ ] **搭建集成测试基建**:`ELASTICKIT_TEST_HOST` 驱动,随机索引名隔离 + ## 测试 测试在 Docker 容器中运行,需要设置以下环境变量: @@ -45,10 +59,12 @@ PSR-5 规范。 | `PHP_CONTAINER` | Docker 容器名 | | `PROJECT_PATH` | 项目在容器内的路径 | | `PROXY_PORT` | HTTP 代理端口(推送用) | +| `ELASTICKIT_TEST_HOST` | ES 集成测试地址(如 `https://localhost:9200`),不设置则跳过集成测试 | ```bash docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpunit --testsuite unit" docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpunit --testsuite index" +docker exec -e ELASTICKIT_TEST_HOST=https://elasticsearch:9200 $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpunit --testsuite integration" docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpunit" docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpstan analyse" docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpmd src text phpmd.xml" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 400bc2b..1321b33 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -57,7 +57,30 @@ parameters: - message: '#^Call to an undefined method Elastic\\Elasticsearch\\ClientInterface\:\:indices\(\)\.$#' identifier: method.notFound - count: 4 + count: 5 + path: src/Index/Rebuild.php + + - + message: '#^Call to an undefined method Elastic\\Elasticsearch\\ClientInterface\:\:exists\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/Index/Rebuild.php + + - + message: '#^Call to an undefined method Elastic\\Elasticsearch\\ClientInterface\:\:index\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/Index/Rebuild.php + + - + message: '#^Call to an undefined method Elastic\\Elasticsearch\\ClientInterface\:\:delete\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/Index/Rebuild.php + + - + message: '#^If condition is always false\.$#' + identifier: if.alwaysFalse path: src/Index/Rebuild.php - diff --git a/src/Index/Rebuild.php b/src/Index/Rebuild.php index 534064e..e8b130e 100644 --- a/src/Index/Rebuild.php +++ b/src/Index/Rebuild.php @@ -2,6 +2,7 @@ namespace ElasticKit\Index; +use Elastic\Elasticsearch\Exception\ClientResponseException; use RuntimeException; use stdClass; @@ -13,6 +14,11 @@ */ class Rebuild { + /** + * Lock index name. + */ + private const LOCK_INDEX = '.ek_locks'; + /** * @var Index */ @@ -107,6 +113,98 @@ public function source($source) * @return array{newIndex: string, oldIndex: string|null} */ public function run(array $context = []) + { + $this->acquireLock(); + + try { + $result = $this->doRun($context); + } finally { + $this->releaseLock(); + } + + return $result; + } + + /** + * Forcibly remove a stale lock left by a crashed rebuild. + * + * Under normal circumstances the lock is released automatically by run(). + * Call this only when a previous rebuild crashed and the lock persists. + */ + public function forceUnlock(): void + { + $this->releaseLock(); + } + + /** + * Check whether a rebuild lock is currently held for this index. + * + * @return bool + */ + public function isLocked(): bool + { + try { + return $this->index->getClient()->exists([ + 'index' => self::LOCK_INDEX, + 'id' => $this->index->name(), + ])->asBool(); + } catch (ClientResponseException $e) { + return false; + } + } + + /** + * Delete a specific backing index by name. + * + * @param string $indexName the backing index to delete + */ + public function clean(string $indexName): void + { + $this->index->getClient()->indices()->delete([ + 'index' => $indexName, + ]); + } + + /** + * Rollback alias to a specific previous backing index. + * + * @param string $targetIndex the backing index to roll back to + * @return string the index name that was rolled back from + * @throws RuntimeException if alias or target index does not exist + */ + public function rollback(string $targetIndex): string + { + $name = $this->index->name(); + $client = $this->index->getClient()->indices(); + + $currentList = array_keys($client->getAlias(['name' => $name])->asArray()); + if (empty($currentList)) { + throw new RuntimeException("No index found for alias [{$name}]"); + } + + if (!$client->exists(['index' => $targetIndex])->asBool()) { + throw new RuntimeException("Target index [{$targetIndex}] does not exist"); + } + + $client->updateAliases([ + 'body' => [ + 'actions' => [ + ['remove' => ['index' => $currentList[0], 'alias' => $name]], + ['add' => ['index' => $targetIndex, 'alias' => $name]], + ], + ], + ]); + + return $currentList[0]; + } + + /** + * Execute the rebuild logic (called after lock is acquired). + * + * @param array $context + * @return array{newIndex: string, oldIndex: string|null} + */ + private function doRun(array $context): array { $name = $this->index->name(); $client = $this->index->getClient()->indices(); @@ -155,48 +253,83 @@ public function run(array $context = []) } /** - * Delete a specific backing index by name. + * Acquire the distributed lock using ES document create (op_type=create). * - * @param string $indexName the backing index to delete + * @throws RuntimeException if the lock is already held */ - public function clean(string $indexName): void + private function acquireLock(): void { - $this->index->getClient()->indices()->delete([ - 'index' => $indexName, - ]); + $this->ensureLockIndex(); + + $name = $this->index->name(); + + try { + $this->index->getClient()->index([ + 'index' => self::LOCK_INDEX, + 'id' => $name, + 'body' => ['locked_at' => date(\DateTimeInterface::ATOM)], + 'op_type' => 'create', + ]); + } catch (ClientResponseException $e) { + if ($e->getResponse()->getStatusCode() === 409) { + throw new RuntimeException( + "Rebuild for [{$name}] is already running. " + . "Call forceUnlock() if the previous rebuild crashed." + ); + } + throw $e; + } } /** - * Rollback alias to a specific previous backing index. - * - * @param string $targetIndex the backing index to roll back to - * @return string the index name that was rolled back from - * @throws RuntimeException if alias or target index does not exist + * Release the distributed lock. Idempotent — silently ignores 404. */ - public function rollback(string $targetIndex): string + private function releaseLock(): void { - $name = $this->index->name(); - $client = $this->index->getClient()->indices(); - - $currentList = array_keys($client->getAlias(['name' => $name])->asArray()); - if (empty($currentList)) { - throw new RuntimeException("No index found for alias [{$name}]"); + try { + $this->index->getClient()->delete([ + 'index' => self::LOCK_INDEX, + 'id' => $this->index->name(), + ]); + } catch (ClientResponseException $e) { + if ($e->getResponse()->getStatusCode() !== 404) { + throw $e; + } + // Lock already gone — idempotent + } catch (\Throwable $e) { + // Swallow transport / server errors in finally to avoid masking the original exception } + } - if (!$client->exists(['index' => $targetIndex])->asBool()) { - throw new RuntimeException("Target index [{$targetIndex}] does not exist"); + /** + * Ensure the lock index exists. Handles concurrent creation races. + */ + private function ensureLockIndex(): void + { + $indices = $this->index->getClient()->indices(); + + if ($indices->exists(['index' => self::LOCK_INDEX])->asBool()) { + return; } - $client->updateAliases([ - 'body' => [ - 'actions' => [ - ['remove' => ['index' => $currentList[0], 'alias' => $name]], - ['add' => ['index' => $targetIndex, 'alias' => $name]], + try { + $indices->create([ + 'index' => self::LOCK_INDEX, + 'body' => [ + 'settings' => [ + 'number_of_shards' => 1, + 'number_of_replicas' => 0, + 'index.hidden' => true, + ], ], - ], - ]); - - return $currentList[0]; + ]); + } catch (ClientResponseException $e) { + // Race: another process may have created it concurrently + if ($indices->exists(['index' => self::LOCK_INDEX])->asBool()) { + return; + } + throw $e; + } } /** diff --git a/tests/Index/RebuildTest.php b/tests/Index/RebuildTest.php index 7e8b79c..97b18b2 100644 --- a/tests/Index/RebuildTest.php +++ b/tests/Index/RebuildTest.php @@ -40,13 +40,20 @@ public function testRunCreatesBackingIndexAndSetsAlias() }))->willReturn(new ArrayResponse(['acknowledged' => true])); $indices->method('existsAlias')->willReturn(new BoolResponse(false)); - $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); $indices->expects($this->once())->method('putAlias')->with($this->callback(function ($params) { return strpos($params['index'], 'products_') === 0 && $params['name'] === 'products'; }))->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->expects($this->once())->method('bulk')->with($this->callback(function ($params) { return count($params['body']) === 4 && $params['body'][0]['index']['_id'] === 1 @@ -78,6 +85,7 @@ public function testRunSwapsAliasAtomically() { $indices = $this->createMock(TestIndices::class); $indices->expects($this->once())->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(true)); $indices->method('existsAlias')->willReturn(new BoolResponse(true)); $indices->method('getAlias')->willReturn(new ArrayResponse(['products_v1' => ['aliases' => ['products' => []]]])); $indices->expects($this->once())->method('updateAliases')->with($this->callback(function ($params) { @@ -90,6 +98,8 @@ public function testRunSwapsAliasAtomically() $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); Index::setClient($client); @@ -119,6 +129,8 @@ public function testRunThrowsWhenNameIsRealIndex() $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); Index::setClient($client); @@ -144,11 +156,18 @@ public function testRunWithBatchSize() $indices = $this->createMock(TestIndices::class); $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); $indices->method('existsAlias')->willReturn(new BoolResponse(false)); - $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->expects($this->exactly(2))->method('bulk')->willReturn(new ArrayResponse(['items' => []])); Index::setClient($client); @@ -174,11 +193,18 @@ public function testRunWithCustomSource() $indices = $this->createMock(TestIndices::class); $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); $indices->method('existsAlias')->willReturn(new BoolResponse(false)); - $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->expects($this->once())->method('bulk')->willReturn(new ArrayResponse(['items' => []])); Index::setClient($client); @@ -199,11 +225,18 @@ public function testRunWithCustomRealName() return strpos($params['index'], 'products_v') === 0; }))->willReturn(new ArrayResponse(['acknowledged' => true])); $indices->method('existsAlias')->willReturn(new BoolResponse(false)); - $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); Index::setClient($client); @@ -305,12 +338,15 @@ public function testRunThrowsOnEmptyImport() { $indices = $this->createMock(TestIndices::class); $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(true)); $indices->method('delete')->with($this->callback(function ($params) { return strpos($params['index'], 'products_') === 0; }))->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); Index::setClient($client); $index = new class extends Index { @@ -335,11 +371,18 @@ public function testRunAllowsEmptyImportWithAllowEmpty() $indices = $this->createMock(TestIndices::class); $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); $indices->method('existsAlias')->willReturn(new BoolResponse(false)); - $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); Index::setClient($client); @@ -363,12 +406,15 @@ public function testRunDeletesNewIndexOnImportFailure() { $indices = $this->createMock(TestIndices::class); $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(true)); $indices->expects($this->once())->method('delete')->with($this->callback(function ($params) { return strpos($params['index'], 'products_') === 0; }))->willReturn(new ArrayResponse(['acknowledged' => true])); $client = $this->createMock(TestClient::class); $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); $client->method('bulk')->willReturn(new ArrayResponse(['items' => [], 'errors' => true])); Index::setClient($client); @@ -387,4 +433,207 @@ public function source(array $context = []): iterable $this->expectException(\RuntimeException::class); (new Rebuild($index))->run(); } + + public function testRunAcquiresAndReleasesLock() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); + $indices->method('existsAlias')->willReturn(new BoolResponse(false)); + $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); + $client->expects($this->once())->method('index')->with($this->callback(function ($params) { + return $params['index'] === '.ek_locks' + && $params['id'] === 'products' + && ($params['op_type'] ?? null) === 'create'; + }))->willReturn(new ArrayResponse(['result' => 'created'])); + $client->expects($this->once())->method('delete')->with($this->callback(function ($params) { + return $params['index'] === '.ek_locks' && $params['id'] === 'products'; + }))->willReturn(new ArrayResponse(['result' => 'deleted'])); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + return []; + } + }; + + (new Rebuild($index))->allowEmpty()->run(); + } + + public function testRunReleasesLockOnFailure() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(true)); + $indices->method('delete')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $lockReleased = false; + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturnCallback(function () use (&$lockReleased) { + $lockReleased = true; + return new ArrayResponse(['result' => 'deleted']); + }); + $client->method('bulk')->willReturn(new ArrayResponse(['items' => [], 'errors' => true])); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + yield 1 => ['title' => 'A']; + } + }; + + try { + (new Rebuild($index))->run(); + } catch (\RuntimeException $e) { + // Expected: bulk import error + } + + $this->assertTrue($lockReleased, 'Lock should be released even when run() fails'); + } + + public function testRunThrowsWhenLocked() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('exists')->willReturn(new BoolResponse(true)); + + $response = $this->createMock(\Psr\Http\Message\ResponseInterface::class); + $response->method('getStatusCode')->willReturn(409); + + $exception = new \Elastic\Elasticsearch\Exception\ClientResponseException(); + $exception->setResponse($response); + + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willThrowException($exception); + Index::setClient($client); + + $index = $this->createIndex('products'); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('already running'); + (new Rebuild($index))->source([1 => ['title' => 'A']])->run(); + } + + public function testForceUnlock() + { + $client = $this->createMock(TestClient::class); + $client->expects($this->once())->method('delete')->with($this->callback(function ($params) { + return $params['index'] === '.ek_locks' && $params['id'] === 'products'; + }))->willReturn(new ArrayResponse(['result' => 'deleted'])); + Index::setClient($client); + + $index = $this->createIndex('products'); + (new Rebuild($index))->forceUnlock(); + } + + public function testForceUnlockIsIdempotent() + { + $response = $this->createMock(\Psr\Http\Message\ResponseInterface::class); + $response->method('getStatusCode')->willReturn(404); + + $exception = new \Elastic\Elasticsearch\Exception\ClientResponseException(); + $exception->setResponse($response); + + $client = $this->createMock(TestClient::class); + $client->method('delete')->willThrowException($exception); + Index::setClient($client); + + $index = $this->createIndex('products'); + + // Should not throw despite 404 + (new Rebuild($index))->forceUnlock(); + $this->assertTrue(true); // Reached without exception + } + + public function testIsLockedReturnsTrue() + { + $client = $this->createMock(TestClient::class); + $client->method('exists')->with($this->callback(function ($params) { + return $params['index'] === '.ek_locks' && $params['id'] === 'products'; + }))->willReturn(new BoolResponse(true)); + Index::setClient($client); + + $index = $this->createIndex('products'); + $this->assertTrue((new Rebuild($index))->isLocked()); + } + + public function testIsLockedReturnsFalse() + { + $client = $this->createMock(TestClient::class); + $client->method('exists')->willReturn(new BoolResponse(false)); + Index::setClient($client); + + $index = $this->createIndex('products'); + $this->assertFalse((new Rebuild($index))->isLocked()); + } + + public function testEnsureLockIndexCreatesWhenNotExists() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(false); + } + return new BoolResponse(false); + }); + $indices->method('create')->willReturnCallback(function ($params) { + return new ArrayResponse(['acknowledged' => true]); + }); + $indices->method('existsAlias')->willReturn(new BoolResponse(false)); + $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $lockIndexCreated = false; + $indices->expects($this->exactly(2))->method('create')->willReturnCallback(function ($params) use (&$lockIndexCreated) { + if (($params['index'] ?? '') === '.ek_locks') { + $lockIndexCreated = true; + $this->assertEquals(1, $params['body']['settings']['number_of_shards'] ?? 0); + $this->assertEquals(0, $params['body']['settings']['number_of_replicas'] ?? 1); + } + return new ArrayResponse(['acknowledged' => true]); + }); + + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); + $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + return []; + } + }; + + (new Rebuild($index))->allowEmpty()->run(); + } } From 5e684c73237db878ef250a6f9233f58d46c470c2 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Thu, 11 Jun 2026 21:47:22 +0800 Subject: [PATCH 02/24] =?UTF-8?q?fix(index):=20clone=20query=20=E5=90=8E?= =?UTF-8?q?=20try-finally=20=E6=81=A2=E5=A4=8D=EF=BC=8Ccount()=20=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit first()/scroll()/paginate()/aggregateScalar() 在 doSearch() 异常时 未能恢复 query 状态,改为 try-finally 确保恢复。 count() 对 ES 响应缺失 count 字段时抛 RuntimeException。 --- src/Index/AggregationShortcut.php | 9 ++++---- src/Index/Search.php | 35 ++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Index/AggregationShortcut.php b/src/Index/AggregationShortcut.php index 87581f2..21ac81b 100644 --- a/src/Index/AggregationShortcut.php +++ b/src/Index/AggregationShortcut.php @@ -64,10 +64,11 @@ private function aggregateScalar($type, $field) $this->query = clone $this->query; $this->query->size(0); $this->query->aggs('__scalar', [$type => ['field' => $field]]); - - $response = $this->doSearch($type); - - $this->query = $saved; + try { + $response = $this->doSearch($type); + } finally { + $this->query = $saved; + } return $response['aggregations']['__scalar']['value'] ?? null; } diff --git a/src/Index/Search.php b/src/Index/Search.php index ea2335a..344857f 100644 --- a/src/Index/Search.php +++ b/src/Index/Search.php @@ -4,6 +4,7 @@ use BadMethodCallException; use ElasticKit\DSL\Query; +use RuntimeException; use stdClass; /** @@ -96,10 +97,11 @@ public function first() $saved = $this->query; $this->query = clone $this->query; $this->query->size(1); - - $response = $this->doSearch('first'); - - $this->query = $saved; + try { + $response = $this->doSearch('first'); + } finally { + $this->query = $saved; + } $docs = (new Results($response))->docs(); return $docs[0] ?? null; @@ -112,7 +114,13 @@ public function first() */ public function count() { - return $this->doCount()['count']; + $response = $this->doCount(); + + if (!isset($response['count'])) { + throw new RuntimeException('Missing "count" in Elasticsearch response.'); + } + + return $response['count']; } /** @@ -135,9 +143,11 @@ public function scroll($scrollId = null, $duration = '5m') $this->query->size(1000); } - $response = $this->doSearch('scroll', ['scroll' => $duration]); - - $this->query = $saved; + try { + $response = $this->doSearch('scroll', ['scroll' => $duration]); + } finally { + $this->query = $saved; + } return new Results($response); } @@ -252,10 +262,11 @@ public function paginate($page = null, $perPage = null) $this->query = clone $this->query; $this->query->from(($page - 1) * $perPage); $this->query->size($perPage); - - $response = $this->doSearch('paginate'); - - $this->query = $saved; + try { + $response = $this->doSearch('paginate'); + } finally { + $this->query = $saved; + } return (new Results($response))->paginate($page, $perPage); } From 1c81f573ce8c1831bb1de407ddc696e579b97d90 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 00:32:12 +0800 Subject: [PATCH 03/24] =?UTF-8?q?feat(dsl):=20ClausesSupport=20=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=BF=BD=E5=8A=A0=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Boolean/DisjunctionMax/SpanOr/SpanNear 的 must()/should()/filter() 等改为追加语义 - 每个 clause key 持有一个 Query(multi=true),闭包透传同一对象 - Query 实例通过 addQuery() 存入,buildQuery() 展平取子句 - 新增 Query::getQueries(),_queryClauses 重命名为 _queries - 移除 Compound::wrapQueryAsClosure() --- CLAUDE.md | 4 +- README.md | 2 +- docs/guide.md | 10 ++-- src/DSL/Queries/Compound/Boolean.php | 58 +++----------------- src/DSL/Queries/Compound/DisjunctionMax.php | 15 +---- src/DSL/Queries/Span/SpanNear.php | 15 +---- src/DSL/Queries/Span/SpanOr.php | 15 +---- src/DSL/Query.php | 40 ++++++++++---- src/DSL/Shared/ClausesSupport.php | 61 +++++---------------- tests/CompoundQueriesTest.php | 12 ++-- tests/SpanQueriesTest.php | 8 +-- 11 files changed, 75 insertions(+), 165 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index e3b8a61..a3e419c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -38,8 +38,8 @@ PSR-5 规范。 ## 待办 -- [ ] **clone query 后 try-finally 恢复**:first() / paginate() 等方法 clone query 后修改状态,需 try-finally 确保恢复 -- [ ] **ClausesSupport API 统一**:废弃 addXXX() 方法,原 API(如 must())直接使用追加语义 +- [x] **clone query 后 try-finally 恢复**:first() / paginate() 等方法 clone query 后修改状态,需 try-finally 确保恢复 +- [x] **ClausesSupport API 统一**:must()/should()/filter() 等改为追加语义,移除 addXXX() 方法 - [ ] **hasMore() 判断逻辑修复**:待确认(看代码) - [ ] **Rebuild::rollback() 支持多索引别名**:当前只移除 `$currentList[0]`,应遍历全部 remove,参考 `doRun()` 循环写法 - [ ] **Index::$name 空验证**:子类未设置 `$name` 时抛异常 diff --git a/README.md b/README.md index 85a0b34..fcca21f 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ $bool = Boolean::create() // 增量构建 if ($filterByPrice) { - $bool->addFilter(Range::create('price', [10, 100])); + $bool->filter(Range::create('price', [10, 100])); } $query = Query::create($bool); diff --git a/docs/guide.md b/docs/guide.md index b95f499..543b2de 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -128,17 +128,17 @@ class OrderIndex extends Index // 精确筛选(不需要评分,放 filter) if (!empty($filters['status'])) { - $bool->addFilter(Term::create('status', $filters['status'])); + $bool->filter(Term::create('status', $filters['status'])); } if (!empty($filters['start_date']) && !empty($filters['end_date'])) { - $bool->addFilter(Range::create('created_at', [$filters['start_date'], $filters['end_date']])); + $bool->filter(Range::create('created_at', [$filters['start_date'], $filters['end_date']])); } // 关键词搜索(OR,放 should) if (!empty($filters['keyword'])) { - $bool->addShould(Wildcard::create('order_no', "*{$filters['keyword']}*")); - $bool->addShould(Wildcard::create('merchant_name', "*{$filters['keyword']}*")); + $bool->should(Wildcard::create('order_no', "*{$filters['keyword']}*")); + $bool->should(Wildcard::create('merchant_name', "*{$filters['keyword']}*")); } return static::query(Query::create($bool)); @@ -160,7 +160,7 @@ public function index(Request $request) } ``` -> 条件用 `if` 逐个判断,只有传了值才加查询。`addShould()` 实现 OR 搜索。深分页场景用 `cursor()` 替代 `paginate()`。 +> 条件用 `if` 逐个判断,只有传了值才加查询。`should()` 实现 OR 搜索。深分页场景用 `cursor()` 替代 `paginate()`。 运营还要导出筛选结果到 Excel。ES 默认 `max_result_window = 10000`,`from/size` 翻不到后面的数据,用 `cursor()` 基于 scroll 遍历: diff --git a/src/DSL/Queries/Compound/Boolean.php b/src/DSL/Queries/Compound/Boolean.php index 658fe51..fe6c768 100644 --- a/src/DSL/Queries/Compound/Boolean.php +++ b/src/DSL/Queries/Compound/Boolean.php @@ -4,7 +4,6 @@ use ElasticKit\DSL\Shared\ClausesSupport; use ElasticKit\DSL\Node; -use ElasticKit\DSL\Query; /** * A query that matches documents matching boolean combinations of other queries. The bool query maps to Lucene BooleanQuery. It is built using one or more boolean clauses, each clause with a typed occurrence. The occurrence types are: @@ -17,91 +16,50 @@ class Boolean extends Node /** * The clause (query) must appear in matching documents and will contribute to the score. + * Supports multiple calls to incrementally build the bool query. * * @param mixed $must * @return static */ public function must($must) { - return $this->addProperty('must', Query::create($must)->multi(true)); - } - - /** - * Append a must clause. Supports multiple calls to incrementally build the bool query. - * Clauses are held in a temporary buffer and merged into the must property during serialization. - * - * @param mixed $must - * @return static - */ - public function addMust($must) - { - return $this->pushClause('must', $must); + return $this->addClause('must', $must); } /** * The clause (query) should appear in the matching document. + * Supports multiple calls to incrementally build the bool query. * * @param mixed $should * @return static */ public function should($should) { - return $this->addProperty('should', Query::create($should)->multi(true)); - } - - /** - * Append a should clause. Supports multiple calls to incrementally build the bool query. - * - * @param mixed $should - * @return static - */ - public function addShould($should) - { - return $this->pushClause('should', $should); + return $this->addClause('should', $should); } /** * The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching. + * Supports multiple calls to incrementally build the bool query. * * @param mixed $filter * @return static */ public function filter($filter) { - return $this->addProperty('filter', Query::create($filter)->multi(true)); - } - - /** - * Append a filter clause. Supports multiple calls to incrementally build the bool query. - * - * @param mixed $filter - * @return static - */ - public function addFilter($filter) - { - return $this->pushClause('filter', $filter); + return $this->addClause('filter', $filter); } /** * The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned. + * Supports multiple calls to incrementally build the bool query. * * @param mixed $mustNot * @return static */ public function mustNot($mustNot) { - return $this->addProperty('must_not', Query::create($mustNot)->multi(true)); - } - - /** - * Append a must_not clause. Supports multiple calls to incrementally build the bool query. - * - * @param mixed $mustNot - * @return static - */ - public function addMustNot($mustNot) - { - return $this->pushClause('must_not', $mustNot); + return $this->addClause('must_not', $mustNot); } /** diff --git a/src/DSL/Queries/Compound/DisjunctionMax.php b/src/DSL/Queries/Compound/DisjunctionMax.php index 520cc02..a1bbe34 100644 --- a/src/DSL/Queries/Compound/DisjunctionMax.php +++ b/src/DSL/Queries/Compound/DisjunctionMax.php @@ -4,7 +4,6 @@ use ElasticKit\DSL\Shared\ClausesSupport; use ElasticKit\DSL\Node; -use ElasticKit\DSL\Query; /** * Returns documents matching one or more wrapped queries, called query clauses or clauses. @@ -17,24 +16,14 @@ class DisjunctionMax extends Node /** * Contains one or more query clauses. Returned documents must match one or more of these queries. If a document matches multiple queries, Elasticsearch uses the highest relevance score. + * Supports multiple calls to incrementally build. * * @param mixed $queries * @return static */ public function queries($queries) { - return $this->addProperty('queries', Query::create($queries)->multi(true)); - } - - /** - * Append a query clause. Supports multiple calls to incrementally build. - * - * @param mixed $query - * @return static - */ - public function addQuery($query) - { - return $this->pushClause('queries', $query); + return $this->addClause('queries', $queries); } /** diff --git a/src/DSL/Queries/Span/SpanNear.php b/src/DSL/Queries/Span/SpanNear.php index c5a5ce6..aec40fc 100644 --- a/src/DSL/Queries/Span/SpanNear.php +++ b/src/DSL/Queries/Span/SpanNear.php @@ -4,7 +4,6 @@ use ElasticKit\DSL\Shared\ClausesSupport; use ElasticKit\DSL\Node; -use ElasticKit\DSL\Query; /** * Matches spans that are near each other, with configurable slop and ordering. @@ -17,24 +16,14 @@ class SpanNear extends Node /** * The list of span query clauses that must appear near each other. + * Supports multiple calls to incrementally build. * * @param mixed $clauses * @return static */ public function clauses($clauses) { - return $this->addProperty('clauses', Query::create($clauses)->multi(true)); - } - - /** - * Append a span query clause. Supports multiple calls to incrementally build. - * - * @param mixed $clause - * @return static - */ - public function addClause($clause) - { - return $this->pushClause('clauses', $clause); + return $this->addClause('clauses', $clauses); } /** diff --git a/src/DSL/Queries/Span/SpanOr.php b/src/DSL/Queries/Span/SpanOr.php index df9a3c9..840aa73 100644 --- a/src/DSL/Queries/Span/SpanOr.php +++ b/src/DSL/Queries/Span/SpanOr.php @@ -4,7 +4,6 @@ use ElasticKit\DSL\Shared\ClausesSupport; use ElasticKit\DSL\Node; -use ElasticKit\DSL\Query; /** * Matches the union of multiple span queries, combining their results. @@ -17,23 +16,13 @@ class SpanOr extends Node /** * The list of span query clauses to combine. + * Supports multiple calls to incrementally build. * * @param mixed $clauses * @return static */ public function clauses($clauses) { - return $this->addProperty('clauses', Query::create($clauses)->multi(true)); - } - - /** - * Append a span query clause. Supports multiple calls to incrementally build. - * - * @param mixed $clause - * @return static - */ - public function addClause($clause) - { - return $this->pushClause('clauses', $clause); + return $this->addClause('clauses', $clauses); } } diff --git a/src/DSL/Query.php b/src/DSL/Query.php index 30acc37..45975f6 100644 --- a/src/DSL/Query.php +++ b/src/DSL/Query.php @@ -48,7 +48,7 @@ class Query extends Node * * @var array */ - protected $_queryClauses = []; + protected $_queries = []; /** * Aggregation nodes stored independently from type properties. @@ -101,18 +101,28 @@ public function __construct($field = null, $value = null) if ($field instanceof Closure) { $field($this); } elseif ($field instanceof Node) { - $this->_queryClauses[] = $field; + $this->_queries[] = $field; } elseif (is_array($field)) { if (array_key_exists('query', $field)) { $this->_properties = $field; } else { - $this->_queryClauses[] = $field; + $this->_queries[] = $field; } } elseif ($field !== null) { $this->_properties = $field; } } + /** + * Get all query clauses. + * + * @return array + */ + public function getQueries() + { + return $this->_queries; + } + /** * Add a query clause to the query container. * @@ -121,7 +131,7 @@ public function __construct($field = null, $value = null) */ public function addQuery($query) { - $this->_queryClauses[] = $query; + $this->_queries[] = $query; return $this; } @@ -234,17 +244,25 @@ public function toArray() */ private function buildQuery() { - if (empty($this->_queryClauses)) { + if (empty($this->_queries)) { return $this->_multi ? (object)[] : []; } - $clauses = []; - foreach ($this->_queryClauses as $query) { - if ($query instanceof Query) { - foreach ($query->toArray()['query'] as $field => $item) { - $clauses[] = [$field => $item]; + // Flatten nested Query instances + $flat = []; + foreach ($this->_queries as $item) { + if ($item instanceof self) { + foreach ($item->getQueries() as $clause) { + $flat[] = $clause; } - } elseif ($query instanceof Node) { + } else { + $flat[] = $item; + } + } + + $clauses = []; + foreach ($flat as $query) { + if ($query instanceof Node) { $clauses[] = [$query->key() => $query->toArray()]; } elseif (is_array($query)) { foreach ($query as $field => $item) { diff --git a/src/DSL/Shared/ClausesSupport.php b/src/DSL/Shared/ClausesSupport.php index d543853..ec2224b 100644 --- a/src/DSL/Shared/ClausesSupport.php +++ b/src/DSL/Shared/ClausesSupport.php @@ -6,64 +6,31 @@ use ElasticKit\DSL\Query; /** - * Provides deferred clause merging for compound query nodes. + * Provides clause accumulation for compound query nodes. * - * Accumulates clauses added via pushClause() method, - * then merges them into _properties during serialization. + * Each clause key holds a Query(multi=true) instance. + * Closures receive the same Query object across calls. */ trait ClausesSupport { /** - * Clauses keyed by property name, merged at serialization time. - * - * @var array> - */ - protected $_clauses = []; - - /** - * Push a clause for the given property. + * Append a clause for the given property. * * @param string $key Property name (e.g. 'must', 'clauses', 'queries') * @param mixed $clause * @return static */ - protected function pushClause(string $key, $clause) + protected function addClause(string $key, $clause) { - $this->_clauses[$key][] = $clause; - return $this; - } - - /** - * Serialize to array, merging clauses into the final output. - * - * @return array - */ - public function toArray() - { - $this->mergeClauses(); - return parent::toArray(); - } - - /** - * Merge clauses into _properties, adding each clause - * directly to the target container's clause list. - * - * @return void - */ - private function mergeClauses() - { - foreach ($this->_clauses as $key => $clauses) { - if (!isset($this->_properties[$key])) { - $this->_properties[$key] = (new Query())->multi(true); - } - $target = $this->_properties[$key]; - if ($target instanceof Query) { - foreach ($clauses as $clause) { - $resolved = ($clause instanceof Closure) ? Query::create($clause) : $clause; - $target->addQuery($resolved); - } - } + if (!isset($this->_properties[$key])) { + $this->_properties[$key] = (new Query())->multi(true); } - $this->_clauses = []; + $target = $this->_properties[$key]; + if ($clause instanceof Closure) { + $clause($target); + } else { + $target->addQuery($clause); + } + return $this; } } diff --git a/tests/CompoundQueriesTest.php b/tests/CompoundQueriesTest.php index d65a4ec..65907fd 100644 --- a/tests/CompoundQueriesTest.php +++ b/tests/CompoundQueriesTest.php @@ -585,8 +585,8 @@ public function testBoolAddMustWithNode() { $query = new Query(); $query->bool(function (Boolean $b) { - $b->addMust(new \ElasticKit\DSL\Queries\FullText\Match_('title', 'test')); - $b->addFilter(new \ElasticKit\DSL\Queries\TermLevel\Term('status', 'published')); + $b->must(new \ElasticKit\DSL\Queries\FullText\Match_('title', 'test')); + $b->filter(new \ElasticKit\DSL\Queries\TermLevel\Term('status', 'published')); }); $expectedJson = << 'nike', 'color' => 'red']; $query = new Query(); $query->bool(function (Boolean $b) use ($filters) { - $b->addMust(function (Query $q) { + $b->must(function (Query $q) { $q->match('title', 'shoes'); }); foreach ($filters as $field => $value) { - $b->addFilter(new \ElasticKit\DSL\Queries\TermLevel\Term($field, $value)); + $b->filter(new \ElasticKit\DSL\Queries\TermLevel\Term($field, $value)); } }); $expectedJson = <<disMax(function (DisjunctionMax $dm) { - $dm->addQuery(function (Query $q) { + $dm->queries(function (Query $q) { $q->term('title', 'Quick pets'); }); - $dm->addQuery(function (Query $q) { + $dm->queries(function (Query $q) { $q->term('body', 'Quick pets'); }); $dm->tieBreaker(0.7); diff --git a/tests/SpanQueriesTest.php b/tests/SpanQueriesTest.php index bf22d03..3fd9b00 100644 --- a/tests/SpanQueriesTest.php +++ b/tests/SpanQueriesTest.php @@ -312,10 +312,10 @@ public function testSpanOrAddClause() JSON; $query = new Query(); $query->spanOr(function (SpanOr $spanOr) { - $spanOr->addClause(function (Query $q) { + $spanOr->clauses(function (Query $q) { $q->spanTerm('field1', 'bar'); }); - $spanOr->addClause(function (Query $q) { + $spanOr->clauses(function (Query $q) { $q->spanTerm('field2', 'baz'); }); }); @@ -340,10 +340,10 @@ public function testSpanNearAddClause() JSON; $query = new Query(); $query->spanNear(function (SpanNear $spanNear) { - $spanNear->addClause(function (Query $q) { + $spanNear->clauses(function (Query $q) { $q->spanTerm('field1', 'bar'); }); - $spanNear->addClause(function (Query $q) { + $spanNear->clauses(function (Query $q) { $q->spanTerm('field2', 'baz'); }); $spanNear->slop(5)->inOrder(true); From 94cff98c2135d6c03342b5d01231c34ed2ff4e45 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 19:54:51 +0800 Subject: [PATCH 04/24] =?UTF-8?q?fix(index):=20=E6=96=B0=E5=A2=9E=20totalR?= =?UTF-8?q?elation()=EF=BC=8Caggregations()=20=E8=BF=94=E5=9B=9E=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 totalRelation() 直接映射 hits.total.relation - aggregations() 缺省返回 null 替代空数组,语义更准确 - hasMore() 确认无 bug,scroll 场景 !empty(hits) 正确 Co-Authored-By: Claude --- CLAUDE.md | 2 +- src/Index/Results.php | 20 ++++- tests/Index/ResultsTest.php | 168 ++++++++++++++++++------------------ 3 files changed, 99 insertions(+), 91 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a3e419c..43450b6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -40,7 +40,7 @@ PSR-5 规范。 - [x] **clone query 后 try-finally 恢复**:first() / paginate() 等方法 clone query 后修改状态,需 try-finally 确保恢复 - [x] **ClausesSupport API 统一**:must()/should()/filter() 等改为追加语义,移除 addXXX() 方法 -- [ ] **hasMore() 判断逻辑修复**:待确认(看代码) +- [x] **hasMore() 确认无 bug**:scroll 场景 !empty(hits) 正确,分页应用 page() + * @return array|null */ public function aggregations() { - return $this->response['aggregations'] ?? []; + return $this->response['aggregations'] ?? null; } /** @@ -124,7 +124,19 @@ public function scrollId() } /** - * Return whether there are more hits available. + * Return the hits.total.relation value from the Elasticsearch response. + * + * "eq" = total is exact, "gte" = total is a lower bound. + * + * @return string "eq" or "gte" + */ + public function totalRelation() + { + return $this->response['hits']['total']['relation']; + } + + /** + * Return whether the current batch contains hits. * * @return bool */ diff --git a/tests/Index/ResultsTest.php b/tests/Index/ResultsTest.php index 76fb5d5..73cc39a 100644 --- a/tests/Index/ResultsTest.php +++ b/tests/Index/ResultsTest.php @@ -6,21 +6,25 @@ class ResultsTest extends TestCase { - public function testTotal() + private function makeResponse(array $overrides = []): array { - $results = new Results([ + return array_merge([ 'hits' => [ - 'total' => ['value' => 42], + 'total' => ['value' => 0, 'relation' => 'eq'], 'hits' => [], ], - ]); - $this->assertEquals(42, $results->total()); + ], $overrides); } - public function testTotalDefaultsToZero() + public function testTotal() { - $results = new Results([]); - $this->assertEquals(0, $results->total()); + $results = new Results($this->makeResponse([ + 'hits' => [ + 'total' => ['value' => 42, 'relation' => 'eq'], + 'hits' => [], + ], + ])); + $this->assertEquals(42, $results->total()); } public function testHits() @@ -29,103 +33,108 @@ public function testHits() ['_id' => '1', '_source' => ['title' => 'foo']], ['_id' => '2', '_source' => ['title' => 'bar']], ]; - $results = new Results([ - 'hits' => ['total' => ['value' => 2], 'hits' => $hits], - ]); + $results = new Results($this->makeResponse([ + 'hits' => [ + 'total' => ['value' => 2, 'relation' => 'eq'], + 'hits' => $hits, + ], + ])); $this->assertEquals($hits, $results->hits()); } - public function testHitsDefaultsToEmpty() - { - $results = new Results([]); - $this->assertEquals([], $results->hits()); - } - public function testDocs() { - $results = new Results([ + $results = new Results($this->makeResponse([ 'hits' => [ - 'total' => ['value' => 2], + 'total' => ['value' => 2, 'relation' => 'eq'], 'hits' => [ ['_id' => '1', '_source' => ['title' => 'foo']], ['_id' => '2', '_source' => ['title' => 'bar']], ], ], - ]); + ])); $this->assertEquals([['title' => 'foo'], ['title' => 'bar']], $results->docs()); } - public function testDocsDefaultsToEmpty() - { - $results = new Results([]); - $this->assertEquals([], $results->docs()); - } - public function testAggregations() { $aggs = ['price_avg' => ['value' => 100.5]]; - $results = new Results([ - 'hits' => ['total' => ['value' => 0], 'hits' => []], - 'aggregations' => $aggs, - ]); + $results = new Results($this->makeResponse(['aggregations' => $aggs])); $this->assertEquals($aggs, $results->aggregations()); } - public function testAggregationsDefaultsToEmpty() + public function testAggregationsReturnsNullWhenAbsent() { - $results = new Results(['hits' => []]); - $this->assertEquals([], $results->aggregations()); + $results = new Results($this->makeResponse()); + $this->assertNull($results->aggregations()); } public function testScrollId() { - $results = new Results([ - '_scroll_id' => 'abc123', - 'hits' => ['total' => ['value' => 0], 'hits' => []], - ]); + $results = new Results($this->makeResponse(['_scroll_id' => 'abc123'])); $this->assertEquals('abc123', $results->scrollId()); } - public function testScrollIdDefaultsToNull() + public function testScrollIdReturnsNullWhenAbsent() { - $results = new Results([]); + $results = new Results($this->makeResponse()); $this->assertNull($results->scrollId()); } - public function testHasMore() + public function testHasMoreScrollWithHits() { - $results = new Results([ + $results = new Results($this->makeResponse([ 'hits' => [ - 'total' => ['value' => 1], + 'total' => ['value' => 1, 'relation' => 'eq'], 'hits' => [['_source' => ['title' => 'foo']]], ], - ]); + ])); $this->assertTrue($results->hasMore()); } - public function testHasMoreReturnsFalseWhenEmpty() + public function testHasMoreScrollEmpty() { - $results = new Results([ - 'hits' => ['total' => ['value' => 0], 'hits' => []], - ]); + $results = new Results($this->makeResponse()); $this->assertFalse($results->hasMore()); } + public function testTotalRelationEq() + { + $results = new Results($this->makeResponse([ + 'hits' => [ + 'total' => ['value' => 42, 'relation' => 'eq'], + 'hits' => [], + ], + ])); + $this->assertEquals('eq', $results->totalRelation()); + } + + public function testTotalRelationGte() + { + $results = new Results($this->makeResponse([ + 'hits' => [ + 'total' => ['value' => 10000, 'relation' => 'gte'], + 'hits' => [], + ], + ])); + $this->assertEquals('gte', $results->totalRelation()); + } + public function testRaw() { - $response = [ - 'took' => 5, - 'hits' => ['total' => ['value' => 1], 'hits' => []], - ]; + $response = $this->makeResponse(['took' => 5]); $results = new Results($response); $this->assertEquals($response, $results->raw()); } public function testPaginateSetsMetadata() { - $results = new Results([ - 'hits' => ['total' => ['value' => 50], 'hits' => []], - ]); + $results = new Results($this->makeResponse([ + 'hits' => [ + 'total' => ['value' => 50, 'relation' => 'eq'], + 'hits' => [], + ], + ])); $results->paginate(3, 10); $this->assertEquals(3, $results->page()); @@ -135,9 +144,7 @@ public function testPaginateSetsMetadata() public function testLastPageMinimumIsOne() { - $results = new Results([ - 'hits' => ['total' => ['value' => 0], 'hits' => []], - ]); + $results = new Results($this->makeResponse()); $results->paginate(1, 15); $this->assertEquals(1, $results->lastPage()); @@ -145,31 +152,29 @@ public function testLastPageMinimumIsOne() public function testItemsReturnsDocs() { - $results = new Results([ + $results = new Results($this->makeResponse([ 'hits' => [ - 'total' => ['value' => 2], + 'total' => ['value' => 2, 'relation' => 'eq'], 'hits' => [ ['_id' => '1', '_source' => ['title' => 'foo']], ['_id' => '2', '_source' => ['title' => 'bar']], ], ], - ]); + ])); $this->assertEquals($results->docs(), $results->items()); } public function testIsEmpty() { - $results = new Results([ - 'hits' => ['total' => ['value' => 0], 'hits' => []], - ]); + $results = new Results($this->makeResponse()); $this->assertTrue($results->isEmpty()); - $results = new Results([ + $results = new Results($this->makeResponse([ 'hits' => [ - 'total' => ['value' => 1], + 'total' => ['value' => 1, 'relation' => 'eq'], 'hits' => [['_source' => ['title' => 'foo']]], ], - ]); + ])); $this->assertFalse($results->isEmpty()); } @@ -179,9 +184,12 @@ public function testToPaginatorCallsResolver() return ['total' => $results->total(), 'page' => $results->page()]; }); - $results = new Results([ - 'hits' => ['total' => ['value' => 50], 'hits' => []], - ]); + $results = new Results($this->makeResponse([ + 'hits' => [ + 'total' => ['value' => 50, 'relation' => 'eq'], + 'hits' => [], + ], + ])); $results->paginate(2, 10); $paginator = $results->toPaginator(); @@ -195,38 +203,26 @@ public function testToPaginatorCallsResolver() public function testToPaginatorThrowsWithoutResolver() { - $results = new Results(['hits' => []]); + $results = new Results($this->makeResponse()); $this->expectException(\RuntimeException::class); $results->toPaginator(); } public function testTook() { - $results = new Results([ - 'took' => 5, - 'hits' => ['total' => ['value' => 1], 'hits' => []], - ]); + $results = new Results($this->makeResponse(['took' => 5])); $this->assertEquals(5, $results->took()); } - public function testTookDefaultsToZero() - { - $results = new Results([]); - $this->assertEquals(0, $results->took()); - } - public function testTimedOut() { - $results = new Results([ - 'timed_out' => true, - 'hits' => ['total' => ['value' => 0], 'hits' => []], - ]); + $results = new Results($this->makeResponse(['timed_out' => true])); $this->assertTrue($results->timedOut()); } - public function testTimedOutDefaultsToFalse() + public function testTimedOutFalse() { - $results = new Results([]); + $results = new Results($this->makeResponse(['timed_out' => false])); $this->assertFalse($results->timedOut()); } } From f956cab02c9d9da3120e9e24330473fc14eb8f00 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 20:04:15 +0800 Subject: [PATCH 05/24] =?UTF-8?q?fix(index):=20Rebuild::rollback()=20?= =?UTF-8?q?=E9=81=8D=E5=8E=86=E5=85=A8=E9=83=A8=E5=88=AB=E5=90=8D=EF=BC=8C?= =?UTF-8?q?Index::name()=20=E7=A9=BA=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rollback() 移除所有 backing index 的别名,对齐 doRun() 写法 - name() 在子类未设置 $name 时抛出异常 Co-Authored-By: Claude --- src/Index/Index.php | 6 ++++++ src/Index/Rebuild.php | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Index/Index.php b/src/Index/Index.php index 6d93164..75f4b52 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -102,6 +102,12 @@ public function getClient() */ public function name() { + if (empty($this->name)) { + throw new RuntimeException( + sprintf('Index $name is not set in %s', static::class) + ); + } + return $this->name; } diff --git a/src/Index/Rebuild.php b/src/Index/Rebuild.php index e8b130e..101e195 100644 --- a/src/Index/Rebuild.php +++ b/src/Index/Rebuild.php @@ -186,12 +186,15 @@ public function rollback(string $targetIndex): string throw new RuntimeException("Target index [{$targetIndex}] does not exist"); } + $actions = []; + foreach ($currentList as $idx) { + $actions[] = ['remove' => ['index' => $idx, 'alias' => $name]]; + } + $actions[] = ['add' => ['index' => $targetIndex, 'alias' => $name]]; + $client->updateAliases([ 'body' => [ - 'actions' => [ - ['remove' => ['index' => $currentList[0], 'alias' => $name]], - ['add' => ['index' => $targetIndex, 'alias' => $name]], - ], + 'actions' => $actions, ], ]); From 4de6a7ce935486deaaf78d717651513bc1004481 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 20:24:15 +0800 Subject: [PATCH 06/24] =?UTF-8?q?refactor(dsl):=20Node/Query=20=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=87=BD=E6=95=B0=E6=8B=86=E5=88=86=E4=B8=BA=20from*?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=BE=85?= =?UTF-8?q?=E5=8A=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Node: 提取 fromKeyValue/fromClosure/fromArrayField/fromScalar - Query: 复用 fromClosure,新增 fromArray 处理 query key - 构造函数变为清晰的路由表,每个方法只处理一种输入形式 - 更新 CLAUDE.md 待办完成状态 Co-Authored-By: Claude --- CLAUDE.md | 6 ++-- src/DSL/Node.php | 92 +++++++++++++++++++++++++++++++++-------------- src/DSL/Query.php | 26 ++++++++++---- 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 43450b6..73f650e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -41,11 +41,11 @@ PSR-5 规范。 - [x] **clone query 后 try-finally 恢复**:first() / paginate() 等方法 clone query 后修改状态,需 try-finally 确保恢复 - [x] **ClausesSupport API 统一**:must()/should()/filter() 等改为追加语义,移除 addXXX() 方法 - [x] **hasMore() 确认无 bug**:scroll 场景 !empty(hits) 正确,分页应用 page()_rawValue = $value; - $this->_properties = []; - } else { - $this->_properties = $value; - } - if ($this->_isPropertyField) { - $this->field($field); - } + $this->fromKeyValue($field, $value); } elseif ($field instanceof Closure) { - // Single-arg closure - $field($this); + $this->fromClosure($field); } elseif ($this->_isPropertyField && is_array($field)) { - // Array shorthand: ['field_name' => value] - foreach ($field as $key => $val) { - $this->field($key); - if (is_scalar($val)) { - $this->_rawValue = $val; - $this->_properties = []; - } else { - $this->_properties = $val; - } - break; - } + $this->fromArrayField($field); } elseif ($this->_isPropertyField && is_scalar($field)) { - $this->_rawValue = $field; - $this->_properties = []; + $this->fromScalar($field); } else { $this->_properties = $field; } } + /** + * Initialize from a field-value pair. + * + * @param mixed $field + * @param mixed $value + */ + protected function fromKeyValue($field, $value): void + { + if ($value instanceof Closure) { + $value($this); + } elseif (is_scalar($value)) { + $this->_rawValue = $value; + $this->_properties = []; + } else { + $this->_properties = $value; + } + if ($this->_isPropertyField) { + $this->field($field); + } + } + + /** + * Initialize from a closure. + * + * @param Closure $closure + */ + protected function fromClosure(Closure $closure): void + { + $closure($this); + } + + /** + * Initialize from a single-element array where key is field name. + * + * @param array $field + */ + protected function fromArrayField(array $field): void + { + foreach ($field as $key => $val) { + $this->field($key); + if (is_scalar($val)) { + $this->_rawValue = $val; + $this->_properties = []; + } else { + $this->_properties = $val; + } + break; + } + } + + /** + * Initialize from a scalar value. + * + * @param mixed $value + */ + protected function fromScalar($value): void + { + $this->_rawValue = $value; + $this->_properties = []; + } + /** * Set whether this node uses a field name as the top-level attribute. * diff --git a/src/DSL/Query.php b/src/DSL/Query.php index 45975f6..93d41db 100644 --- a/src/DSL/Query.php +++ b/src/DSL/Query.php @@ -19,6 +19,7 @@ * Query container that combines multiple query conditions into an Elasticsearch DSL query. * * @phpstan-consistent-constructor + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class Query extends Node { @@ -99,20 +100,33 @@ public function __construct($field = null, $value = null) return; } if ($field instanceof Closure) { - $field($this); + $this->fromClosure($field); } elseif ($field instanceof Node) { $this->_queries[] = $field; } elseif (is_array($field)) { - if (array_key_exists('query', $field)) { - $this->_properties = $field; - } else { - $this->_queries[] = $field; - } + $this->fromArray($field); } elseif ($field !== null) { $this->_properties = $field; } } + /** + * Initialize from a raw ES body array. + * + * Arrays with a 'query' key are stored as-is (raw DSL). + * Other arrays are added as query clauses. + * + * @param array $field + */ + protected function fromArray(array $field): void + { + if (array_key_exists('query', $field)) { + $this->_properties = $field; + } else { + $this->_queries[] = $field; + } + } + /** * Get all query clauses. * From ed988b7baf09ea227e48fe3849062d1736bf6cc1 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 21:55:42 +0800 Subject: [PATCH 07/24] =?UTF-8?q?feat(index):=20Bulk/Rebuild=20onError=20?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=20skipErrors=EF=BC=8C=E5=88=A0=20rebuild.imp?= =?UTF-8?q?ort.failed=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bulk 新增 onError(callable),execute() 默认 throw on errors - Rebuild 删 skipErrors,新增 onError(callable),内部委托给 Bulk - 删 rebuild.import.failed 事件,错误处理统一走 onError 回调 - batchSize auto-flush 的错误也通过 onError 捕获,不再丢失 - 更新文档和待办 Co-Authored-By: Claude --- CLAUDE.md | 4 +- docs/index.md | 33 +++++++++++---- src/Index/Bulk.php | 34 ++++++++++++++++ src/Index/Rebuild.php | 36 +++++++---------- tests/Index/BulkTest.php | 81 +++++++++++++++++++++++++++++++++++++ tests/Index/RebuildTest.php | 81 +++++++++++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+), 29 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 73f650e..3833668 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -46,7 +46,7 @@ PSR-5 规范。 - [ ] **锁抽取为独立类**:通用分布式锁(acquire/release/forceUnlock/isLocked + ensureLockIndex),Bulk 等可复用 - [ ] **$client 抽到 Registry 类**:新建 Registry 持有 client / pageResolver / paginatorResolver / listeners,Index 不再持有静态状态。旧 API 保留作 deprecated 代理,前期统一放 Registry,后续按需拆分 - [x] **Node 构造函数重构**:拆分为 fromKeyValue/fromClosure/fromArrayField/fromScalar -- [ ] **Bulk skipErrors() 设计**:参考 Rebuild 的 skipErrors 模式 +- [x] **Bulk/Rebuild onError 设计**:Bulk 加 onError(callback) 默认 throw,Rebuild 删 skipErrors 加 onError,删 rebuild.import.failed 事件 - [ ] **补核心路径的边界测试**:scroll、bulk 分批、rebuild 失败回滚 - [ ] **搭建集成测试基建**:`ELASTICKIT_TEST_HOST` 驱动,随机索引名隔离 @@ -61,6 +61,8 @@ PSR-5 规范。 | `PROXY_PORT` | HTTP 代理端口(推送用) | | `ELASTICKIT_TEST_HOST` | ES 集成测试地址(如 `https://localhost:9200`),不设置则跳过集成测试 | +## 推送代码前需要执行4件套 + ```bash docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpunit --testsuite unit" docker exec $PHP_CONTAINER sh -c "cd $PROJECT_PATH && vendor/bin/phpunit --testsuite index" diff --git a/docs/index.md b/docs/index.md index 996048e..67c38c0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -164,6 +164,28 @@ $bulk->delete(3); $bulk->execute(); // 执行所有操作,执行后清空状态 ``` +### 错误处理 + +`execute()` 默认在响应包含错误时抛出 `RuntimeException`。使用 `onError()` 自定义处理。回调接收 ES 原始响应,不抛出则继续,抛出则中断: + +```php +$bulk = new Bulk(new ProductIndex()); + +// 不设 onError → 有错误就抛异常 +$bulk->execute(); + +// 设 onError → 回调内不抛则继续,抛则中断 +$bulk->onError(function (array $response) { + $failures = count(array_filter($response['items'], fn($i) => isset($i['index']['error']))); + if ($failures > 100) { + throw new RuntimeException("失败超过阈值: {$failures}"); + } + Log::warning("部分失败: {$failures} 条"); +})->execute(); +``` + +> `batchSize` 自动 flush 时的错误同样走 `onError`,不会丢失。 + ## 零停机重建 创建新索引 → 导入数据 → 切换别名。 @@ -242,14 +264,12 @@ $rebuild->run(['after' => '2024-01-01']); ### 错误处理 -导入错误会触发 `rebuild.import.failed` 事件(始终),并抛出异常(默认)。使用 `skipErrors()` 抑制异常但保留事件通知: +Rebuild 内部使用 Bulk 执行导入,`onError()` 用法与 [批量操作 > 错误处理](#错误处理) 一致: ```php -Index::listen('rebuild.import.failed', function (Event $e) { - Log::warning("重建导入错误", $e->response); -}); - -$rebuild->skipErrors()->run(); // 通过事件记录错误,不中断 +$rebuild->onError(function (array $response) { + Log::warning("重建导入错误", $response); +})->run(); ``` > rebuild 期间 DB 仍在变更,新索引是开始时刻的快照,建议 rebuild 后通过 `updated_at` 增量同步补齐。 @@ -351,4 +371,3 @@ Index::setClient($client); | `manager.swap_alias.after` | `$response` | | `rebuild.run.before` | | | `rebuild.run.after` | `$newIndex`, `$oldIndex` | -| `rebuild.import.failed` | `$response` | diff --git a/src/Index/Bulk.php b/src/Index/Bulk.php index 2ab5c3b..8f2336e 100644 --- a/src/Index/Bulk.php +++ b/src/Index/Bulk.php @@ -3,6 +3,7 @@ namespace ElasticKit\Index; use InvalidArgumentException; +use RuntimeException; /** * Batch document operations using the ES _bulk API. @@ -39,6 +40,11 @@ class Bulk */ private $docCount = 0; + /** + * @var callable|null + */ + private $errorHandler = null; + /** * @param Index $index */ @@ -78,6 +84,22 @@ public function batchSize($size) return $this; } + /** + * Set a callback to handle bulk errors. + * + * The callback receives the raw ES response. To continue execution, simply + * return without throwing. To abort, throw an exception from the callback. + * Without an error handler, execute() throws RuntimeException on errors. + * + * @param callable $handler function (array $response): void + * @return $this + */ + public function onError($handler) + { + $this->errorHandler = $handler; + return $this; + } + /** * Set retry_on_conflict for all update actions in this batch. * @@ -213,6 +235,18 @@ public function execute(array $options = []) $e->duration = $duration; Index::dispatch($e); + if (!empty($response['errors'])) { + if ($this->errorHandler) { + ($this->errorHandler)($response); + } else { + $json = json_encode($response, JSON_UNESCAPED_UNICODE); + if (strlen($json) > 4096) { + $json = substr($json, 0, 4096) . '... [truncated]'; + } + throw new RuntimeException("Bulk request has errors: {$json}"); + } + } + return $response; } diff --git a/src/Index/Rebuild.php b/src/Index/Rebuild.php index 101e195..7d21f56 100644 --- a/src/Index/Rebuild.php +++ b/src/Index/Rebuild.php @@ -30,9 +30,9 @@ class Rebuild private $batchSize = 1000; /** - * @var bool + * @var callable|null */ - private $skipErrors = false; + private $errorHandler = null; /** * @var bool @@ -65,14 +65,18 @@ public function batchSize($size) } /** - * Skip bulk import errors instead of throwing. Defaults to false. + * Set a callback to handle bulk import errors. + * + * The callback receives the raw ES response. To continue the rebuild, simply + * return without throwing. To abort, throw an exception from the callback. + * Without an error handler, import errors cause the rebuild to abort. * - * @param bool $skip + * @param callable $handler function (array $response): void * @return $this */ - public function skipErrors($skip = true) + public function onError($handler) { - $this->skipErrors = $skip; + $this->errorHandler = $handler; return $this; } @@ -372,6 +376,10 @@ protected function import($newName, array $context): void } $bulk = (new Bulk($this->index))->target($newName)->batchSize($this->batchSize); + if ($this->errorHandler) { + $bulk->onError($this->errorHandler); + } + $count = 0; foreach ($items as $id => $doc) { if (!is_array($doc)) { @@ -391,20 +399,6 @@ protected function import($newName, array $context): void ); } - $response = $bulk->execute(); - - if (!empty($response['errors'])) { - $e = new Event('rebuild.import.failed', $this->index->name()); - $e->response = $response; - Index::dispatch($e); - - if (!$this->skipErrors) { - $json = json_encode($response, JSON_UNESCAPED_UNICODE); - if (strlen($json) > 4096) { - $json = substr($json, 0, 4096) . '... [truncated]'; - } - throw new RuntimeException("Bulk import failed for index [{$newName}]: {$json}"); - } - } + $bulk->execute(); } } diff --git a/tests/Index/BulkTest.php b/tests/Index/BulkTest.php index ee2f9c6..90539a8 100644 --- a/tests/Index/BulkTest.php +++ b/tests/Index/BulkTest.php @@ -269,4 +269,85 @@ public function testExecuteReturnsEmptyWhenBodyIsEmpty() $this->assertEquals([], $result); } + + public function testExecuteThrowsOnErrors() + { + $client = $this->createMock(TestClient::class); + $client->method('bulk')->willReturn(new ArrayResponse([ + 'errors' => true, + 'items' => [ + ['index' => ['_id' => '1', 'status' => 400, 'error' => ['type' => 'mapper_parsing_exception']]], + ], + ])); + Index::setClient($client); + + $index = $this->createIndex('products'); + $this->expectException(\RuntimeException::class); + (new Bulk($index))->index('1', ['title' => 'foo'])->execute(); + } + + public function testExecuteCallsOnError() + { + $client = $this->createMock(TestClient::class); + $errorResponse = [ + 'errors' => true, + 'items' => [ + ['index' => ['_id' => '1', 'status' => 400, 'error' => ['type' => 'mapper_parsing_exception']]], + ], + ]; + $client->method('bulk')->willReturn(new ArrayResponse($errorResponse)); + Index::setClient($client); + + $received = null; + $index = $this->createIndex('products'); + (new Bulk($index)) + ->onError(function ($response) use (&$received) { + $received = $response; + }) + ->index('1', ['title' => 'foo']) + ->execute(); + + $this->assertEquals($errorResponse, $received); + } + + public function testAutoFlushCallsOnError() + { + $errorResponse = [ + 'errors' => true, + 'items' => [ + ['index' => ['_id' => '1', 'status' => 400, 'error' => ['type' => 'mapper_parsing_exception']]], + ], + ]; + $client = $this->createMock(TestClient::class); + $client->method('bulk')->willReturn(new ArrayResponse($errorResponse)); + Index::setClient($client); + + $received = null; + $index = $this->createIndex('products'); + $bulk = (new Bulk($index)) + ->batchSize(1) + ->onError(function ($response) use (&$received) { + $received = $response; + }); + + $bulk->index('1', ['title' => 'foo']); // triggers auto-flush + + $this->assertEquals($errorResponse, $received); + } + + public function testAutoFlushThrowsOnErrorsWithoutHandler() + { + $client = $this->createMock(TestClient::class); + $client->method('bulk')->willReturn(new ArrayResponse([ + 'errors' => true, + 'items' => [], + ])); + Index::setClient($client); + + $index = $this->createIndex('products'); + $bulk = (new Bulk($index))->batchSize(1); + + $this->expectException(\RuntimeException::class); + $bulk->index('1', ['title' => 'foo']); // auto-flush throws + } } diff --git a/tests/Index/RebuildTest.php b/tests/Index/RebuildTest.php index 97b18b2..2dd1abf 100644 --- a/tests/Index/RebuildTest.php +++ b/tests/Index/RebuildTest.php @@ -636,4 +636,85 @@ public function source(array $context = []): iterable (new Rebuild($index))->allowEmpty()->run(); } + + public function testOnErrorReceivesResponse() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('existsAlias')->willReturn(new BoolResponse(false)); + $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $errorResponse = [ + 'errors' => true, + 'items' => [ + ['index' => ['_id' => '1', 'status' => 400, 'error' => ['type' => 'mapper_parsing_exception']]], + ], + ]; + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); + $client->method('bulk')->willReturn(new ArrayResponse($errorResponse)); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + yield 1 => ['title' => 'A']; + } + }; + + $received = null; + (new Rebuild($index)) + ->onError(function ($response) use (&$received) { + $received = $response; + }) + ->run(); + + $this->assertEquals($errorResponse, $received); + } + + public function testOnErrorPreventsException() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(false)); + $indices->method('existsAlias')->willReturn(new BoolResponse(false)); + $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + $client->method('delete')->willReturn(new ArrayResponse(['result' => 'deleted'])); + $client->method('bulk')->willReturn(new ArrayResponse([ + 'errors' => true, + 'items' => [], + ])); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + yield 1 => ['title' => 'A']; + } + }; + + // Without onError, would throw. With onError (empty callback), completes successfully. + $result = (new Rebuild($index)) + ->onError(function () {}) + ->run(); + + $this->assertStringStartsWith('products_', $result['newIndex']); + } } From 56b1672cf27661f062dbe15881638114fe2c374f Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 22:52:09 +0800 Subject: [PATCH 08/24] =?UTF-8?q?refactor(index):=20AggregationShortcut=20?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BA=20StatsSupport=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20stats()=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Index/Search.php | 2 +- ...gregationShortcut.php => StatsSupport.php} | 34 ++++++++- ...nShortcutTest.php => StatsSupportTest.php} | 71 +++++++++++++++++-- 3 files changed, 101 insertions(+), 6 deletions(-) rename src/Index/{AggregationShortcut.php => StatsSupport.php} (61%) rename tests/Index/{AggregationShortcutTest.php => StatsSupportTest.php} (62%) diff --git a/src/Index/Search.php b/src/Index/Search.php index 344857f..2152981 100644 --- a/src/Index/Search.php +++ b/src/Index/Search.php @@ -14,7 +14,7 @@ */ class Search { - use AggregationShortcut; + use StatsSupport; /** * @var Query diff --git a/src/Index/AggregationShortcut.php b/src/Index/StatsSupport.php similarity index 61% rename from src/Index/AggregationShortcut.php rename to src/Index/StatsSupport.php index 21ac81b..0d09a0b 100644 --- a/src/Index/AggregationShortcut.php +++ b/src/Index/StatsSupport.php @@ -5,7 +5,7 @@ /** * Shortcut methods for common metric aggregations on Search. */ -trait AggregationShortcut +trait StatsSupport { /** * Return the maximum value of a field. @@ -51,6 +51,38 @@ public function sum($field) return $this->aggregateScalar('sum', $field); } + /** + * Return stats (count, min, max, avg, sum) for a field in a single request. + * + * @param string $field + * @return array{count: int, min: float|null, max: float|null, avg: float|null, sum: float|null}|null + */ + public function stats($field) + { + $saved = $this->query; + $this->query = clone $this->query; + $this->query->size(0); + $this->query->aggs('__stats', ['stats' => ['field' => $field]]); + try { + $response = $this->doSearch('stats'); + } finally { + $this->query = $saved; + } + + $raw = $response['aggregations']['__stats'] ?? null; + if ($raw === null) { + return null; + } + + return [ + 'count' => $raw['count'] ?? 0, + 'min' => $raw['min'] ?? null, + 'max' => $raw['max'] ?? null, + 'avg' => $raw['avg'] ?? null, + 'sum' => $raw['sum'] ?? null, + ]; + } + /** * Execute a metric aggregation and return the scalar value. * diff --git a/tests/Index/AggregationShortcutTest.php b/tests/Index/StatsSupportTest.php similarity index 62% rename from tests/Index/AggregationShortcutTest.php rename to tests/Index/StatsSupportTest.php index 2b3972d..507cff7 100644 --- a/tests/Index/AggregationShortcutTest.php +++ b/tests/Index/StatsSupportTest.php @@ -4,7 +4,7 @@ use ElasticKit\Index\Index; use ElasticKit\Index\Search; -class AggregationShortcutTest extends TestCase +class StatsSupportTest extends TestCase { protected function setUp(): void { @@ -78,7 +78,70 @@ public function testSum() $this->assertEquals(1500.0, $result); } - public function testAggregationShortcutSendsCorrectBody() + public function testStatsReturnsAllMetrics() + { + $client = $this->createMock(TestClient::class); + $client->method('search')->willReturn(new ArrayResponse([ + 'hits' => ['total' => ['value' => 0], 'hits' => []], + 'aggregations' => [ + '__stats' => [ + 'count' => 100, + 'min' => 9.99, + 'max' => 199.99, + 'avg' => 49.5, + 'sum' => 4950.0, + ], + ], + ])); + Index::setClient($client); + + $index = $this->createIndex(); + $result = $index->query()->stats('price'); + + $this->assertEquals([ + 'count' => 100, + 'min' => 9.99, + 'max' => 199.99, + 'avg' => 49.5, + 'sum' => 4950.0, + ], $result); + } + + public function testStatsReturnsNullWhenNoAggregation() + { + $client = $this->createMock(TestClient::class); + $client->method('search')->willReturn(new ArrayResponse([ + 'hits' => ['total' => ['value' => 0], 'hits' => []], + ])); + Index::setClient($client); + + $index = $this->createIndex(); + $result = $index->query()->stats('nonexistent'); + + $this->assertNull($result); + } + + public function testStatsSendsCorrectBody() + { + $client = $this->createMock(TestClient::class); + $client->expects($this->once())->method('search')->with($this->callback(function ($params) { + $body = $params['body']; + return $body['size'] === 0 + && isset($body['aggs']['__stats']['stats']['field']) + && $body['aggs']['__stats']['stats']['field'] === 'price'; + }))->willReturn(new ArrayResponse([ + 'hits' => ['total' => ['value' => 0], 'hits' => []], + 'aggregations' => [ + '__stats' => ['count' => 0, 'min' => null, 'max' => null, 'avg' => null, 'sum' => 0], + ], + ])); + Index::setClient($client); + + $index = $this->createIndex(); + $index->query()->stats('price'); + } + + public function testScalarSendsCorrectBody() { $client = $this->createMock(TestClient::class); $client->expects($this->once())->method('search')->with($this->callback(function ($params) { @@ -96,7 +159,7 @@ public function testAggregationShortcutSendsCorrectBody() $index->query()->max('price'); } - public function testAggregationShortcutDoesNotMutateQuery() + public function testScalarDoesNotMutateQuery() { $lastBody = null; $client = $this->createMock(TestClient::class); @@ -118,7 +181,7 @@ public function testAggregationShortcutDoesNotMutateQuery() $this->assertEquals(0, $lastBody['size']); } - public function testAggregationShortcutReturnsNullWhenNoValue() + public function testScalarReturnsNullWhenNoValue() { $client = $this->createMock(TestClient::class); $client->method('search')->willReturn(new ArrayResponse([ From 9bcb741145a6dddd1ac665c1fc6495d0b0b6042f Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 12 Jun 2026 23:19:56 +0800 Subject: [PATCH 09/24] =?UTF-8?q?refactor(index):=20=E4=BB=8E=20Index=20?= =?UTF-8?q?=E6=8B=86=E5=87=BA=20ClientManager=E3=80=81EventDispatcher?= =?UTF-8?q?=E3=80=81Pagination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Index 静态方法保留作 @deprecated 代理,调用点迁移到新类。 测试 ReflectionProperty 替换为新类的 reset()。 --- src/Index/Bulk.php | 4 +- src/Index/ClientManager.php | 62 ++++++++++++++++++++++++++ src/Index/EventDispatcher.php | 72 ++++++++++++++++++++++++++++++ src/Index/Index.php | 75 +++++++------------------------- src/Index/Manager.php | 12 ++--- src/Index/Pagination.php | 72 ++++++++++++++++++++++++++++++ src/Index/Rebuild.php | 4 +- src/Index/Results.php | 2 +- src/Index/Search.php | 14 +++--- tests/Index/BulkTest.php | 5 +-- tests/Index/DocTest.php | 5 +-- tests/Index/EventTest.php | 11 ++--- tests/Index/IndexTest.php | 22 +++------- tests/Index/ManagerTest.php | 5 +-- tests/Index/RebuildTest.php | 5 +-- tests/Index/ResultsTest.php | 5 +-- tests/Index/StatsSupportTest.php | 5 +-- 17 files changed, 260 insertions(+), 120 deletions(-) create mode 100644 src/Index/ClientManager.php create mode 100644 src/Index/EventDispatcher.php create mode 100644 src/Index/Pagination.php diff --git a/src/Index/Bulk.php b/src/Index/Bulk.php index 8f2336e..9001e08 100644 --- a/src/Index/Bulk.php +++ b/src/Index/Bulk.php @@ -217,7 +217,7 @@ public function execute(array $options = []) $e = new Event('bulk.execute.before', $indexName); $e->actions = $actions; - Index::dispatch($e); + EventDispatcher::dispatch($e); $start = microtime(true); $response = $this->index->getClient()->bulk( @@ -233,7 +233,7 @@ public function execute(array $options = []) $e->actions = $actions; $e->response = $response; $e->duration = $duration; - Index::dispatch($e); + EventDispatcher::dispatch($e); if (!empty($response['errors'])) { if ($this->errorHandler) { diff --git a/src/Index/ClientManager.php b/src/Index/ClientManager.php new file mode 100644 index 0000000..077cb71 --- /dev/null +++ b/src/Index/ClientManager.php @@ -0,0 +1,62 @@ + + */ + private static $clients = []; + + /** + * Register an Elasticsearch client. Optionally name the connection. + * + * @param ClientInterface $client + * @param string|null $name connection name, null for default + * @return void + */ + public static function set(ClientInterface $client, $name = null) + { + self::$clients[$name ?? 'default'] = $client; + } + + /** + * Return the Elasticsearch client for the given connection name. + * + * Falls back to 'default' if the named connection is not registered. + * + * @param string $connection + * @return ClientInterface + * @throws RuntimeException if no client is registered + */ + public static function get($connection = 'default') + { + if (isset(self::$clients[$connection])) { + return self::$clients[$connection]; + } + if (isset(self::$clients['default'])) { + return self::$clients['default']; + } + throw new RuntimeException( + "Elasticsearch client not registered for connection '{$connection}'. " + . 'Call ClientManager::set($client) first.' + ); + } + + /** + * Reset all registered clients. Mainly for testing. + * + * @return void + */ + public static function reset() + { + self::$clients = []; + } +} diff --git a/src/Index/EventDispatcher.php b/src/Index/EventDispatcher.php new file mode 100644 index 0000000..e3ac9df --- /dev/null +++ b/src/Index/EventDispatcher.php @@ -0,0 +1,72 @@ +> + */ + private static $listeners = []; + + /** + * Register an event listener. + * + * Supports exact event name, category wildcard (e.g. 'search.*'), or global '*'. + * + * @param string $event + * @param callable $listener receives (Event $event) + * @return void + */ + public static function listen($event, callable $listener) + { + self::$listeners[$event][] = $listener; + } + + /** + * Dispatch an event to all matching listeners. + * + * @param Event $event + * @return void + */ + public static function dispatch(Event $event) + { + foreach (self::$listeners as $pattern => $listeners) { + if ($pattern === $event->name || $pattern === '*' || self::matchesCategory($pattern, $event->name)) { + foreach ($listeners as $listener) { + $listener($event); + } + } + } + } + + /** + * Reset all registered listeners. Mainly for testing. + * + * @return void + */ + public static function reset() + { + self::$listeners = []; + } + + /** + * Check if a wildcard pattern matches an event by category. + * + * @param string $pattern + * @param string $event + * @return bool + */ + private static function matchesCategory($pattern, $event) + { + if (substr($pattern, -2) !== '.*') { + return false; + } + + $prefix = substr($pattern, 0, -1); + return strpos($event, $prefix) === 0; + } +} diff --git a/src/Index/Index.php b/src/Index/Index.php index 75f4b52..1b44bd1 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -14,11 +14,6 @@ */ abstract class Index { - /** - * @var array - */ - protected static $clients = []; - /** * @var string */ @@ -49,31 +44,17 @@ abstract class Index */ protected $maxPerPage = 100; - /** - * @var callable|null - */ - protected static $pageResolver; - - /** - * @var callable|null - */ - protected static $paginatorResolver; - - /** - * @var array> - */ - protected static $listeners = []; - /** * Register an Elasticsearch client. Optionally name the connection. * * @param ClientInterface $client * @param string|null $name connection name, null for default * @return void + * @deprecated Use ClientManager::set() instead */ public static function setClient(ClientInterface $client, $name = null) { - self::$clients[$name ?? 'default'] = $client; + ClientManager::set($client, $name); } /** @@ -83,16 +64,7 @@ public static function setClient(ClientInterface $client, $name = null) */ public function getClient() { - if (isset(self::$clients[$this->connection])) { - return self::$clients[$this->connection]; - } - if (isset(self::$clients['default'])) { - return self::$clients['default']; - } - throw new RuntimeException( - 'Elasticsearch client not registered for connection \'' . $this->connection . '\'. ' - . 'Call ' . static::class . '::setClient($client) first.' - ); + return ClientManager::get($this->connection); } /** @@ -206,10 +178,11 @@ public function maxPerPage() * * @param callable $resolver returns [$page, $perPage] * @return void + * @deprecated Use Pagination::setPageResolver() instead */ public static function setPageResolver(callable $resolver) { - self::$pageResolver = $resolver; + Pagination::setPageResolver($resolver); } /** @@ -217,30 +190,33 @@ public static function setPageResolver(callable $resolver) * * @param callable $resolver receives (Results $results, int $page, int $perPage) * @return void + * @deprecated Use Pagination::setPaginatorResolver() instead */ public static function setPaginatorResolver(callable $resolver) { - self::$paginatorResolver = $resolver; + Pagination::setPaginatorResolver($resolver); } /** * Return the registered page resolver, or null. * * @return callable|null + * @deprecated Use Pagination::getPageResolver() instead */ public static function getPageResolver() { - return self::$pageResolver; + return Pagination::getPageResolver(); } /** * Return the registered paginator resolver, or null. * * @return callable|null + * @deprecated Use Pagination::getPaginatorResolver() instead */ public static function getPaginatorResolver() { - return self::$paginatorResolver; + return Pagination::getPaginatorResolver(); } /** @@ -263,10 +239,11 @@ public function source(array $context = []): iterable * @param string $event * @param callable $listener receives (Event $event) * @return void + * @deprecated Use EventDispatcher::listen() instead */ public static function listen($event, callable $listener) { - self::$listeners[$event][] = $listener; + EventDispatcher::listen($event, $listener); } /** @@ -274,32 +251,10 @@ public static function listen($event, callable $listener) * * @param Event $event * @return void + * @deprecated Use EventDispatcher::dispatch() instead */ public static function dispatch(Event $event) { - foreach (self::$listeners as $pattern => $listeners) { - if ($pattern === $event->name || $pattern === '*' || static::matchesCategory($pattern, $event->name)) { - foreach ($listeners as $listener) { - $listener($event); - } - } - } - } - - /** - * Check if a wildcard pattern matches an event by category. - * - * @param string $pattern - * @param string $event - * @return bool - */ - protected static function matchesCategory($pattern, $event) - { - if (substr($pattern, -2) !== '.*') { - return false; - } - - $prefix = substr($pattern, 0, -1); - return strpos($event, $prefix) === 0; + EventDispatcher::dispatch($event); } } diff --git a/src/Index/Manager.php b/src/Index/Manager.php index f166ac3..00ee232 100644 --- a/src/Index/Manager.php +++ b/src/Index/Manager.php @@ -36,7 +36,7 @@ public function create() $indexName = $this->index->name(); $e = new Event('manager.create.before', $indexName); - Index::dispatch($e); + EventDispatcher::dispatch($e); $mappings = $this->index->mappings(); $settings = $this->index->settings(); @@ -51,7 +51,7 @@ public function create() $e = new Event('manager.create.after', $indexName); $e->response = $response; - Index::dispatch($e); + EventDispatcher::dispatch($e); return $response; } @@ -66,7 +66,7 @@ public function delete() $indexName = $this->resolveIndexName(); $e = new Event('manager.delete.before', $indexName); - Index::dispatch($e); + EventDispatcher::dispatch($e); $response = $this->index->getClient()->indices()->delete([ 'index' => $indexName, @@ -74,7 +74,7 @@ public function delete() $e = new Event('manager.delete.after', $indexName); $e->response = $response; - Index::dispatch($e); + EventDispatcher::dispatch($e); return $response; } @@ -256,7 +256,7 @@ public function swapAlias($alias, $fromIndex) $indexName = $this->index->name(); $e = new Event('manager.swap_alias.before', $indexName); - Index::dispatch($e); + EventDispatcher::dispatch($e); $response = $this->index->getClient()->indices()->updateAliases([ 'body' => [ @@ -269,7 +269,7 @@ public function swapAlias($alias, $fromIndex) $e = new Event('manager.swap_alias.after', $indexName); $e->response = $response; - Index::dispatch($e); + EventDispatcher::dispatch($e); return $response; } diff --git a/src/Index/Pagination.php b/src/Index/Pagination.php new file mode 100644 index 0000000..9a933b3 --- /dev/null +++ b/src/Index/Pagination.php @@ -0,0 +1,72 @@ +index->name(); $client = $this->index->getClient()->indices(); - Index::dispatch(new Event('rebuild.run.before', $name)); + EventDispatcher::dispatch(new Event('rebuild.run.before', $name)); $newName = $this->createIndex(); @@ -254,7 +254,7 @@ private function doRun(array $context): array $e = new Event('rebuild.run.after', $name); $e->newIndex = $newName; $e->oldIndex = $oldIndex; - Index::dispatch($e); + EventDispatcher::dispatch($e); return ['newIndex' => $newName, 'oldIndex' => $oldIndex]; } diff --git a/src/Index/Results.php b/src/Index/Results.php index 0efd61e..5216d1b 100644 --- a/src/Index/Results.php +++ b/src/Index/Results.php @@ -239,7 +239,7 @@ public function toPaginator() ); } - $resolver = Index::getPaginatorResolver(); + $resolver = Pagination::getPaginatorResolver(); if ($resolver === null) { throw new RuntimeException( 'Paginator resolver not registered. Call Index::setPaginatorResolver() first.' diff --git a/src/Index/Search.php b/src/Index/Search.php index 2152981..c275c2a 100644 --- a/src/Index/Search.php +++ b/src/Index/Search.php @@ -194,7 +194,7 @@ protected function doScroll($scrollId, $duration) $e = new Event('search.scroll.before', $indexName); $e->action = 'scroll'; $e->scrollId = $scrollId; - Index::dispatch($e); + EventDispatcher::dispatch($e); $start = microtime(true); $response = $this->index->getClient()->scroll([ @@ -209,7 +209,7 @@ protected function doScroll($scrollId, $duration) $e->scrollId = $scrollId; $e->response = $response; $e->duration = $durationTime; - Index::dispatch($e); + EventDispatcher::dispatch($e); return new Results($response); } @@ -244,7 +244,7 @@ public function cursor($duration = '5m') public function paginate($page = null, $perPage = null) { if ($page === null && $perPage === null) { - $resolver = Index::getPageResolver(); + $resolver = Pagination::getPageResolver(); if ($resolver !== null) { [$page, $perPage] = $resolver(); } @@ -284,7 +284,7 @@ protected function doCount() $e = new Event('search.query.before', $indexName); $e->dsl = $body; $e->action = 'count'; - Index::dispatch($e); + EventDispatcher::dispatch($e); $start = microtime(true); $response = $this->index->getClient()->count([ @@ -299,7 +299,7 @@ protected function doCount() $e->response = $response; $e->duration = $duration; $e->action = 'count'; - Index::dispatch($e); + EventDispatcher::dispatch($e); return $response; } @@ -319,7 +319,7 @@ protected function doSearch($action, array $extra = []) $e = new Event('search.query.before', $indexName); $e->dsl = $body; $e->action = $action; - Index::dispatch($e); + EventDispatcher::dispatch($e); $params = array_merge(['index' => $indexName, 'body' => $body], $this->urlParams, $extra); @@ -333,7 +333,7 @@ protected function doSearch($action, array $extra = []) $e->response = $response; $e->duration = $duration; $e->action = $action; - Index::dispatch($e); + EventDispatcher::dispatch($e); return $response; } diff --git a/tests/Index/BulkTest.php b/tests/Index/BulkTest.php index 90539a8..82dee70 100644 --- a/tests/Index/BulkTest.php +++ b/tests/Index/BulkTest.php @@ -2,6 +2,7 @@ use PHPUnit\Framework\TestCase; use ElasticKit\Index\Bulk; +use ElasticKit\Index\ClientManager; use ElasticKit\Index\Index; class BulkTest extends TestCase @@ -13,9 +14,7 @@ protected function setUp(): void protected function tearDown(): void { - $ref = new ReflectionProperty(Index::class, 'clients'); - $ref->setAccessible(true); - $ref->setValue(null, []); + ClientManager::reset(); } protected function createIndex($name = 'products') diff --git a/tests/Index/DocTest.php b/tests/Index/DocTest.php index 71168f4..7b3058f 100644 --- a/tests/Index/DocTest.php +++ b/tests/Index/DocTest.php @@ -1,6 +1,7 @@ setAccessible(true); - $ref->setValue(null, []); + ClientManager::reset(); } protected function createIndex($name = 'products') diff --git a/tests/Index/EventTest.php b/tests/Index/EventTest.php index 09edd1f..bb15d11 100644 --- a/tests/Index/EventTest.php +++ b/tests/Index/EventTest.php @@ -1,20 +1,17 @@ setAccessible(true); - $ref->setValue(null, []); - - $clientRef = new ReflectionProperty(Index::class, 'clients'); - $clientRef->setAccessible(true); - $clientRef->setValue(null, []); + EventDispatcher::reset(); + ClientManager::reset(); } protected function createIndex($name = 'products') diff --git a/tests/Index/IndexTest.php b/tests/Index/IndexTest.php index acc5d73..ea9403e 100644 --- a/tests/Index/IndexTest.php +++ b/tests/Index/IndexTest.php @@ -2,7 +2,9 @@ use PHPUnit\Framework\TestCase; use ElasticKit\DSL\Query; +use ElasticKit\Index\ClientManager; use ElasticKit\Index\Index; +use ElasticKit\Index\Pagination; use ElasticKit\Index\Results; use ElasticKit\Index\Search; @@ -15,19 +17,8 @@ protected function setUp(): void protected function tearDown(): void { - // Reset static clients between tests - $ref = new ReflectionProperty(Index::class, 'clients'); - $ref->setAccessible(true); - $ref->setValue(null, []); - - // Reset static resolvers between tests - $pageRef = new ReflectionProperty(Index::class, 'pageResolver'); - $pageRef->setAccessible(true); - $pageRef->setValue(null, null); - - $paginatorRef = new ReflectionProperty(Index::class, 'paginatorResolver'); - $paginatorRef->setAccessible(true); - $paginatorRef->setValue(null, null); + ClientManager::reset(); + Pagination::reset(); } protected function createIndex($name = 'products') @@ -703,10 +694,7 @@ public function __construct($name) public function testGetClientThrowsWhenNotRegistered() { - // Ensure no clients are registered - $ref = new ReflectionProperty(Index::class, 'clients'); - $ref->setAccessible(true); - $ref->setValue(null, []); + ClientManager::reset(); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('nonexistent'); diff --git a/tests/Index/ManagerTest.php b/tests/Index/ManagerTest.php index d1bdbac..5039b72 100644 --- a/tests/Index/ManagerTest.php +++ b/tests/Index/ManagerTest.php @@ -1,6 +1,7 @@ setAccessible(true); - $ref->setValue(null, []); + ClientManager::reset(); } protected function createIndex($name = 'products', $mappings = [], $settings = []) diff --git a/tests/Index/RebuildTest.php b/tests/Index/RebuildTest.php index 2dd1abf..8d25dbb 100644 --- a/tests/Index/RebuildTest.php +++ b/tests/Index/RebuildTest.php @@ -1,6 +1,7 @@ setAccessible(true); - $ref->setValue(null, []); + ClientManager::reset(); } protected function createIndex($name = 'products', $mappings = [], $settings = []) diff --git a/tests/Index/ResultsTest.php b/tests/Index/ResultsTest.php index 73cc39a..40108a1 100644 --- a/tests/Index/ResultsTest.php +++ b/tests/Index/ResultsTest.php @@ -2,6 +2,7 @@ use PHPUnit\Framework\TestCase; use ElasticKit\Index\Index; +use ElasticKit\Index\Pagination; use ElasticKit\Index\Results; class ResultsTest extends TestCase @@ -196,9 +197,7 @@ public function testToPaginatorCallsResolver() $this->assertEquals(['total' => 50, 'page' => 2], $paginator); // Clean up - $ref = new ReflectionProperty(Index::class, 'paginatorResolver'); - $ref->setAccessible(true); - $ref->setValue(null, null); + Pagination::reset(); } public function testToPaginatorThrowsWithoutResolver() diff --git a/tests/Index/StatsSupportTest.php b/tests/Index/StatsSupportTest.php index 507cff7..715c084 100644 --- a/tests/Index/StatsSupportTest.php +++ b/tests/Index/StatsSupportTest.php @@ -1,6 +1,7 @@ setAccessible(true); - $ref->setValue(null, []); + ClientManager::reset(); } protected function createIndex($name = 'products') From 2caae252f95a0859323b365464c51b4bd9198aea Mon Sep 17 00:00:00 2001 From: ykan821 Date: Sat, 13 Jun 2026 00:38:40 +0800 Subject: [PATCH 10/24] =?UTF-8?q?refactor(index):=20=E7=A7=BB=E9=99=A4=20i?= =?UTF-8?q?nsert/deprecated=20=E4=BB=A3=E7=90=86=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20on/newQuery/newDoc=20=E5=AE=9E=E4=BE=8B=E5=85=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 Index::insert(),等价功能由 Doc::save() 覆盖 - 移除 6 个 deprecated 代理方法(listen/dispatch/setPageResolver 等) - 新增 on(string $connection)、newQuery()、newDoc() 实例方法 - 新增 setConnection()/getConnection() 实例方法 - query()/doc() 改为委托 newQuery()/newDoc() - ClientManager 删除隐式 fallback,补类型声明 - 更新测试和 README --- README.md | 2 +- src/Index/ClientManager.php | 17 ++-- src/Index/Index.php | 151 ++++++++++++++---------------------- tests/Index/EventTest.php | 32 ++++---- tests/Index/IndexTest.php | 140 +++++++++++++++++++++++++++++---- tests/Index/ResultsTest.php | 12 ++- 6 files changed, 217 insertions(+), 137 deletions(-) diff --git a/README.md b/README.md index fcca21f..ceffd8f 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ foreach (ProductIndex::query()->cursor() as $batch) { ### 文档 CRUD ```php -ProductIndex::insert(1, ['title' => 'Hello', 'price' => 99.9]); +ProductIndex::doc(1)->save(['title' => 'Hello', 'price' => 99.9]); $doc = ProductIndex::doc(1); $doc->source(); // ['title' => 'Hello', 'price' => 99.9] diff --git a/src/Index/ClientManager.php b/src/Index/ClientManager.php index 077cb71..886b042 100644 --- a/src/Index/ClientManager.php +++ b/src/Index/ClientManager.php @@ -19,31 +19,26 @@ class ClientManager * Register an Elasticsearch client. Optionally name the connection. * * @param ClientInterface $client - * @param string|null $name connection name, null for default + * @param string $name connection name, defaults to 'default' * @return void */ - public static function set(ClientInterface $client, $name = null) + public static function set(ClientInterface $client, string $name = 'default'): void { - self::$clients[$name ?? 'default'] = $client; + self::$clients[$name] = $client; } /** * Return the Elasticsearch client for the given connection name. * - * Falls back to 'default' if the named connection is not registered. - * * @param string $connection * @return ClientInterface - * @throws RuntimeException if no client is registered + * @throws RuntimeException if the connection is not registered */ - public static function get($connection = 'default') + public static function get(string $connection = 'default'): ClientInterface { if (isset(self::$clients[$connection])) { return self::$clients[$connection]; } - if (isset(self::$clients['default'])) { - return self::$clients['default']; - } throw new RuntimeException( "Elasticsearch client not registered for connection '{$connection}'. " . 'Call ClientManager::set($client) first.' @@ -55,7 +50,7 @@ public static function get($connection = 'default') * * @return void */ - public static function reset() + public static function reset(): void { self::$clients = []; } diff --git a/src/Index/Index.php b/src/Index/Index.php index 1b44bd1..0dd9854 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -48,11 +48,10 @@ abstract class Index * Register an Elasticsearch client. Optionally name the connection. * * @param ClientInterface $client - * @param string|null $name connection name, null for default + * @param string $name connection name, defaults to 'default' * @return void - * @deprecated Use ClientManager::set() instead */ - public static function setClient(ClientInterface $client, $name = null) + public static function setClient(ClientInterface $client, string $name = 'default'): void { ClientManager::set($client, $name); } @@ -62,11 +61,45 @@ public static function setClient(ClientInterface $client, $name = null) * * @return ClientInterface */ - public function getClient() + public function getClient(): ClientInterface { return ClientManager::get($this->connection); } + /** + * Set the connection name for this index instance. + * + * @param string $connection + * @return $this + */ + public function setConnection(string $connection) + { + $this->connection = $connection; + + return $this; + } + + /** + * Return the connection name for this index. + * + * @return string + */ + public function getConnection(): string + { + return $this->connection; + } + + /** + * Create a new index instance with the given connection. + * + * @param string $connection + * @return static + */ + public static function on(string $connection) + { + return (new static())->setConnection($connection); + } + /** * Return the index name. * @@ -84,43 +117,47 @@ public function name() } /** - * Create a new Search instance. Supports both static and instance call. + * Create a new Search instance from this index instance. * + * @param Query|null $query + * @return Search + */ + public function newQuery(Query $query = null) + { + return new Search($this, $query); + } + + /** + * Create a Search instance. Delegates to newQuery() with a fresh instance. + * + * @param Query|null $query * @return Search */ public static function query(Query $query = null) { - return new Search(new static(), $query); + return (new static())->newQuery($query); } /** - * Create a DocReference for a single document. Supports both static and instance call. + * Create a Doc reference from this index instance. * * @param string|int $id * @return Doc */ - public static function doc($id) + public function newDoc($id) { - return new Doc(new static(), $id); + return new Doc($this, $id); } /** - * Insert (create or overwrite) a single document. + * Create a Doc reference. Delegates to newDoc() with a fresh instance. * - * @param string|int|null $id document ID, null or empty string to let ES auto-generate - * @param array $document document body - * @return array + * @param string|int $id + * @return Doc */ - public static function insert($id, array $document) + public static function doc($id) { - $index = new static(); - $params = ['index' => $index->name(), 'body' => $document]; - - if ($id !== null && $id !== '') { - $params['id'] = $id; - } - - return $index->getClient()->index($params)->asArray(); + return (new static())->newDoc($id); } /** @@ -173,52 +210,6 @@ public function maxPerPage() return $this->maxPerPage; } - /** - * Register a resolver that extracts page and perPage from the request. - * - * @param callable $resolver returns [$page, $perPage] - * @return void - * @deprecated Use Pagination::setPageResolver() instead - */ - public static function setPageResolver(callable $resolver) - { - Pagination::setPageResolver($resolver); - } - - /** - * Register a resolver that converts Results into a framework paginator. - * - * @param callable $resolver receives (Results $results, int $page, int $perPage) - * @return void - * @deprecated Use Pagination::setPaginatorResolver() instead - */ - public static function setPaginatorResolver(callable $resolver) - { - Pagination::setPaginatorResolver($resolver); - } - - /** - * Return the registered page resolver, or null. - * - * @return callable|null - * @deprecated Use Pagination::getPageResolver() instead - */ - public static function getPageResolver() - { - return Pagination::getPageResolver(); - } - - /** - * Return the registered paginator resolver, or null. - * - * @return callable|null - * @deprecated Use Pagination::getPaginatorResolver() instead - */ - public static function getPaginatorResolver() - { - return Pagination::getPaginatorResolver(); - } - /** * Yield documents as [id => doc] pairs. Override to provide a default data source for rebuild. * @@ -233,28 +224,4 @@ public function source(array $context = []): iterable ); } - /** - * Register an event listener. Supports exact event name, category wildcard (e.g. 'search.*'), or global '*'. - * - * @param string $event - * @param callable $listener receives (Event $event) - * @return void - * @deprecated Use EventDispatcher::listen() instead - */ - public static function listen($event, callable $listener) - { - EventDispatcher::listen($event, $listener); - } - - /** - * Dispatch an event to all matching listeners. - * - * @param Event $event - * @return void - * @deprecated Use EventDispatcher::dispatch() instead - */ - public static function dispatch(Event $event) - { - EventDispatcher::dispatch($event); - } } diff --git a/tests/Index/EventTest.php b/tests/Index/EventTest.php index bb15d11..8d01c92 100644 --- a/tests/Index/EventTest.php +++ b/tests/Index/EventTest.php @@ -37,7 +37,7 @@ protected function mockClient() public function testListenAndDispatch() { $received = null; - Index::listen('search.query.before', function (Event $e) use (&$received) { + EventDispatcher::listen('search.query.before', function (Event $e) use (&$received) { $received = $e; }); @@ -53,7 +53,7 @@ public function testListenAndDispatch() public function testSearchBeforePassesDsl() { $dsl = null; - Index::listen('search.query.before', function (Event $e) use (&$dsl) { + EventDispatcher::listen('search.query.before', function (Event $e) use (&$dsl) { $dsl = $e->dsl; }); @@ -68,7 +68,7 @@ public function testSearchBeforePassesDsl() public function testSearchAfterPassesResponse() { $response = null; - Index::listen('search.query.after', function (Event $e) use (&$response) { + EventDispatcher::listen('search.query.after', function (Event $e) use (&$response) { $response = $e->response; }); @@ -83,7 +83,7 @@ public function testSearchAfterPassesResponse() public function testSearchAfterContainsDuration() { $duration = null; - Index::listen('search.query.after', function (Event $e) use (&$duration) { + EventDispatcher::listen('search.query.after', function (Event $e) use (&$duration) { $duration = $e->duration; }); @@ -98,7 +98,7 @@ public function testSearchAfterContainsDuration() public function testSearchEventPassesAction() { $action = null; - Index::listen('search.query.before', function (Event $e) use (&$action) { + EventDispatcher::listen('search.query.before', function (Event $e) use (&$action) { $action = $e->action; }); @@ -112,7 +112,7 @@ public function testSearchEventPassesAction() public function testFirstTriggersSearchWithAction() { $action = null; - Index::listen('search.query.before', function (Event $e) use (&$action) { + EventDispatcher::listen('search.query.before', function (Event $e) use (&$action) { $action = $e->action; }); @@ -126,7 +126,7 @@ public function testFirstTriggersSearchWithAction() public function testWildcardListener() { $events = []; - Index::listen('*', function (Event $e) use (&$events) { + EventDispatcher::listen('*', function (Event $e) use (&$events) { $events[] = $e->name; }); @@ -141,7 +141,7 @@ public function testWildcardListener() public function testCategoryWildcardListener() { $events = []; - Index::listen('search.*', function (Event $e) use (&$events) { + EventDispatcher::listen('search.*', function (Event $e) use (&$events) { $events[] = $e->name; }); @@ -156,7 +156,7 @@ public function testCategoryWildcardListener() public function testCategoryWildcardMatchesSearchQueryEvents() { $events = []; - Index::listen('search.*', function (Event $e) use (&$events) { + EventDispatcher::listen('search.*', function (Event $e) use (&$events) { $events[] = $e->name; }); @@ -178,10 +178,10 @@ public function testCategoryWildcardMatchesSearchQueryEvents() public function testMultipleListeners() { $count = 0; - Index::listen('search.query.before', function (Event $e) use (&$count) { + EventDispatcher::listen('search.query.before', function (Event $e) use (&$count) { $count++; }); - Index::listen('search.query.before', function (Event $e) use (&$count) { + EventDispatcher::listen('search.query.before', function (Event $e) use (&$count) { $count++; }); @@ -204,7 +204,7 @@ public function testNoListenersDoesNotError() public function testBulkExecutePassesActions() { $actions = null; - Index::listen('bulk.execute.before', function (Event $e) use (&$actions) { + EventDispatcher::listen('bulk.execute.before', function (Event $e) use (&$actions) { $actions = $e->actions; }); @@ -224,7 +224,7 @@ public function testBulkExecutePassesActions() public function testManagerCreateEvents() { $events = []; - Index::listen('manager.create.*', function (Event $e) use (&$events) { + EventDispatcher::listen('manager.create.*', function (Event $e) use (&$events) { $events[] = $e->name; }); @@ -245,7 +245,7 @@ public function testManagerCreateEvents() public function testManagerDeleteEvents() { $events = []; - Index::listen('manager.delete.*', function (Event $e) use (&$events) { + EventDispatcher::listen('manager.delete.*', function (Event $e) use (&$events) { $events[] = $e->name; }); @@ -267,7 +267,7 @@ public function testManagerDeleteEvents() public function testManagerReadOperationsHaveNoEvents() { $events = []; - Index::listen('*', function (Event $e) use (&$events) { + EventDispatcher::listen('*', function (Event $e) use (&$events) { $events[] = $e->name; }); @@ -294,7 +294,7 @@ public function testManagerReadOperationsHaveNoEvents() public function testRebuildRunBeforeAndAfterEvents() { $events = []; - Index::listen('rebuild.*', function (Event $e) use (&$events) { + EventDispatcher::listen('rebuild.*', function (Event $e) use (&$events) { $events[] = $e->name; }); diff --git a/tests/Index/IndexTest.php b/tests/Index/IndexTest.php index ea9403e..08b732b 100644 --- a/tests/Index/IndexTest.php +++ b/tests/Index/IndexTest.php @@ -467,7 +467,7 @@ public function testPaginateWithExplicitParams() public function testPaginateWithPageResolver() { - Index::setPageResolver(function () { + Pagination::setPageResolver(function () { return [2, 20]; }); @@ -597,7 +597,7 @@ public function __construct($name = 'products') public function testToPaginatorReturnsFrameworkPaginator() { - Index::setPaginatorResolver(function (Results $results) { + Pagination::setPaginatorResolver(function (Results $results) { return [ 'data' => $results->items(), 'total' => $results->total(), @@ -676,11 +676,14 @@ public function __construct($name) $this->assertSame($logClient, $logs->getClient()); } - public function testGetClientFallsBackToDefault() + public function testGetClientThrowsForUnknownConnection() { $defaultClient = $this->createMock(TestClient::class); Index::setClient($defaultClient); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('nonexistent'); + $index = new class('unknown') extends Index { public function __construct($name) { @@ -689,7 +692,7 @@ public function __construct($name) } }; - $this->assertSame($defaultClient, $index->getClient()); + $index->getClient(); } public function testGetClientThrowsWhenNotRegistered() @@ -697,16 +700,127 @@ public function testGetClientThrowsWhenNotRegistered() ClientManager::reset(); $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('nonexistent'); - - $index = new class('test') extends Index { - public function __construct($name) - { - $this->name = $name; - $this->connection = 'nonexistent'; - } - }; + $index = $this->createIndex('test'); $index->getClient(); } + + public function testSetConnectionAndGetConnection() + { + $index = $this->createIndex('products'); + + $this->assertEquals('default', $index->getConnection()); + + $result = $index->setConnection('secondary'); + $this->assertSame($index, $result); + $this->assertEquals('secondary', $index->getConnection()); + } + + public function testOnCreatesInstanceWithConnection() + { + $defaultClient = $this->createMock(TestClient::class); + $secondaryClient = $this->createMock(TestClient::class); + Index::setClient($defaultClient); + Index::setClient($secondaryClient, 'secondary'); + + $index = TestConcreteIndex::on('secondary'); + + $this->assertInstanceOf(TestConcreteIndex::class, $index); + $this->assertEquals('secondary', $index->getConnection()); + $this->assertEquals('test', $index->name()); + $this->assertSame($secondaryClient, $index->getClient()); + } + + public function testNewQueryReturnsSearch() + { + $client = $this->createMock(TestClient::class); + $client->method('search')->willReturn(new ArrayResponse([ + 'hits' => ['total' => ['value' => 1], 'hits' => [['_source' => ['title' => 'test']]]], + ])); + Index::setClient($client); + + $index = $this->createIndex('products'); + $this->assertInstanceOf(Search::class, $index->newQuery()); + + $query = Query::create()->match('title', 'test'); + $results = $index->newQuery($query)->get(); + $this->assertEquals(1, $results->total()); + } + + public function testNewQueryUsesInstanceConnection() + { + $secondaryClient = $this->createMock(TestClient::class); + $secondaryClient->method('search')->willReturn(new ArrayResponse([ + 'hits' => ['total' => ['value' => 0], 'hits' => []], + ])); + Index::setClient($secondaryClient, 'secondary'); + + $index = $this->createIndex('products'); + $index->setConnection('secondary'); + $results = $index->newQuery()->matchAll()->get(); + + $this->assertEquals(0, $results->total()); + } + + public function testNewDocUsesInstanceConnection() + { + $secondaryClient = $this->createMock(TestClient::class); + $secondaryClient->method('getSource')->willReturn(new ArrayResponse([ + 'found' => true, + '_source' => ['title' => 'test'], + ])); + Index::setClient($secondaryClient, 'secondary'); + + $index = $this->createIndex('products'); + $index->setConnection('secondary'); + $doc = $index->newDoc(1); + + $this->assertInstanceOf(\ElasticKit\Index\Doc::class, $doc); + $this->assertEquals([ + 'found' => true, + '_source' => ['title' => 'test'], + ], $doc->source()); + } + + public function testQueryDocDelegateToNew() + { + $this->assertInstanceOf(Search::class, TestConcreteIndex::query()); + $this->assertInstanceOf(\ElasticKit\Index\Doc::class, TestConcreteIndex::doc(1)); + } + + public function testOnNewQueryChain() + { + $secondaryClient = $this->createMock(TestClient::class); + $secondaryClient->method('search')->willReturn(new ArrayResponse([ + 'hits' => ['total' => ['value' => 1], 'hits' => [['_source' => ['title' => 'from_secondary']]]], + ])); + Index::setClient($secondaryClient, 'secondary'); + + $results = TestConcreteIndex::on('secondary')->newQuery()->matchAll()->get(); + + $this->assertEquals(1, $results->total()); + $this->assertEquals([['title' => 'from_secondary']], $results->docs()); + } + + public function testOnNewDocChain() + { + $secondaryClient = $this->createMock(TestClient::class); + $secondaryClient->method('getSource')->willReturn(new ArrayResponse([ + 'found' => true, + '_source' => ['title' => 'secondary_doc'], + ])); + Index::setClient($secondaryClient, 'secondary'); + + $doc = TestConcreteIndex::on('secondary')->newDoc(42); + + $this->assertEquals([ + 'found' => true, + '_source' => ['title' => 'secondary_doc'], + ], $doc->source()); + } +} + +class TestConcreteIndex extends Index +{ + protected $name = 'test'; } diff --git a/tests/Index/ResultsTest.php b/tests/Index/ResultsTest.php index 40108a1..853b0a4 100644 --- a/tests/Index/ResultsTest.php +++ b/tests/Index/ResultsTest.php @@ -1,12 +1,19 @@ $results->total(), 'page' => $results->page()]; }); @@ -195,9 +202,6 @@ public function testToPaginatorCallsResolver() $paginator = $results->toPaginator(); $this->assertEquals(['total' => 50, 'page' => 2], $paginator); - - // Clean up - Pagination::reset(); } public function testToPaginatorThrowsWithoutResolver() From 6b50541c72c1a4daf8f79f7c8129e7e695f508e8 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Sat, 13 Jun 2026 01:26:06 +0800 Subject: [PATCH 11/24] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E5=BE=85?= =?UTF-8?q?=E5=8A=9E=E2=80=94=E2=80=94=E6=A0=87=E8=AE=B0=E5=B7=B2=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E9=A1=B9=EF=BC=8C=E6=96=B0=E5=A2=9E=20PHP=208=20?= =?UTF-8?q?=E7=8E=B0=E4=BB=A3=E5=8C=96=E3=80=81Rebuild=20=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E5=BE=85=E5=8A=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 3833668..1bd3c95 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -43,8 +43,14 @@ PSR-5 规范。 - [x] **hasMore() 确认无 bug**:scroll 场景 !empty(hits) 正确,分页应用 page() Date: Sat, 13 Jun 2026 01:30:46 +0800 Subject: [PATCH 12/24] =?UTF-8?q?refactor(dsl):=20Shared/=20=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E4=B8=BA=20Support/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DSL/Queries/Compound/Boolean.php | 2 +- src/DSL/Queries/Compound/DisjunctionMax.php | 2 +- src/DSL/Queries/FullText/Intervals/Range.php | 2 +- src/DSL/Queries/Span/SpanNear.php | 2 +- src/DSL/Queries/Span/SpanOr.php | 2 +- src/DSL/Queries/TermLevel/Range.php | 2 +- src/DSL/{Shared => Support}/ClausesSupport.php | 2 +- src/DSL/{Shared => Support}/RangeSupport.php | 2 +- tests/Index/IndexTest.php | 16 ++++------------ 9 files changed, 12 insertions(+), 20 deletions(-) rename src/DSL/{Shared => Support}/ClausesSupport.php (96%) rename src/DSL/{Shared => Support}/RangeSupport.php (97%) diff --git a/src/DSL/Queries/Compound/Boolean.php b/src/DSL/Queries/Compound/Boolean.php index fe6c768..4b142ac 100644 --- a/src/DSL/Queries/Compound/Boolean.php +++ b/src/DSL/Queries/Compound/Boolean.php @@ -2,7 +2,7 @@ namespace ElasticKit\DSL\Queries\Compound; -use ElasticKit\DSL\Shared\ClausesSupport; +use ElasticKit\DSL\Support\ClausesSupport; use ElasticKit\DSL\Node; /** diff --git a/src/DSL/Queries/Compound/DisjunctionMax.php b/src/DSL/Queries/Compound/DisjunctionMax.php index a1bbe34..ec0a92d 100644 --- a/src/DSL/Queries/Compound/DisjunctionMax.php +++ b/src/DSL/Queries/Compound/DisjunctionMax.php @@ -2,7 +2,7 @@ namespace ElasticKit\DSL\Queries\Compound; -use ElasticKit\DSL\Shared\ClausesSupport; +use ElasticKit\DSL\Support\ClausesSupport; use ElasticKit\DSL\Node; /** diff --git a/src/DSL/Queries/FullText/Intervals/Range.php b/src/DSL/Queries/FullText/Intervals/Range.php index f40a01b..9237c3d 100644 --- a/src/DSL/Queries/FullText/Intervals/Range.php +++ b/src/DSL/Queries/FullText/Intervals/Range.php @@ -3,7 +3,7 @@ namespace ElasticKit\DSL\Queries\FullText\Intervals; use ElasticKit\DSL\Node; -use ElasticKit\DSL\Shared\RangeSupport; +use ElasticKit\DSL\Support\RangeSupport; /** * The range rule matches terms that fall within a specified range of values. diff --git a/src/DSL/Queries/Span/SpanNear.php b/src/DSL/Queries/Span/SpanNear.php index aec40fc..eaa8f20 100644 --- a/src/DSL/Queries/Span/SpanNear.php +++ b/src/DSL/Queries/Span/SpanNear.php @@ -2,7 +2,7 @@ namespace ElasticKit\DSL\Queries\Span; -use ElasticKit\DSL\Shared\ClausesSupport; +use ElasticKit\DSL\Support\ClausesSupport; use ElasticKit\DSL\Node; /** diff --git a/src/DSL/Queries/Span/SpanOr.php b/src/DSL/Queries/Span/SpanOr.php index 840aa73..3999878 100644 --- a/src/DSL/Queries/Span/SpanOr.php +++ b/src/DSL/Queries/Span/SpanOr.php @@ -2,7 +2,7 @@ namespace ElasticKit\DSL\Queries\Span; -use ElasticKit\DSL\Shared\ClausesSupport; +use ElasticKit\DSL\Support\ClausesSupport; use ElasticKit\DSL\Node; /** diff --git a/src/DSL/Queries/TermLevel/Range.php b/src/DSL/Queries/TermLevel/Range.php index 892e331..71d191b 100644 --- a/src/DSL/Queries/TermLevel/Range.php +++ b/src/DSL/Queries/TermLevel/Range.php @@ -3,7 +3,7 @@ namespace ElasticKit\DSL\Queries\TermLevel; use ElasticKit\DSL\Node; -use ElasticKit\DSL\Shared\RangeSupport; +use ElasticKit\DSL\Support\RangeSupport; class Range extends Node { diff --git a/src/DSL/Shared/ClausesSupport.php b/src/DSL/Support/ClausesSupport.php similarity index 96% rename from src/DSL/Shared/ClausesSupport.php rename to src/DSL/Support/ClausesSupport.php index ec2224b..a80534e 100644 --- a/src/DSL/Shared/ClausesSupport.php +++ b/src/DSL/Support/ClausesSupport.php @@ -1,6 +1,6 @@ =, >, <=, <) and [start, end] to ES range keys. diff --git a/tests/Index/IndexTest.php b/tests/Index/IndexTest.php index 08b732b..130191f 100644 --- a/tests/Index/IndexTest.php +++ b/tests/Index/IndexTest.php @@ -766,8 +766,7 @@ public function testNewDocUsesInstanceConnection() { $secondaryClient = $this->createMock(TestClient::class); $secondaryClient->method('getSource')->willReturn(new ArrayResponse([ - 'found' => true, - '_source' => ['title' => 'test'], + 'title' => 'test', ])); Index::setClient($secondaryClient, 'secondary'); @@ -776,10 +775,7 @@ public function testNewDocUsesInstanceConnection() $doc = $index->newDoc(1); $this->assertInstanceOf(\ElasticKit\Index\Doc::class, $doc); - $this->assertEquals([ - 'found' => true, - '_source' => ['title' => 'test'], - ], $doc->source()); + $this->assertEquals(['title' => 'test'], $doc->source()); } public function testQueryDocDelegateToNew() @@ -806,17 +802,13 @@ public function testOnNewDocChain() { $secondaryClient = $this->createMock(TestClient::class); $secondaryClient->method('getSource')->willReturn(new ArrayResponse([ - 'found' => true, - '_source' => ['title' => 'secondary_doc'], + 'title' => 'secondary_doc', ])); Index::setClient($secondaryClient, 'secondary'); $doc = TestConcreteIndex::on('secondary')->newDoc(42); - $this->assertEquals([ - 'found' => true, - '_source' => ['title' => 'secondary_doc'], - ], $doc->source()); + $this->assertEquals(['title' => 'secondary_doc'], $doc->source()); } } From 27547e6b3839f5db63d02f4752b6622302af2d9f Mon Sep 17 00:00:00 2001 From: ykan821 Date: Sat, 13 Jun 2026 15:26:02 +0800 Subject: [PATCH 13/24] =?UTF-8?q?refactor(index):=20PHP=208=20=E7=8E=B0?= =?UTF-8?q?=E4=BB=A3=E5=8C=96=EF=BC=88Index=20=E5=B1=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 全 12 文件 declare(strict_types=1) + 构造器属性提升 + readonly + native 属性/返回/参数类型 + 联合类型。 主要变更: - 修复 Manager::resolveIndexName() 空别名映射 null→TypeError(array_key_first() ?? $name) - Doc $id 支持 string|int|null:index/create 省略 id 由 ES 自动生成, get/source/exists/update/delete 用 requireId() 守卫(治住静默发 null id 到 ES 的隐患) - Bulk::execute() 加 json_encode false 守卫(strict_types 下防 strlen(false) TypeError) - callable 属性(resolver/errorHandler/dataSource)保留 docblock(PHP 禁止 callable 作属性类型) 同步:TestConcreteIndex 与 docs 示例属性类型化;CLAUDE.md 待办拆分 Index/DSL 两层。 Co-Authored-By: Claude --- CLAUDE.md | 4 +- README.md | 4 +- docs/guide.md | 4 +- docs/index.md | 8 +-- src/Index/Bulk.php | 53 ++++++++------- src/Index/ClientManager.php | 4 +- src/Index/Doc.php | 121 +++++++++++++++++++++++----------- src/Index/Event.php | 16 +++-- src/Index/EventDispatcher.php | 12 ++-- src/Index/Index.php | 40 +++++------ src/Index/Manager.php | 52 +++++++-------- src/Index/Pagination.php | 16 +++-- src/Index/Rebuild.php | 34 ++++------ src/Index/Results.php | 50 +++++++------- src/Index/Search.php | 49 +++++++------- src/Index/StatsSupport.php | 14 ++-- tests/Index/DocTest.php | 23 +++++++ tests/Index/IndexTest.php | 2 +- 18 files changed, 284 insertions(+), 222 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 1bd3c95..ccffaca 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -48,13 +48,15 @@ PSR-5 规范。 - [x] **实例入口**:新增 on()/newQuery()/newDoc()/setConnection()/getConnection(),query()/doc() 委托实例方法 - [x] **测试 mock 污染修复**:所有测试文件补 tearDown 清理静态状态 - [ ] **命名参数一致性**:公开方法参数名是 API 的一部分,全库审查确保命名统一(如 connection/name/client 不混用) -- [ ] **PHP 8 现代化**:构造器属性提升、属性/返回/参数类型声明、readonly、联合类型 +- [x] **PHP 8 现代化(Index 层)**:全 12 文件 strict_types + 构造器提升 + readonly + 属性/返回/参数类型 + 联合类型;callable 属性(resolver / errorHandler / dataSource)因 PHP 禁止 callable 作属性类型,保留 docblock +- [ ] **PHP 8 现代化(DSL 层)**:Node/Query/Agg + 122 leaf 类。strict_types + 类型声明;`$_key`/`$_valueKey`/`$_isPropertyField`/`$_multi` 4 属性加类型需同步全部 leaf(原子操作,漏一个 fatal),field()/create()/boost()/toArray() 加返回类型需同步所有覆写;`$_properties`/`$_rawValue` 三模式统一留给批次 1 - [ ] **Rebuild 异常处理**:run() 改为 try-catch + releaseLock 分离,releaseLock 不吞任何异常,forceUnlock 单独处理 404(文档不存在 vs 索引不存在的 404 需区分);isLocked() 只吞 404 不吞其他 ClientResponseException;rebuild 失败优先抛原始异常;ensureLockIndex() replicas=0 在多节点集群有风险需注释说明 - [x] **$client 抽到 Registry 类**:拆为 ClientManager / EventDispatcher / Pagination,Index 不再持有静态状态 - [x] **Node 构造函数重构**:拆分为 fromKeyValue/fromClosure/fromArrayField/fromScalar - [x] **Bulk/Rebuild onError 设计**:Bulk 加 onError(callback) 默认 throw,Rebuild 删 skipErrors 加 onError,删 rebuild.import.failed 事件 - [ ] **补核心路径的边界测试**:scroll、bulk 分批、rebuild 失败回滚 - [ ] **搭建集成测试基建**:`ELASTICKIT_TEST_HOST` 驱动,随机索引名隔离 +- [ ] **cursor/chunk API 重构**:现 `cursor()` 返回批次(Results)命名不准。拆为 `chunk($duration): Generator`(按批,即现 cursor 改名)+ `cursor($duration): Generator`(逐条 doc,内部扁平化 chunk、复用其 finally clear);保留 `scroll()/next()/clear()` 作低层原语。待定:单条 yield 完整 hit(带 _id/_score)还是只 _source;底层未来可换 PIT+search_after(上层签名不变) ## 测试 diff --git a/README.md b/README.md index ceffd8f..5f5b1de 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Index::setClient($client); // 2. 定义索引 class ProductIndex extends Index { - protected $name = 'products'; - protected $mappings = [ + protected string $name = 'products'; + protected array $mappings = [ 'properties' => [ 'title' => ['type' => 'text'], 'price' => ['type' => 'float'], diff --git a/docs/guide.md b/docs/guide.md index 543b2de..5cd09ff 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -40,9 +40,9 @@ use Illuminate\Support\Facades\Db; class OrderIndex extends Index { - protected $name = 'orders'; + protected string $name = 'orders'; - protected $mappings = [ + protected array $mappings = [ 'properties' => [ 'order_no' => ['type' => 'keyword'], // 精确匹配 'status' => ['type' => 'keyword'], // pending/paid/shipped/completed diff --git a/docs/index.md b/docs/index.md index 67c38c0..34535b0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,18 +25,18 @@ Index::setClient($logClient, 'logs'); ```php class ProductIndex extends Index { - protected $name = 'products'; // 索引名(必填) - protected $mappings = [ // 索引 mappings + protected string $name = 'products'; // 索引名(必填) + protected array $mappings = [ // 索引 mappings 'properties' => [ 'title' => ['type' => 'text'], 'price' => ['type' => 'float'], 'status' => ['type' => 'keyword'], ], ]; - protected $settings = [ // 索引 settings + protected array $settings = [ // 索引 settings 'number_of_shards' => 1, ]; - protected $connection = 'main'; // 连接名(默认 'default') + protected string $connection = 'main'; // 连接名(默认 'default') public function rebuildName(): string // 重建后的真实索引名(可重写自定义) { diff --git a/src/Index/Bulk.php b/src/Index/Bulk.php index 9001e08..470af0e 100644 --- a/src/Index/Bulk.php +++ b/src/Index/Bulk.php @@ -1,5 +1,7 @@ */ - private $body = []; + private array $body = []; /** * @var int */ - private $retryOnConflict = 0; + private int $retryOnConflict = 0; /** * @var string|null */ - private $targetIndex = null; + private ?string $targetIndex = null; /** * @var int */ - private $batchSize = 0; + private int $batchSize = 0; /** * @var int */ - private $docCount = 0; + private int $docCount = 0; /** * @var callable|null */ private $errorHandler = null; - /** - * @param Index $index - */ - public function __construct(Index $index) - { - $this->index = $index; + public function __construct( + private readonly Index $index + ) { } /** @@ -60,7 +54,7 @@ public function __construct(Index $index) * @return $this * @throws \InvalidArgumentException if indexName starts with a dot (system index) */ - public function target($indexName) + public function target(string $indexName): static { if (strpos($indexName, '.') === 0) { throw new InvalidArgumentException("System index names (starting with '.') are not allowed: {$indexName}"); @@ -77,7 +71,7 @@ public function target($indexName) * @param int $size * @return $this */ - public function batchSize($size) + public function batchSize(int $size): static { $this->batchSize = $size; @@ -94,7 +88,7 @@ public function batchSize($size) * @param callable $handler function (array $response): void * @return $this */ - public function onError($handler) + public function onError(callable $handler): static { $this->errorHandler = $handler; return $this; @@ -106,7 +100,7 @@ public function onError($handler) * @param int $count * @return $this */ - public function retryOnConflict($count) + public function retryOnConflict(int $count): static { $this->retryOnConflict = $count; @@ -120,7 +114,7 @@ public function retryOnConflict($count) * @param array $document * @return $this */ - public function index($id, $document) + public function index(string|int|null $id, array $document): static { $action = ['index' => ['_index' => $this->resolveIndex()]]; if ($id !== null && $id !== '') { @@ -140,7 +134,7 @@ public function index($id, $document) * @param array $document * @return $this */ - public function save($id, $document) + public function save(string|int|null $id, array $document): static { return $this->index($id, $document); } @@ -152,7 +146,7 @@ public function save($id, $document) * @param array $document * @return $this */ - public function create($id, $document) + public function create(string|int $id, array $document): static { $this->body[] = ['create' => ['_index' => $this->resolveIndex(), '_id' => $id]]; $this->body[] = $document; @@ -171,7 +165,7 @@ public function create($id, $document) * @param bool $upsert * @return $this */ - public function update($id, $data, $upsert = false) + public function update(string|int $id, array $data, bool $upsert = false): static { $action = ['update' => ['_index' => $this->resolveIndex(), '_id' => $id]]; @@ -192,7 +186,7 @@ public function update($id, $data, $upsert = false) * @param string|int $id * @return $this */ - public function delete($id) + public function delete(string|int $id): static { $this->body[] = ['delete' => ['_index' => $this->resolveIndex(), '_id' => $id]]; $this->afterPush(); @@ -206,7 +200,7 @@ public function delete($id) * @param array $options top-level bulk API params (refresh, timeout, etc) * @return array */ - public function execute(array $options = []) + public function execute(array $options = []): array { if (empty($this->body)) { return []; @@ -240,6 +234,11 @@ public function execute(array $options = []) ($this->errorHandler)($response); } else { $json = json_encode($response, JSON_UNESCAPED_UNICODE); + // json_encode() can return false on malformed payloads; guard required + // under strict_types to avoid passing false to strlen(). + if ($json === false) { + $json = '(unable to encode bulk response)'; + } if (strlen($json) > 4096) { $json = substr($json, 0, 4096) . '... [truncated]'; } @@ -255,7 +254,7 @@ public function execute(array $options = []) * * @return string */ - private function resolveIndex() + private function resolveIndex(): string { return $this->targetIndex ?? $this->index->name(); } diff --git a/src/Index/ClientManager.php b/src/Index/ClientManager.php index 886b042..ae62175 100644 --- a/src/Index/ClientManager.php +++ b/src/Index/ClientManager.php @@ -1,5 +1,7 @@ */ - private static $clients = []; + private static array $clients = []; /** * Register an Elasticsearch client. Optionally name the connection. diff --git a/src/Index/Doc.php b/src/Index/Doc.php index c5a194f..dd8d2fd 100644 --- a/src/Index/Doc.php +++ b/src/Index/Doc.php @@ -1,48 +1,44 @@ index = $index; - $this->id = $id; + public function __construct( + private readonly Index $index, + private readonly string|int|null $id + ) { } /** * Return the document ID. * - * @return string|int + * @return string|int|null */ - public function id() + public function id(): string|int|null { return $this->id; } @@ -53,7 +49,7 @@ public function id() * @param int $count * @return $this */ - public function retryOnConflict($count) + public function retryOnConflict(int $count): static { $this->retryOnConflict = $count; @@ -66,7 +62,7 @@ public function retryOnConflict($count) * @param string $value * @return $this */ - public function refresh($value) + public function refresh(string $value): static { $this->refresh = $value; @@ -78,11 +74,13 @@ public function refresh($value) * * @return array */ - public function get() + public function get(): array { + $id = $this->requireId('get'); + return $this->index->getClient()->get([ 'index' => $this->index->name(), - 'id' => $this->id, + 'id' => $id, ])->asArray(); } @@ -91,11 +89,13 @@ public function get() * * @return array */ - public function source() + public function source(): array { + $id = $this->requireId('source'); + return $this->index->getClient()->getSource([ 'index' => $this->index->name(), - 'id' => $this->id, + 'id' => $id, ])->asArray(); } @@ -104,11 +104,13 @@ public function source() * * @return bool */ - public function exists() + public function exists(): bool { + $id = $this->requireId('exists'); + return $this->index->getClient()->exists([ 'index' => $this->index->name(), - 'id' => $this->id, + 'id' => $id, ])->asBool(); } @@ -121,11 +123,13 @@ public function exists() * @param bool $upsert * @return array */ - public function update($data, $upsert = false) + public function update(array $data, bool $upsert = false): array { + $id = $this->requireId('update'); + $params = [ 'index' => $this->index->name(), - 'id' => $this->id, + 'id' => $id, 'body' => [ 'doc' => $data, 'doc_as_upsert' => $upsert, @@ -148,17 +152,23 @@ public function update($data, $upsert = false) /** * Index (create or overwrite) the document. * + * If $id is null or empty, ES auto-generates an id. + * * @param array $document * @return array */ - public function index($document) + public function index(array $document): array { $params = [ 'index' => $this->index->name(), - 'id' => $this->id, - 'body' => $document, ]; + if ($this->id !== null && $this->id !== '') { + $params['id'] = $this->id; + } + + $params['body'] = $document; + if ($this->refresh !== null) { $params['refresh'] = $this->refresh; } @@ -174,7 +184,7 @@ public function index($document) * @param array $document * @return array */ - public function save($document) + public function save(array $document): array { return $this->index($document); } @@ -182,18 +192,25 @@ public function save($document) /** * Create the document (fail if already exists). * + * If $id is null or empty, ES auto-generates an id (always a create, since + * auto-generated ids are unique). + * * @param array $document * @return array */ - public function create($document) + public function create(array $document): array { $params = [ 'index' => $this->index->name(), - 'id' => $this->id, - 'body' => $document, - 'op_type' => 'create', ]; + if ($this->id !== null && $this->id !== '') { + $params['id'] = $this->id; + } + + $params['body'] = $document; + $params['op_type'] = 'create'; + if ($this->refresh !== null) { $params['refresh'] = $this->refresh; } @@ -208,11 +225,13 @@ public function create($document) * * @return array */ - public function delete() + public function delete(): array { + $id = $this->requireId('delete'); + $params = [ 'index' => $this->index->name(), - 'id' => $this->id, + 'id' => $id, ]; if ($this->refresh !== null) { @@ -224,6 +243,28 @@ public function delete() return $this->index->getClient()->delete($params)->asArray(); } + /** + * Resolve the document id, throwing for operations that cannot auto-generate. + * + * get/source/exists/update/delete address an existing document and require + * an explicit id; only index/create let ES auto-generate. + * + * @return string|int + * @throws RuntimeException if the id is null or empty + */ + private function requireId(string $operation): string|int + { + if ($this->id === null || $this->id === '') { + throw new RuntimeException(sprintf( + '%s() requires an explicit document id; got null/empty. ' + . 'Use index() or create() to let Elasticsearch auto-generate one.', + $operation + )); + } + + return $this->id; + } + /** * Reset pending options after a write operation. */ diff --git a/src/Index/Event.php b/src/Index/Event.php index 9c250d0..bd8edd1 100644 --- a/src/Index/Event.php +++ b/src/Index/Event.php @@ -1,5 +1,7 @@ */ - private $data = []; + private array $data = []; /** * @param string $name * @param string $index */ - public function __construct($name, $index) + public function __construct(string $name, string $index) { $this->name = $name; $this->index = $index; @@ -47,7 +49,7 @@ public function __construct($name, $index) * @param string $key * @return mixed */ - public function __get($key) + public function __get(string $key): mixed { return $this->data[$key] ?? null; } @@ -56,7 +58,7 @@ public function __get($key) * @param string $key * @param mixed $value */ - public function __set($key, $value) + public function __set(string $key, mixed $value): void { $this->data[$key] = $value; } @@ -65,7 +67,7 @@ public function __set($key, $value) * @param string $key * @return bool */ - public function __isset($key) + public function __isset(string $key): bool { return isset($this->data[$key]); } diff --git a/src/Index/EventDispatcher.php b/src/Index/EventDispatcher.php index e3ac9df..830611b 100644 --- a/src/Index/EventDispatcher.php +++ b/src/Index/EventDispatcher.php @@ -1,5 +1,7 @@ > */ - private static $listeners = []; + private static array $listeners = []; /** * Register an event listener. @@ -21,7 +23,7 @@ class EventDispatcher * @param callable $listener receives (Event $event) * @return void */ - public static function listen($event, callable $listener) + public static function listen(string $event, callable $listener): void { self::$listeners[$event][] = $listener; } @@ -32,7 +34,7 @@ public static function listen($event, callable $listener) * @param Event $event * @return void */ - public static function dispatch(Event $event) + public static function dispatch(Event $event): void { foreach (self::$listeners as $pattern => $listeners) { if ($pattern === $event->name || $pattern === '*' || self::matchesCategory($pattern, $event->name)) { @@ -48,7 +50,7 @@ public static function dispatch(Event $event) * * @return void */ - public static function reset() + public static function reset(): void { self::$listeners = []; } @@ -60,7 +62,7 @@ public static function reset() * @param string $event * @return bool */ - private static function matchesCategory($pattern, $event) + private static function matchesCategory(string $pattern, string $event): bool { if (substr($pattern, -2) !== '.*') { return false; diff --git a/src/Index/Index.php b/src/Index/Index.php index 0dd9854..a7c9c98 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -1,5 +1,7 @@ */ - protected $mappings = []; + protected array $mappings = []; /** * @var array */ - protected $settings = []; + protected array $settings = []; /** * @var int */ - protected $perPage = 15; + protected int $perPage = 15; /** * @var int */ - protected $maxPerPage = 100; + protected int $maxPerPage = 100; /** * Register an Elasticsearch client. Optionally name the connection. @@ -72,7 +74,7 @@ public function getClient(): ClientInterface * @param string $connection * @return $this */ - public function setConnection(string $connection) + public function setConnection(string $connection): static { $this->connection = $connection; @@ -95,7 +97,7 @@ public function getConnection(): string * @param string $connection * @return static */ - public static function on(string $connection) + public static function on(string $connection): static { return (new static())->setConnection($connection); } @@ -105,7 +107,7 @@ public static function on(string $connection) * * @return string */ - public function name() + public function name(): string { if (empty($this->name)) { throw new RuntimeException( @@ -122,7 +124,7 @@ public function name() * @param Query|null $query * @return Search */ - public function newQuery(Query $query = null) + public function newQuery(?Query $query = null): Search { return new Search($this, $query); } @@ -133,7 +135,7 @@ public function newQuery(Query $query = null) * @param Query|null $query * @return Search */ - public static function query(Query $query = null) + public static function query(?Query $query = null): Search { return (new static())->newQuery($query); } @@ -141,10 +143,10 @@ public static function query(Query $query = null) /** * Create a Doc reference from this index instance. * - * @param string|int $id + * @param string|int|null $id document id, or null/'' to let ES auto-generate * @return Doc */ - public function newDoc($id) + public function newDoc(string|int|null $id): Doc { return new Doc($this, $id); } @@ -152,10 +154,10 @@ public function newDoc($id) /** * Create a Doc reference. Delegates to newDoc() with a fresh instance. * - * @param string|int $id + * @param string|int|null $id document id, or null/'' to let ES auto-generate * @return Doc */ - public static function doc($id) + public static function doc(string|int|null $id): Doc { return (new static())->newDoc($id); } @@ -165,7 +167,7 @@ public static function doc($id) * * @return array */ - public function mappings() + public function mappings(): array { return $this->mappings; } @@ -175,7 +177,7 @@ public function mappings() * * @return array */ - public function settings() + public function settings(): array { return $this->settings; } @@ -195,7 +197,7 @@ public function rebuildName(): string * * @return int */ - public function perPage() + public function perPage(): int { return $this->perPage; } @@ -205,7 +207,7 @@ public function perPage() * * @return int */ - public function maxPerPage() + public function maxPerPage(): int { return $this->maxPerPage; } diff --git a/src/Index/Manager.php b/src/Index/Manager.php index 00ee232..1d6054e 100644 --- a/src/Index/Manager.php +++ b/src/Index/Manager.php @@ -1,5 +1,7 @@ index = $index; + public function __construct( + private readonly Index $index + ) { } /** @@ -31,7 +25,7 @@ public function __construct(Index $index) * * @return array */ - public function create() + public function create(): array { $indexName = $this->index->name(); @@ -61,7 +55,7 @@ public function create() * * @return array */ - public function delete() + public function delete(): array { $indexName = $this->resolveIndexName(); @@ -84,7 +78,7 @@ public function delete() * * @return bool */ - public function exists() + public function exists(): bool { return $this->index->getClient()->indices()->exists([ 'index' => $this->index->name(), @@ -96,7 +90,7 @@ public function exists() * * @return array */ - public function get() + public function get(): array { return $this->index->getClient()->indices()->get([ 'index' => $this->index->name(), @@ -108,7 +102,7 @@ public function get() * * @return array */ - public function putMapping() + public function putMapping(): array { return $this->index->getClient()->indices()->putMapping([ 'index' => $this->index->name(), @@ -121,7 +115,7 @@ public function putMapping() * * @return array */ - public function getMapping() + public function getMapping(): array { return $this->index->getClient()->indices()->getMapping([ 'index' => $this->index->name(), @@ -134,7 +128,7 @@ public function getMapping() * @param array $settings * @return array */ - public function putSettings(array $settings) + public function putSettings(array $settings): array { return $this->index->getClient()->indices()->putSettings([ 'index' => $this->index->name(), @@ -147,7 +141,7 @@ public function putSettings(array $settings) * * @return array */ - public function getSettings() + public function getSettings(): array { return $this->index->getClient()->indices()->getSettings([ 'index' => $this->index->name(), @@ -159,7 +153,7 @@ public function getSettings() * * @return array */ - public function refresh() + public function refresh(): array { return $this->index->getClient()->indices()->refresh([ 'index' => $this->index->name(), @@ -172,7 +166,7 @@ public function refresh() * @param array $options ES params: max_num_segments, only_expunge_deletes, flush. * @return array */ - public function forceMerge(array $options = []) + public function forceMerge(array $options = []): array { return $this->index->getClient()->indices()->forcemerge( array_merge(['index' => $this->index->name()], $options) @@ -184,7 +178,7 @@ public function forceMerge(array $options = []) * * @return array */ - public function close() + public function close(): array { return $this->index->getClient()->indices()->close([ 'index' => $this->index->name(), @@ -196,7 +190,7 @@ public function close() * * @return array */ - public function open() + public function open(): array { return $this->index->getClient()->indices()->open([ 'index' => $this->index->name(), @@ -211,7 +205,7 @@ public function open() * @param array $options additional alias options: routing, filter, is_write_index. * @return array */ - public function addAlias($alias, array $options = []) + public function addAlias(string $alias, array $options = []): array { $indexName = $this->resolveIndexName(); @@ -234,7 +228,7 @@ public function addAlias($alias, array $options = []) * @param string $alias * @return array */ - public function removeAlias($alias) + public function removeAlias(string $alias): array { $indexName = $this->resolveIndexName(); @@ -251,7 +245,7 @@ public function removeAlias($alias) * @param string $fromIndex * @return array */ - public function swapAlias($alias, $fromIndex) + public function swapAlias(string $alias, string $fromIndex): array { $indexName = $this->index->name(); @@ -280,7 +274,7 @@ public function swapAlias($alias, $fromIndex) * * @return array */ - public function getAliases() + public function getAliases(): array { $indexName = $this->resolveIndexName(); @@ -294,14 +288,14 @@ public function getAliases() * * @return string */ - private function resolveIndexName() + private function resolveIndexName(): string { $name = $this->index->name(); $client = $this->index->getClient()->indices(); if ($client->existsAlias(['name' => $name])->asBool()) { $aliases = $client->getAlias(['name' => $name])->asArray(); - return array_key_first($aliases); + return array_key_first($aliases) ?? $name; } return $name; diff --git a/src/Index/Pagination.php b/src/Index/Pagination.php index 9a933b3..7474381 100644 --- a/src/Index/Pagination.php +++ b/src/Index/Pagination.php @@ -1,5 +1,7 @@ >|null */ private $dataSource; - /** - * @param Index $index - */ - public function __construct(Index $index) - { - $this->index = $index; + public function __construct( + private readonly Index $index + ) { } /** @@ -58,7 +52,7 @@ public function __construct(Index $index) * @param int $size * @return $this */ - public function batchSize($size) + public function batchSize(int $size): static { $this->batchSize = $size; return $this; @@ -74,7 +68,7 @@ public function batchSize($size) * @param callable $handler function (array $response): void * @return $this */ - public function onError($handler) + public function onError(callable $handler): static { $this->errorHandler = $handler; return $this; @@ -86,7 +80,7 @@ public function onError($handler) * @param bool $allow * @return $this */ - public function allowEmpty($allow = true) + public function allowEmpty(bool $allow = true): static { $this->allowEmpty = $allow; return $this; @@ -99,7 +93,7 @@ public function allowEmpty($allow = true) * @param callable|\Iterator> $source * @return $this */ - public function source($source) + public function source($source): static { $this->dataSource = $source; return $this; @@ -116,7 +110,7 @@ public function source($source) * @param array $context user-defined context passed to source() * @return array{newIndex: string, oldIndex: string|null} */ - public function run(array $context = []) + public function run(array $context = []): array { $this->acquireLock(); @@ -344,7 +338,7 @@ private function ensureLockIndex(): void * * @return string the new backing index name */ - protected function createIndex() + protected function createIndex(): string { $newName = $this->index->rebuildName(); $mappings = $this->index->mappings(); @@ -367,7 +361,7 @@ protected function createIndex() * @param string $newName * @param array $context */ - protected function import($newName, array $context): void + protected function import(string $newName, array $context): void { if ($this->dataSource !== null) { $items = is_callable($this->dataSource) ? ($this->dataSource)($context) : $this->dataSource; diff --git a/src/Index/Results.php b/src/Index/Results.php index 5216d1b..18bc275 100644 --- a/src/Index/Results.php +++ b/src/Index/Results.php @@ -1,5 +1,7 @@ */ - protected $response; + protected array $response; /** * @var int */ - protected $page = 1; + protected int $page = 1; /** * @var int */ - protected $perPage = 15; + protected int $perPage = 15; /** * @var bool */ - protected $paginated = false; + protected bool $paginated = false; /** * @param array $response @@ -44,7 +46,7 @@ public function __construct(array $response) * @param int $perPage * @return $this */ - public function paginate($page, $perPage) + public function paginate(int $page, int $perPage): static { $this->page = $page; $this->perPage = $perPage; @@ -57,7 +59,7 @@ public function paginate($page, $perPage) * * @return int */ - public function total() + public function total(): int { return $this->response['hits']['total']['value'] ?? 0; } @@ -67,7 +69,7 @@ public function total() * * @return array> */ - public function hits() + public function hits(): array { return $this->response['hits']['hits'] ?? []; } @@ -77,7 +79,7 @@ public function hits() * * @return array|null> */ - public function docs() + public function docs(): array { return array_column($this->hits(), '_source'); } @@ -87,7 +89,7 @@ public function docs() * * @return array */ - public function ids() + public function ids(): array { return array_column($this->hits(), '_id'); } @@ -97,7 +99,7 @@ public function ids() * * @return array|null */ - public function first() + public function first(): ?array { $docs = $this->docs(); return $docs[0] ?? null; @@ -108,7 +110,7 @@ public function first() * * @return array|null */ - public function aggregations() + public function aggregations(): ?array { return $this->response['aggregations'] ?? null; } @@ -118,7 +120,7 @@ public function aggregations() * * @return string|null */ - public function scrollId() + public function scrollId(): ?string { return $this->response['_scroll_id'] ?? null; } @@ -128,11 +130,11 @@ public function scrollId() * * "eq" = total is exact, "gte" = total is a lower bound. * - * @return string "eq" or "gte" + * @return string|null "eq" or "gte" */ - public function totalRelation() + public function totalRelation(): ?string { - return $this->response['hits']['total']['relation']; + return $this->response['hits']['total']['relation'] ?? null; } /** @@ -140,7 +142,7 @@ public function totalRelation() * * @return bool */ - public function hasMore() + public function hasMore(): bool { return !empty($this->response['hits']['hits']); } @@ -150,7 +152,7 @@ public function hasMore() * * @return int */ - public function took() + public function took(): int { return $this->response['took'] ?? 0; } @@ -160,7 +162,7 @@ public function took() * * @return bool */ - public function timedOut() + public function timedOut(): bool { return $this->response['timed_out'] ?? false; } @@ -170,7 +172,7 @@ public function timedOut() * * @return array */ - public function raw() + public function raw(): array { return $this->response; } @@ -180,7 +182,7 @@ public function raw() * * @return int */ - public function page() + public function page(): int { return $this->page; } @@ -190,7 +192,7 @@ public function page() * * @return int */ - public function perPage() + public function perPage(): int { return $this->perPage; } @@ -200,7 +202,7 @@ public function perPage() * * @return int */ - public function lastPage() + public function lastPage(): int { return (int) ceil($this->total() / $this->perPage) ?: 1; } @@ -210,7 +212,7 @@ public function lastPage() * * @return array|null> */ - public function items() + public function items(): array { return $this->docs(); } @@ -220,7 +222,7 @@ public function items() * * @return bool */ - public function isEmpty() + public function isEmpty(): bool { return empty($this->response['hits']['hits']); } diff --git a/src/Index/Search.php b/src/Index/Search.php index c275c2a..88b78c8 100644 --- a/src/Index/Search.php +++ b/src/Index/Search.php @@ -1,5 +1,7 @@ */ - private $urlParams = []; + private array $urlParams = []; - /** - * @param Index $index - */ - public function __construct(Index $index, Query $query = null) - { + public function __construct( + private readonly Index $index, + ?Query $query = null + ) { $this->query = $query ?? new Query(); - $this->index = $index; } /** @@ -46,7 +41,7 @@ public function __construct(Index $index, Query $query = null) * @param string $routing * @return $this */ - public function routing($routing) + public function routing(string $routing): static { $this->urlParams['routing'] = $routing; return $this; @@ -57,10 +52,10 @@ public function routing($routing) * * @param string $method * @param array $args - * @return $this|mixed + * @return mixed * @throws BadMethodCallException */ - public function __call($method, $args) + public function __call(string $method, array $args): mixed { if (!method_exists($this->query, $method)) { throw new BadMethodCallException( @@ -82,7 +77,7 @@ public function __call($method, $args) * * @return Results */ - public function get() + public function get(): Results { return new Results($this->doSearch('get')); } @@ -92,7 +87,7 @@ public function get() * * @return array|null */ - public function first() + public function first(): ?array { $saved = $this->query; $this->query = clone $this->query; @@ -112,7 +107,7 @@ public function first() * * @return int */ - public function count() + public function count(): int { $response = $this->doCount(); @@ -130,7 +125,7 @@ public function count() * @param string $duration * @return Results */ - public function scroll($scrollId = null, $duration = '5m') + public function scroll(?string $scrollId = null, string $duration = '5m'): Results { if ($scrollId !== null) { return $this->doScroll($scrollId, $duration); @@ -159,7 +154,7 @@ public function scroll($scrollId = null, $duration = '5m') * @param string $duration * @return Results */ - public function next(Results $results, $duration = '5m') + public function next(Results $results, string $duration = '5m'): Results { return $this->doScroll($results->scrollId(), $duration); } @@ -170,7 +165,7 @@ public function next(Results $results, $duration = '5m') * @param Results $results * @return void */ - public function clear(Results $results) + public function clear(Results $results): void { $scrollId = $results->scrollId(); if ($scrollId !== null) { @@ -187,7 +182,7 @@ public function clear(Results $results) * @param string $duration * @return Results */ - protected function doScroll($scrollId, $duration) + protected function doScroll(string $scrollId, string $duration): Results { $indexName = $this->index->name(); @@ -220,7 +215,7 @@ protected function doScroll($scrollId, $duration) * @param string $duration * @return \Generator */ - public function cursor($duration = '5m') + public function cursor(string $duration = '5m'): \Generator { $results = $this->scroll(null, $duration); @@ -241,7 +236,7 @@ public function cursor($duration = '5m') * @param int|null $perPage * @return Results */ - public function paginate($page = null, $perPage = null) + public function paginate(?int $page = null, ?int $perPage = null): Results { if ($page === null && $perPage === null) { $resolver = Pagination::getPageResolver(); @@ -276,7 +271,7 @@ public function paginate($page = null, $perPage = null) * * @return array */ - protected function doCount() + protected function doCount(): array { $indexName = $this->index->name(); $body = $this->query->toArray() ?: new stdClass(); @@ -311,7 +306,7 @@ protected function doCount() * @param array $extra extra request params (e.g. scroll) * @return array */ - protected function doSearch($action, array $extra = []) + protected function doSearch(string $action, array $extra = []): array { $indexName = $this->index->name(); $body = $this->query->toArray() ?: new stdClass(); diff --git a/src/Index/StatsSupport.php b/src/Index/StatsSupport.php index 0d09a0b..f25627e 100644 --- a/src/Index/StatsSupport.php +++ b/src/Index/StatsSupport.php @@ -1,5 +1,7 @@ aggregateScalar('max', $field); } @@ -24,7 +26,7 @@ public function max($field) * @param string $field * @return float|null */ - public function min($field) + public function min(string $field): ?float { return $this->aggregateScalar('min', $field); } @@ -35,7 +37,7 @@ public function min($field) * @param string $field * @return float|null */ - public function avg($field) + public function avg(string $field): ?float { return $this->aggregateScalar('avg', $field); } @@ -46,7 +48,7 @@ public function avg($field) * @param string $field * @return float|null */ - public function sum($field) + public function sum(string $field): ?float { return $this->aggregateScalar('sum', $field); } @@ -57,7 +59,7 @@ public function sum($field) * @param string $field * @return array{count: int, min: float|null, max: float|null, avg: float|null, sum: float|null}|null */ - public function stats($field) + public function stats(string $field): ?array { $saved = $this->query; $this->query = clone $this->query; @@ -90,7 +92,7 @@ public function stats($field) * @param string $field * @return float|null */ - private function aggregateScalar($type, $field) + private function aggregateScalar(string $type, string $field): ?float { $saved = $this->query; $this->query = clone $this->query; diff --git a/tests/Index/DocTest.php b/tests/Index/DocTest.php index 7b3058f..949fac1 100644 --- a/tests/Index/DocTest.php +++ b/tests/Index/DocTest.php @@ -331,4 +331,27 @@ public function testDeleteWithRefresh() $index = $this->createIndex('products'); $index->doc('1')->refresh('wait_for')->delete(); } + + public function testIndexAutoGeneratesIdWhenEmpty() + { + $client = $this->createMock(TestClient::class); + $client->expects($this->once()) + ->method('index') + ->with(['index' => 'products', 'body' => ['title' => 'foo']]) + ->willReturn(new ArrayResponse(['result' => 'created', '_id' => 'auto'])); + Index::setClient($client); + + $index = $this->createIndex('products'); + $result = $index->newDoc(null)->index(['title' => 'foo']); + + $this->assertEquals('created', $result['result']); + } + + public function testUpdateRequiresExplicitId() + { + $index = $this->createIndex('products'); + + $this->expectException(\RuntimeException::class); + $index->newDoc(null)->update(['title' => 'foo']); + } } diff --git a/tests/Index/IndexTest.php b/tests/Index/IndexTest.php index 130191f..f6cb55e 100644 --- a/tests/Index/IndexTest.php +++ b/tests/Index/IndexTest.php @@ -814,5 +814,5 @@ public function testOnNewDocChain() class TestConcreteIndex extends Index { - protected $name = 'test'; + protected string $name = 'test'; } From 933240c794e7e7511f14106e6146c386cb2c81b5 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Sat, 13 Jun 2026 15:55:14 +0800 Subject: [PATCH 14/24] =?UTF-8?q?docs:=20=E7=A7=BB=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E6=96=87=E4=BB=B6=E5=B9=B6=E6=B8=85=E7=90=86=20README?= =?UTF-8?q?=207.x=20=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- README.md | 3 +- docs/upgrade.md | 94 -------- ...07\345\215\227\350\247\204\345\210\222.md" | 225 ------------------ 3 files changed, 1 insertion(+), 321 deletions(-) delete mode 100644 docs/upgrade.md delete mode 100644 "docs/\345\256\236\346\210\230\346\214\207\345\215\227\350\247\204\345\210\222.md" diff --git a/README.md b/README.md index 5f5b1de..29d9ed8 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ PHP Elasticsearch DSL 查询构建库,覆盖查询、聚合、CRUD、批量写 composer require ykan/elastickit:^8 ``` -> 需要 PHP 8.1+、Elasticsearch 8.x。依赖 `elasticsearch-php` 自动安装。ES 7.x 用户见 [7.x 分支](https://github.com/ykan821/ElasticKit/tree/7.x)。 +> 需要 PHP 8.1+、Elasticsearch 8.x。依赖 `elasticsearch-php` 自动安装。 ## 快速开始 @@ -277,7 +277,6 @@ ProductIndex::listen('search.*', function (Event $e) { - [实践指南](docs/guide.md)——电商订单场景,从安装到上线的完整流程 - [Index 文档](docs/index.md)——搜索、CRUD、批量操作、零停机重建、事件 -- [升级指南](docs/upgrade.md)——v7.x → v8.x 迁移说明 - [更新日志](CHANGELOG.md) - [Elasticsearch 官方文档](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html)——查询类型和参数参考 diff --git a/docs/upgrade.md b/docs/upgrade.md deleted file mode 100644 index 66ec6d0..0000000 --- a/docs/upgrade.md +++ /dev/null @@ -1,94 +0,0 @@ -# 升级指南 - -## v7.x → v8.x - -### 环境要求 - -| | v7.x | v8.x | -|---|---|---| -| PHP | 7.2+ | **8.1+** | -| Elasticsearch | 7.x | **8.x** | -| elasticsearch-php | ^7.0 | **^8.0** | - -```bash -composer require ykan/elastickit:^8 -``` - -### Client 配置 - -命名空间从 `Elasticsearch\` 变更为 `Elastic\Elasticsearch\`: - -```php -// v7.x -$client = \Elasticsearch\ClientBuilder::create() - ->setHosts(['http://localhost:9200']) - ->build(); - -// v8.x -$client = \Elastic\Elasticsearch\ClientBuilder::create() - ->setHosts(['https://localhost:9200']) - ->setBasicAuthentication('elastic', 'password') - ->build(); -``` - -> ES 8.x 默认启用安全认证(TLS + 认证)。需使用 `https://` 并提供凭据。 - -### 不兼容变更 - -**1. 自定义 Client** - -`Client` 现在是 `final` 类——不可继承。使用 `ClientBuilder` 配置代替: - -```php -// v7.x — 继承 Client 自定义 -class MyClient extends \Elasticsearch\Client { ... } - -// v8.x — 通过 ClientBuilder 配置 -$client = \Elastic\Elasticsearch\ClientBuilder::create() - ->setHosts([...]) - ->setLogger($logger) - ->setSSLVerification(false) - ->build(); -``` - -**2. 响应对象** - -elasticsearch-php 8.x 返回 Response 对象而非数组。ElasticKit 内部已处理——Index 层所有方法(search、get、bulk 等)仍返回数组。**用户代码无需修改。** - -如果你在 ElasticKit 之外直接使用 elasticsearch-php 客户端: - -```php -// v7.x — 返回数组 -$response = $client->search($params); -$total = $response['hits']['total']['value']; - -// v8.x — 返回 Response 对象,使用 asArray() -$response = $client->search($params); -$total = $response['hits']['total']['value']; // ArrayAccess 仍可读取 -$total = $response->asArray()['hits']['total']['value']; // 显式转换 -``` - -**3. GeoPolygon 查询** - -`geo_polygon` 查询在 ES 8.x 中已移除。使用 `geo_shape` 代替: - -```php -// v7.x -$query->geoPolygon('location', $points); - -// v8.x -$query->geoShape('location', function ($s) { - $s->shape($polygon, 'envelope'); -}); -``` - -### 无需修改 - -以下在 v7.x 和 v8.x 中完全一致: - -- DSL 查询构建(match、term、bool、range 等) -- 聚合构建 -- Index 层所有 API(Search、Doc、Bulk、Manager、Rebuild) -- 事件系统 -- `Query::make()`、`Agg::make()`、`Query::when()` -- Index 子类定义($name、$mappings、$settings) diff --git "a/docs/\345\256\236\346\210\230\346\214\207\345\215\227\350\247\204\345\210\222.md" "b/docs/\345\256\236\346\210\230\346\214\207\345\215\227\350\247\204\345\210\222.md" deleted file mode 100644 index de3d7c6..0000000 --- "a/docs/\345\256\236\346\210\230\346\214\207\345\215\227\350\247\204\345\210\222.md" +++ /dev/null @@ -1,225 +0,0 @@ -# 实战指南规划 - -以电商订单系统为例,展示 ElasticKit 在真实业务中的完整使用流程。 - -> 灵感来源:真实生产环境的 ES 集成经验,简化后用于教学。 - -## 场景设定 - -电商后台,订单数据分散在多张表,需要搜索、筛选、统计、导出。核心需求: - -- **订单列表**:按状态、日期、金额、品类筛选,支持搜索订单号/商品名 -- **统计看板**:按月/品类统计销售额,按商家分组 -- **数据导出**:筛选结果批量导出 Excel -- **实时同步**:数据库变更后 ES 自动更新 - -### 技术难点 - -1. **数据分散在多张表**(订单 + 用户 + 商品 + 商家),写入时必须关联组装 -2. **订单有嵌套明细**(items),ES 用 nested 类型存储 -3. **筛选条件多且动态**(10+ 个可选条件),需要灵活的条件构建器 -4. **统计和列表要联动**(同一组条件,既要分页列表又要聚合数据) -5. **数据一致性**(数据库更新后 ES 必须同步,处理冲突重试) - ---- - -## 踩坑记录 - -> 从生产环境提炼。只收录非显而易见的实战教训,ES 基础知识不在此列。 - -### 数据建模 - -**1. nested 要慎重** - -nested 查询比普通字段慢很多。真实项目中用了 nested 存流水明细,后来条件查询改成了平铺字段,放弃了嵌套查询。教训:**如果不需要对嵌套文档做独立筛选,就不要用 nested**,平铺即可。 - -### 查询 - -**2. 聚合 N+1 反模式** - -多组统计数据(如按不同状态分别求和)不要发 N 次查询。用一次查询 + 多个 `filter` 聚合桶,或 `aggs()` 嵌套聚合。真实项目账单统计发了 11 次查询,其实可以合并为 1 次。 - -**3. 深分页 10000 限制** - -ES 默认 `max_result_window = 10000`。应对: - -- 用户翻页:限制最大页数 -- 批量导出:用 `cursor()`(scroll API) -- 注意 `chunk()` 如果内部用 from/size,同样受限 - -### 增量同步 - -**4. 队列投递要延迟** - -ORM afterSave 触发时,MySQL 事务可能还没提交。队列 job 立即执行会读到旧数据。解决:延迟投递,等事务提交。 - -**5. 队列 job 不要先删除再执行** - -先删除任务再执行 ES 更新,失败时任务就丢了。正确:执行成功后再删除。 - -**6. Bulk API 不支持 retry_on_conflict** - -ES 单文档 update 支持 `retry_on_conflict`,但 Bulk API 的 update action 不支持。并发写入版本冲突只能靠应用层重试。ElasticKit 的 `Bulk::retryOnConflict()` 封装了这个参数。 - -**7. 间接关联更新** - -商品改名了,订单里的 `product_name` 也要改。但订单 source() 查的是订单表,不是商品表。解决:商品变更 → 查关联订单 ID → 批量更新订单文档。 - -``` -商品表变更 → SELECT id FROM 订单表 WHERE product_id = ? → source(['ids' => $ids]) → Bulk update -``` - -**8. doc_as_upsert 默认策略** - -更新时统一用 `doc_as_upsert: true`(不存在则插入,存在则更新),避免区分 insert/update 两种逻辑。 - -**9. Canal 配置技巧** - -- **字段过滤**:只监听业务字段,忽略 `updated_at` 等无关变更 -- **事件过滤**:只监听 UPDATE,忽略 INSERT/DELETE -- **去重**:同一批次内相同文档 ID 合并,避免重复入队 - -### 数据一致性 - -**10. 一致性校验是必要的** - -不管同步多完善,总会丢数据(进程崩溃、网络超时、冲突重试耗尽)。定时对比 DB 和 ES 关键字段,不一致就修复。真实项目每小时跑一次。 - ---- - -## 阶段规划 - -### 阶段 1:安装与配置 - -**业务背景**:项目立项,先把 ES 连上。 - -**内容**: -- composer 安装 -- 注册 ES Client(Laravel ServiceProvider) -- 验证连接 - ---- - -### 阶段 2:设计索引 - -**业务背景**:订单数据分散在 4 张表,ES 不支持 join,写入时关联组装。 - -**内容**: -- OrderIndex 类定义 -- mappings 设计:基本字段 + nested(订单明细)+ 关联字段(用户/商家/品类) -- `source()` 方法:多表 join 组装文档数据 -- 增量查询支持:`source(['ids' => [...]])` - -**踩坑提醒**:坑 1(nested 慎重) - -**索引字段**(简化版,保留核心模式): - -``` -基本字段:id, order_no, user_id, merchant_id, status, total_amount, - paid_at, created_at, is_cancelled - -关联字段(写入时从其他表组装):user_name, merchant_name, category_name - -嵌套文档:items (product_id, product_name, price, quantity) -``` - ---- - -### 阶段 3:首次导入 - -**业务背景**:索引设计好了,把现有数据灌进去。 - -**内容**: -- Rebuild::run() 全量导入 -- batchSize 调优 -- 查看结果验证 - ---- - -### 阶段 4:搜索与筛选 - -**业务背景**:运营要一个订单查询页面,条件多且动态。 - -**内容**: -- 条件构建器模式(从真实代码提炼) -- `term`(精确匹配)/ `terms`(多值匹配)/ `range`(日期范围)/ `wildcard`(模糊搜索) -- `bool should` 实现多字段 OR 搜索 -- `when()` 条件查询 -- 分页与排序 - -**踩坑提醒**:坑 3(深分页限制) - ---- - -### 阶段 5:聚合统计 - -**业务背景**:管理看板需要按月/品类统计销售额,筛选条件和列表页联动。 - -**内容**: -- 聚合 + 列表一次查询(同一条件,`size(0)` 只取聚合) -- terms 桶聚合:按品类分组 -- date_histogram:按月分组,带时区和补零 -- stats/sum:金额统计 -- 嵌套聚合:品类 → 月份 → 销售额合计 - -**踩坑提醒**:坑 2(聚合 N+1) - ---- - -### 阶段 6:增量同步 - -**业务背景**:数据持续变更(发货、退款、改价),ES 要跟着更新。 - -**内容**: -- 同步流程:数据变更 → 提取 doc_ids → source(['ids']) 取最新数据 → Bulk update -- 队列投递与延迟 -- 冲突重试 -- 间接关联更新(商品改名 → 关联订单全部更新) -- doc_as_upsert 默认策略 - -**踩坑提醒**:坑 4-9 全部涉及 - ---- - -### 阶段 7:Schema 演进 - -**业务背景**:产品要加字段(如新增"配送方式"),需要修改 mapping。 - -**内容**: -- 新增可空字段:`putMapping()` 直接加 -- Breaking 变更(改字段类型、改分词器):必须 Rebuild -- 修改 `source()` 配合新字段 -- Rebuild 完整流程 - ---- - -### 阶段 8:监控与数据一致性 - -**业务背景**:上线后要监控搜索性能和同步延迟。 - -**内容**: -- 慢查询日志(事件监听) -- 数据一致性校验:定时对比 DB 和 ES 关键字段,不一致则重新入队 - -**踩坑提醒**:坑 10(一致性校验) - ---- - -## 覆盖的 ElasticKit 特性 - -| 阶段 | 特性 | -|---|---| -| 1 | 安装、注册 Client | -| 2 | Index 定义、mappings、nested、source()、multi-table join | -| 3 | Rebuild::run()、Bulk、别名切换 | -| 4 | term/terms/range/wildcard/bool/when、分页、排序 | -| 5 | aggs/terms/stats/dateHistogram、嵌套聚合 | -| 6 | Bulk update、source(['ids'])、冲突重试 | -| 7 | putMapping、Rebuild(schema 变更) | -| 8 | 事件监听、数据校验 | - -## 不在指南范围内的 - -- Canal/binlog 监听部署(属于基础设施) -- Laravel Queue 配置(属于框架知识) -- ES 集群调优(属于运维范畴) From 3809dcec16a9e169e6c560a936f274e3ba744ecd Mon Sep 17 00:00:00 2001 From: ykan821 Date: Mon, 15 Jun 2026 22:49:27 +0800 Subject: [PATCH 15/24] =?UTF-8?q?refactor(dsl):=20PHP=208=20=E7=8E=B0?= =?UTF-8?q?=E4=BB=A3=E5=8C=96=E4=B8=8E=E5=86=97=E4=BD=99=E6=B8=85=E7=90=86?= =?UTF-8?q?=EF=BC=88DSL=20=E5=B1=82=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - strict_types 全 151 文件;$_key/$_valueKey/$_fieldKeyed/$_multi 4 原子属性 类型同步全部 leaf;leaf 参数类型对照 ES docblock 补齐 - $_properties 统一为 ?array,新增 $_raw 承接整体透传 - $_isPropertyField → $_fieldKeyed,统一命名风格(与 $_multi 对齐) - 删 setMulti 死方法(Node/Query),multi() 统一承担 - 删 30 个与基类等价的 field() override,保留 Highlight - AdjacencyMatrix/Composite 清理冗余属性与 toArray,序列化下沉 resolveProperties Co-Authored-By: Claude --- CLAUDE.md | 2 +- src/DSL/Agg.php | 34 +++--- src/DSL/Aggs/Bucket.php | 2 + src/DSL/Aggs/Bucket/AdjacencyMatrix.php | 44 ++----- src/DSL/Aggs/Bucket/AutoDateHistogram.php | 14 ++- src/DSL/Aggs/Bucket/CategorizeText.php | 22 ++-- src/DSL/Aggs/Bucket/Composite.php | 40 ++----- src/DSL/Aggs/Bucket/DateHistogram.php | 28 ++--- src/DSL/Aggs/Bucket/DateRange.php | 25 ++-- src/DSL/Aggs/Bucket/DiversifiedSampler.php | 10 +- src/DSL/Aggs/Bucket/FilterAgg.php | 12 +- src/DSL/Aggs/Bucket/Filters.php | 10 +- src/DSL/Aggs/Bucket/FrequentItemSets.php | 12 +- src/DSL/Aggs/Bucket/GeoDistance.php | 25 ++-- src/DSL/Aggs/Bucket/GeoHashGrid.php | 21 +--- src/DSL/Aggs/Bucket/GeohexGrid.php | 21 +--- src/DSL/Aggs/Bucket/GeotileGrid.php | 21 +--- src/DSL/Aggs/Bucket/GlobalAgg.php | 4 +- src/DSL/Aggs/Bucket/Histogram.php | 35 +++--- src/DSL/Aggs/Bucket/IpPrefix.php | 17 +-- src/DSL/Aggs/Bucket/IpRange.php | 21 +--- src/DSL/Aggs/Bucket/Missing.php | 17 +-- src/DSL/Aggs/Bucket/MultiTerms.php | 18 +-- src/DSL/Aggs/Bucket/Nested.php | 8 +- src/DSL/Aggs/Bucket/ParentAgg.php | 6 +- src/DSL/Aggs/Bucket/RandomSampler.php | 19 +--- src/DSL/Aggs/Bucket/Range.php | 23 ++-- src/DSL/Aggs/Bucket/RareTerms.php | 25 ++-- src/DSL/Aggs/Bucket/ReverseNested.php | 6 +- src/DSL/Aggs/Bucket/SignificantTerms.php | 31 ++--- src/DSL/Aggs/Bucket/SignificantText.php | 31 ++--- src/DSL/Aggs/Bucket/Terms.php | 37 +++--- src/DSL/Aggs/Bucket/TimeSeries.php | 19 +--- .../Aggs/Bucket/VariableWidthHistogram.php | 17 +-- src/DSL/Aggs/Metric.php | 2 + src/DSL/Aggs/Metric/Avg.php | 23 ++-- src/DSL/Aggs/Metric/Cardinality.php | 25 ++-- src/DSL/Aggs/Metric/ExtendedStats.php | 25 ++-- src/DSL/Aggs/Metric/Max.php | 23 ++-- src/DSL/Aggs/Metric/Min.php | 23 ++-- src/DSL/Aggs/Metric/Stats.php | 23 ++-- src/DSL/Aggs/Metric/Sum.php | 23 ++-- src/DSL/Aggs/Metric/ValueCount.php | 19 +--- src/DSL/Aggs/Pipeline.php | 2 + src/DSL/Aggs/Pipeline/AvgBucket.php | 14 ++- src/DSL/Aggs/Pipeline/BucketScript.php | 12 +- src/DSL/Aggs/Pipeline/CumulativeSum.php | 8 +- src/DSL/Aggs/Pipeline/Derivative.php | 12 +- src/DSL/Aggs/Pipeline/MaxBucket.php | 14 ++- src/DSL/Aggs/Pipeline/MinBucket.php | 14 ++- src/DSL/Aggs/Pipeline/StatsBucket.php | 14 ++- src/DSL/Aggs/Pipeline/SumBucket.php | 14 ++- src/DSL/Node.php | 107 ++++++++++-------- src/DSL/Param.php | 14 ++- src/DSL/Params/Collapse.php | 23 ++-- src/DSL/Params/Highlight.php | 38 ++++--- src/DSL/Params/Knn.php | 37 +++--- src/DSL/Params/Rescore.php | 16 +-- src/DSL/Params/Suggest.php | 10 +- src/DSL/Queries/Compound.php | 2 + src/DSL/Queries/Compound/Boolean.php | 16 +-- src/DSL/Queries/Compound/Boosting.php | 10 +- src/DSL/Queries/Compound/ConstantScore.php | 6 +- src/DSL/Queries/Compound/DisjunctionMax.php | 8 +- src/DSL/Queries/Compound/FunctionScore.php | 34 +++--- src/DSL/Queries/Compound/Functions/Exp.php | 22 ++-- .../Compound/Functions/FieldValueFactor.php | 23 ++-- .../Queries/Compound/Functions/Function_.php | 40 +++---- src/DSL/Queries/Compound/Functions/Gauss.php | 22 ++-- src/DSL/Queries/Compound/Functions/Linear.php | 22 ++-- .../Compound/Functions/RandomScore.php | 19 +--- .../Compound/Functions/ScriptScore.php | 8 +- src/DSL/Queries/FullText.php | 2 + src/DSL/Queries/FullText/CombinedFields.php | 18 +-- src/DSL/Queries/FullText/Intervals.php | 22 ++-- src/DSL/Queries/FullText/Intervals/AllOf.php | 18 +-- src/DSL/Queries/FullText/Intervals/AnyOf.php | 14 ++- src/DSL/Queries/FullText/Intervals/Filter.php | 22 ++-- src/DSL/Queries/FullText/Intervals/Fuzzy.php | 18 +-- src/DSL/Queries/FullText/Intervals/Match_.php | 16 +-- src/DSL/Queries/FullText/Intervals/Prefix.php | 10 +- src/DSL/Queries/FullText/Intervals/Range.php | 32 +++--- .../Queries/FullText/Intervals/Wildcard.php | 10 +- src/DSL/Queries/FullText/MatchBoolPrefix.php | 32 +++--- src/DSL/Queries/FullText/MatchPhrase.php | 16 +-- .../Queries/FullText/MatchPhrasePrefix.php | 18 +-- src/DSL/Queries/FullText/Match_.php | 38 ++++--- src/DSL/Queries/FullText/MultiMatch.php | 42 +++---- src/DSL/Queries/FullText/QueryString.php | 54 ++++----- .../Queries/FullText/SimpleQueryString.php | 32 +++--- src/DSL/Queries/Geo.php | 2 + src/DSL/Queries/Geo/GeoBoundingBox.php | 28 ++--- src/DSL/Queries/Geo/GeoDistance.php | 16 +-- src/DSL/Queries/Geo/GeoGrid.php | 12 +- src/DSL/Queries/Geo/GeoPolygon.php | 12 +- src/DSL/Queries/Geo/GeoShape.php | 14 ++- src/DSL/Queries/Joining.php | 2 + src/DSL/Queries/Joining/HasChild.php | 16 +-- src/DSL/Queries/Joining/HasParent.php | 12 +- src/DSL/Queries/Joining/Nested.php | 14 ++- src/DSL/Queries/Joining/ParentId.php | 10 +- src/DSL/Queries/MatchAll.php | 2 + src/DSL/Queries/MatchAll/MatchAll.php | 4 +- src/DSL/Queries/MatchAll/MatchNone.php | 4 +- src/DSL/Queries/Script.php | 20 ++-- src/DSL/Queries/Shape.php | 2 + src/DSL/Queries/Shape/Shape.php | 12 +- src/DSL/Queries/Span.php | 2 + src/DSL/Queries/Span/SpanContaining.php | 8 +- src/DSL/Queries/Span/SpanFieldMasking.php | 17 +-- src/DSL/Queries/Span/SpanFirst.php | 8 +- src/DSL/Queries/Span/SpanMulti.php | 6 +- src/DSL/Queries/Span/SpanNear.php | 10 +- src/DSL/Queries/Span/SpanNot.php | 14 ++- src/DSL/Queries/Span/SpanOr.php | 6 +- src/DSL/Queries/Span/SpanTerm.php | 14 ++- src/DSL/Queries/Span/SpanWithin.php | 8 +- src/DSL/Queries/Specialized.php | 2 + .../Queries/Specialized/DistanceFeature.php | 10 +- src/DSL/Queries/Specialized/MoreLikeThis.php | 12 +- src/DSL/Queries/Specialized/Percolate.php | 6 +- src/DSL/Queries/Specialized/Pinned.php | 10 +- src/DSL/Queries/Specialized/RankFeature.php | 12 +- src/DSL/Queries/Specialized/Script.php | 6 +- src/DSL/Queries/Specialized/ScriptScore.php | 10 +- src/DSL/Queries/Specialized/Wrapper.php | 8 +- src/DSL/Queries/TermLevel.php | 2 + src/DSL/Queries/TermLevel/Exists.php | 4 +- src/DSL/Queries/TermLevel/Fuzzy.php | 20 ++-- src/DSL/Queries/TermLevel/IDs.php | 6 +- src/DSL/Queries/TermLevel/Prefix.php | 12 +- src/DSL/Queries/TermLevel/Range.php | 36 +++--- src/DSL/Queries/TermLevel/Regexp.php | 16 +-- src/DSL/Queries/TermLevel/Term.php | 12 +- src/DSL/Queries/TermLevel/Terms.php | 10 +- src/DSL/Queries/TermLevel/TermsSet.php | 20 ++-- src/DSL/Queries/TermLevel/Wildcard.php | 14 ++- src/DSL/Query.php | 38 +++---- src/DSL/Support/ClausesSupport.php | 2 + src/DSL/Support/RangeSupport.php | 2 + tests/DslTestCase.php | 2 +- 141 files changed, 1151 insertions(+), 1254 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index ccffaca..75b1dc9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -49,7 +49,7 @@ PSR-5 规范。 - [x] **测试 mock 污染修复**:所有测试文件补 tearDown 清理静态状态 - [ ] **命名参数一致性**:公开方法参数名是 API 的一部分,全库审查确保命名统一(如 connection/name/client 不混用) - [x] **PHP 8 现代化(Index 层)**:全 12 文件 strict_types + 构造器提升 + readonly + 属性/返回/参数类型 + 联合类型;callable 属性(resolver / errorHandler / dataSource)因 PHP 禁止 callable 作属性类型,保留 docblock -- [ ] **PHP 8 现代化(DSL 层)**:Node/Query/Agg + 122 leaf 类。strict_types + 类型声明;`$_key`/`$_valueKey`/`$_isPropertyField`/`$_multi` 4 属性加类型需同步全部 leaf(原子操作,漏一个 fatal),field()/create()/boost()/toArray() 加返回类型需同步所有覆写;`$_properties`/`$_rawValue` 三模式统一留给批次 1 +- [x] **PHP 8 现代化(DSL 层)**:Node/Query/Agg + 122 leaf 类全部完成。strict_types 全 151 文件;4 原子属性类型同步全 leaf;leaf 参数类型对照 ES docblock 完成;`$_properties` 三模式统一为 `?array`(新增 `$_raw` 承接整体透传,null 保留为合法空态);`toJson` 加 `:string` + false 检查;`toArray` 因多态返回(array/stdClass/null)不强加 PHP 返回类型 - [ ] **Rebuild 异常处理**:run() 改为 try-catch + releaseLock 分离,releaseLock 不吞任何异常,forceUnlock 单独处理 404(文档不存在 vs 索引不存在的 404 需区分);isLocked() 只吞 404 不吞其他 ClientResponseException;rebuild 失败优先抛原始异常;ensureLockIndex() replicas=0 在多节点集群有风险需注释说明 - [x] **$client 抽到 Registry 类**:拆为 ClientManager / EventDispatcher / Pagination,Index 不再持有静态状态 - [x] **Node 构造函数重构**:拆分为 fromKeyValue/fromClosure/fromArrayField/fromScalar diff --git a/src/DSL/Agg.php b/src/DSL/Agg.php index cb7c565..79a2aaa 100644 --- a/src/DSL/Agg.php +++ b/src/DSL/Agg.php @@ -1,5 +1,7 @@ */ - protected $subAggs = []; + protected array $subAggs = []; /** - * Properties for array-based aggregation definitions. - * Supports nested Query, Node, and Agg instances (resolved by resolveProperties). + * Properties for array-based aggregation definitions (raw DSL mode). + * Null when the aggregation is node-based or empty. * * @var array|null */ - protected $_properties; + protected ?array $_properties = null; /** * Static factory — thin proxy over the constructor. @@ -56,7 +54,7 @@ class Agg * @param mixed $agg * @return static */ - public static function create($agg = []) + public static function create($agg = []): static { if ($agg instanceof static) { return $agg; @@ -83,7 +81,7 @@ public static function create($agg = []) * @param Node $node * @return $this */ - protected function node($node) + protected function node($node): static { $this->_node = $node; $this->_properties = null; @@ -99,7 +97,7 @@ protected function node($node) * @param string $alias * @return $this */ - public function alias($alias) + public function alias($alias): static { $this->_alias = $alias; return $this; @@ -128,7 +126,7 @@ public function getAlias() * @return $this * @throws \BadMethodCallException if called with a string alias and no definition */ - public function aggs($alias, $aggs = null) + public function aggs($alias, $aggs = null): static { if ($aggs === null && !is_string($alias)) { $aggs = $alias; @@ -236,9 +234,11 @@ public function toArray() * @param int $depth * @return string */ - public function toJson($flags = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT, $depth = 512) + public function toJson(int $flags = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT, int $depth = 512): string { - return json_encode($this->toArray(), $flags, $depth); + $json = json_encode($this->toArray(), $flags, $depth); + + return $json === false ? '' : $json; } /** @@ -246,7 +246,7 @@ public function toJson($flags = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT, $dep * * @return string */ - public function __toString() + public function __toString(): string { return $this->toJson(); } diff --git a/src/DSL/Aggs/Bucket.php b/src/DSL/Aggs/Bucket.php index e31eb30..b9336c1 100644 --- a/src/DSL/Aggs/Bucket.php +++ b/src/DSL/Aggs/Bucket.php @@ -1,5 +1,7 @@ */ - protected $_filters; + protected string $_key = 'adjacency_matrix'; /** - * Filters used to create buckets. + * Add a named filter used to create buckets. * * @param string $key * @param mixed $query * @return static */ - public function filters($key, $query) + public function filters($key, $query): static { - $this->_filters[$key] = Query::create($query); - return $this->addProperty('filters', $this->_filters); + $this->_properties ??= []; + $this->_properties['filters'][$key] = Query::create($query); + return $this; } /** @@ -37,31 +34,8 @@ public function filters($key, $query) * @param string $separator * @return static */ - public function separator($separator) + public function separator(string $separator): static { return $this->addProperty('separator', $separator); } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $properties = $this->_properties; - - if (isset($properties['filters'])) { - foreach ($properties['filters'] as $key => $filter) { - if ($filter instanceof Query) { - $properties['filters'][$key] = $filter->toArray()['query']; - } - } - } - - $properties = $this->resolveProperties($properties); - - if ($this->_isPropertyField) { - return [$this->_field => $properties]; - } - return $properties; - } } diff --git a/src/DSL/Aggs/Bucket/AutoDateHistogram.php b/src/DSL/Aggs/Bucket/AutoDateHistogram.php index f2c1172..aa9fa77 100644 --- a/src/DSL/Aggs/Bucket/AutoDateHistogram.php +++ b/src/DSL/Aggs/Bucket/AutoDateHistogram.php @@ -1,5 +1,7 @@ addProperty('buckets', $buckets); } @@ -28,7 +30,7 @@ public function buckets($buckets) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } @@ -39,7 +41,7 @@ public function format($format) * @param string $timeZone * @return static */ - public function timeZone($timeZone) + public function timeZone(string $timeZone): static { return $this->addProperty('time_zone', $timeZone); } @@ -50,7 +52,7 @@ public function timeZone($timeZone) * @param string $minimumInterval * @return static */ - public function minimumInterval($minimumInterval) + public function minimumInterval(string $minimumInterval): static { return $this->addProperty('minimum_interval', $minimumInterval); } @@ -61,7 +63,7 @@ public function minimumInterval($minimumInterval) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Bucket/CategorizeText.php b/src/DSL/Aggs/Bucket/CategorizeText.php index c54f088..09f74e8 100644 --- a/src/DSL/Aggs/Bucket/CategorizeText.php +++ b/src/DSL/Aggs/Bucket/CategorizeText.php @@ -1,5 +1,7 @@ addProperty('categorization_analyzer', $categorizationAnalyzer); } @@ -28,7 +30,7 @@ public function categorizationAnalyzer($categorizationAnalyzer) * @param array $categorizationFilters * @return static */ - public function categorizationFilters($categorizationFilters) + public function categorizationFilters(array $categorizationFilters): static { return $this->addProperty('categorization_filters', $categorizationFilters); } @@ -39,7 +41,7 @@ public function categorizationFilters($categorizationFilters) * @param int $maxMatchedTokens * @return static */ - public function maxMatchedTokens($maxMatchedTokens) + public function maxMatchedTokens(int $maxMatchedTokens): static { return $this->addProperty('max_matched_tokens', $maxMatchedTokens); } @@ -50,7 +52,7 @@ public function maxMatchedTokens($maxMatchedTokens) * @param int $maxUniqueTokens * @return static */ - public function maxUniqueTokens($maxUniqueTokens) + public function maxUniqueTokens(int $maxUniqueTokens): static { return $this->addProperty('max_unique_tokens', $maxUniqueTokens); } @@ -61,7 +63,7 @@ public function maxUniqueTokens($maxUniqueTokens) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -72,7 +74,7 @@ public function minDocCount($minDocCount) * @param int $shardMinDocCount * @return static */ - public function shardMinDocCount($shardMinDocCount) + public function shardMinDocCount(int $shardMinDocCount): static { return $this->addProperty('shard_min_doc_count', $shardMinDocCount); } @@ -83,7 +85,7 @@ public function shardMinDocCount($shardMinDocCount) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } @@ -94,7 +96,7 @@ public function shardSize($shardSize) * @param float $similarityThreshold * @return static */ - public function similarityThreshold($similarityThreshold) + public function similarityThreshold(float $similarityThreshold): static { return $this->addProperty('similarity_threshold', $similarityThreshold); } @@ -105,7 +107,7 @@ public function similarityThreshold($similarityThreshold) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } diff --git a/src/DSL/Aggs/Bucket/Composite.php b/src/DSL/Aggs/Bucket/Composite.php index 681ef95..c3a57ae 100644 --- a/src/DSL/Aggs/Bucket/Composite.php +++ b/src/DSL/Aggs/Bucket/Composite.php @@ -1,5 +1,7 @@ addProperty('sources', $sources); } @@ -32,7 +30,7 @@ public function sources($sources) * @param mixed $after * @return static */ - public function after($after) + public function after($after): static { return $this->addProperty('after', $after); } @@ -43,7 +41,7 @@ public function after($after) * @param mixed $order * @return static */ - public function order($order) + public function order($order): static { return $this->addProperty('order', $order); } @@ -54,32 +52,8 @@ public function order($order) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } - - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.IfStatementAssignment) - */ - public function toArray() - { - $properties = $this->_properties; - - if (isset($properties['sources'])) { - foreach ($properties['sources'] as $key => $source) { - if (($item = current($source)) instanceof Node) { - $properties['sources'][$key] = $item->toArray(); - } - } - } - - $properties = $this->resolveProperties($properties); - - if ($this->_isPropertyField) { - return [$this->_field => $properties]; - } - return $properties; - } } diff --git a/src/DSL/Aggs/Bucket/DateHistogram.php b/src/DSL/Aggs/Bucket/DateHistogram.php index 2e1d01b..e95c988 100644 --- a/src/DSL/Aggs/Bucket/DateHistogram.php +++ b/src/DSL/Aggs/Bucket/DateHistogram.php @@ -1,5 +1,7 @@ addProperty('calendar_interval', $calendarInterval); } @@ -28,7 +30,7 @@ public function calendarInterval($calendarInterval) * @param string $interval * @return static */ - public function interval($interval) + public function interval(string $interval): static { return $this->addProperty('interval', $interval); } @@ -39,7 +41,7 @@ public function interval($interval) * @param string $fixedInterval * @return static */ - public function fixedInterval($fixedInterval) + public function fixedInterval(string $fixedInterval): static { return $this->addProperty('fixed_interval', $fixedInterval); } @@ -50,7 +52,7 @@ public function fixedInterval($fixedInterval) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } @@ -61,7 +63,7 @@ public function format($format) * @param string $timeZone * @return static */ - public function timeZone($timeZone) + public function timeZone(string $timeZone): static { return $this->addProperty('time_zone', $timeZone); } @@ -72,7 +74,7 @@ public function timeZone($timeZone) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -83,7 +85,7 @@ public function minDocCount($minDocCount) * @param mixed $extendedBounds * @return static */ - public function extendedBounds($extendedBounds) + public function extendedBounds($extendedBounds): static { return $this->addProperty('extended_bounds', $extendedBounds); } @@ -94,7 +96,7 @@ public function extendedBounds($extendedBounds) * @param mixed $hardBounds * @return static */ - public function hardBounds($hardBounds) + public function hardBounds($hardBounds): static { return $this->addProperty('hard_bounds', $hardBounds); } @@ -105,7 +107,7 @@ public function hardBounds($hardBounds) * @param mixed $order * @return static */ - public function order($order) + public function order($order): static { return $this->addProperty('order', $order); } @@ -116,7 +118,7 @@ public function order($order) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } @@ -127,7 +129,7 @@ public function keyed($keyed) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } @@ -138,7 +140,7 @@ public function missing($missing) * @param string $offset * @return static */ - public function offset($offset) + public function offset(string $offset): static { return $this->addProperty('offset', $offset); } diff --git a/src/DSL/Aggs/Bucket/DateRange.php b/src/DSL/Aggs/Bucket/DateRange.php index e7a6638..cd19739 100644 --- a/src/DSL/Aggs/Bucket/DateRange.php +++ b/src/DSL/Aggs/Bucket/DateRange.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'date_range'; /** * Array of range definitions for bucketing. @@ -28,7 +19,7 @@ public function field($field) * @param array $ranges * @return static */ - public function ranges($ranges) + public function ranges(array $ranges): static { return $this->addProperty('ranges', $ranges); } @@ -39,7 +30,7 @@ public function ranges($ranges) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } @@ -50,7 +41,7 @@ public function keyed($keyed) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } @@ -61,7 +52,7 @@ public function format($format) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } @@ -72,7 +63,7 @@ public function missing($missing) * @param string $timeZone * @return static */ - public function timeZone($timeZone) + public function timeZone(string $timeZone): static { return $this->addProperty('time_zone', $timeZone); } diff --git a/src/DSL/Aggs/Bucket/DiversifiedSampler.php b/src/DSL/Aggs/Bucket/DiversifiedSampler.php index 781676d..d50f4b7 100644 --- a/src/DSL/Aggs/Bucket/DiversifiedSampler.php +++ b/src/DSL/Aggs/Bucket/DiversifiedSampler.php @@ -1,5 +1,7 @@ addProperty('shard_size', $shardSize); } @@ -28,7 +30,7 @@ public function shardSize($shardSize) * @param int $maxDocsPerValue * @return static */ - public function maxDocsPerValue($maxDocsPerValue) + public function maxDocsPerValue(int $maxDocsPerValue): static { return $this->addProperty('max_docs_per_value', $maxDocsPerValue); } @@ -39,7 +41,7 @@ public function maxDocsPerValue($maxDocsPerValue) * @param string $executionHint * @return static */ - public function executionHint($executionHint) + public function executionHint(string $executionHint): static { return $this->addProperty('execution_hint', $executionHint); } diff --git a/src/DSL/Aggs/Bucket/FilterAgg.php b/src/DSL/Aggs/Bucket/FilterAgg.php index f2c8f54..630b2d8 100644 --- a/src/DSL/Aggs/Bucket/FilterAgg.php +++ b/src/DSL/Aggs/Bucket/FilterAgg.php @@ -1,5 +1,7 @@ _properties = $filter; + $this->_raw = $filter; return $this; } @@ -31,6 +33,6 @@ public function setFilter($filter) */ public function toArray() { - return Query::create($this->_properties)->toArray()['query']; + return Query::create($this->_raw)->toArray()['query']; } } diff --git a/src/DSL/Aggs/Bucket/Filters.php b/src/DSL/Aggs/Bucket/Filters.php index e6502f8..33282d8 100644 --- a/src/DSL/Aggs/Bucket/Filters.php +++ b/src/DSL/Aggs/Bucket/Filters.php @@ -1,5 +1,7 @@ addProperty('filters', $filters); } @@ -28,7 +30,7 @@ public function filters($filters) * @param string $otherBucketKey * @return static */ - public function otherBucketKey($otherBucketKey) + public function otherBucketKey(string $otherBucketKey): static { return $this->addProperty('other_bucket_key', $otherBucketKey); } @@ -39,7 +41,7 @@ public function otherBucketKey($otherBucketKey) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } diff --git a/src/DSL/Aggs/Bucket/FrequentItemSets.php b/src/DSL/Aggs/Bucket/FrequentItemSets.php index a5c944e..7fd11af 100644 --- a/src/DSL/Aggs/Bucket/FrequentItemSets.php +++ b/src/DSL/Aggs/Bucket/FrequentItemSets.php @@ -1,5 +1,7 @@ addProperty('minimum_set_size', $minimumSetSize); } @@ -28,7 +30,7 @@ public function minimumSetSize($minimumSetSize) * @param array $fields * @return static */ - public function fields($fields) + public function fields(array $fields): static { return $this->addProperty('fields', $fields); } @@ -39,7 +41,7 @@ public function fields($fields) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -50,7 +52,7 @@ public function size($size) * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { return $this->addProperty('filter', $filter); } diff --git a/src/DSL/Aggs/Bucket/GeoDistance.php b/src/DSL/Aggs/Bucket/GeoDistance.php index 3e6dcdd..8e05b02 100644 --- a/src/DSL/Aggs/Bucket/GeoDistance.php +++ b/src/DSL/Aggs/Bucket/GeoDistance.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'geo_distance'; /** * The central geo point from which distances are measured. @@ -28,7 +19,7 @@ public function field($field) * @param mixed $origin * @return static */ - public function origin($origin) + public function origin($origin): static { return $this->addProperty('origin', $origin); } @@ -39,7 +30,7 @@ public function origin($origin) * @param string $unit * @return static */ - public function unit($unit) + public function unit(string $unit): static { return $this->addProperty('unit', $unit); } @@ -50,7 +41,7 @@ public function unit($unit) * @param string $distanceType * @return static */ - public function distanceType($distanceType) + public function distanceType(string $distanceType): static { return $this->addProperty('distance_type', $distanceType); } @@ -61,7 +52,7 @@ public function distanceType($distanceType) * @param array $ranges * @return static */ - public function ranges($ranges) + public function ranges(array $ranges): static { return $this->addProperty('ranges', $ranges); } @@ -72,7 +63,7 @@ public function ranges($ranges) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } diff --git a/src/DSL/Aggs/Bucket/GeoHashGrid.php b/src/DSL/Aggs/Bucket/GeoHashGrid.php index 6933f99..15b75b6 100644 --- a/src/DSL/Aggs/Bucket/GeoHashGrid.php +++ b/src/DSL/Aggs/Bucket/GeoHashGrid.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'geohash_grid'; /** * Geohash precision (length) for grid cells. @@ -28,7 +19,7 @@ public function field($field) * @param int $precision * @return static */ - public function precision($precision) + public function precision(int $precision): static { return $this->addProperty('precision', $precision); } @@ -39,7 +30,7 @@ public function precision($precision) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -50,7 +41,7 @@ public function size($size) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } diff --git a/src/DSL/Aggs/Bucket/GeohexGrid.php b/src/DSL/Aggs/Bucket/GeohexGrid.php index fa8b446..d8ad854 100644 --- a/src/DSL/Aggs/Bucket/GeohexGrid.php +++ b/src/DSL/Aggs/Bucket/GeohexGrid.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'geohex_grid'; /** * H3 resolution for grid cells. @@ -28,7 +19,7 @@ public function field($field) * @param int $precision * @return static */ - public function precision($precision) + public function precision(int $precision): static { return $this->addProperty('precision', $precision); } @@ -39,7 +30,7 @@ public function precision($precision) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -50,7 +41,7 @@ public function size($size) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } diff --git a/src/DSL/Aggs/Bucket/GeotileGrid.php b/src/DSL/Aggs/Bucket/GeotileGrid.php index 6f60cec..2e95403 100644 --- a/src/DSL/Aggs/Bucket/GeotileGrid.php +++ b/src/DSL/Aggs/Bucket/GeotileGrid.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'geotile_grid'; /** * Zoom level (precision) for geotile grid cells. @@ -28,7 +19,7 @@ public function field($field) * @param int $precision * @return static */ - public function precision($precision) + public function precision(int $precision): static { return $this->addProperty('precision', $precision); } @@ -39,7 +30,7 @@ public function precision($precision) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -50,7 +41,7 @@ public function size($size) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } diff --git a/src/DSL/Aggs/Bucket/GlobalAgg.php b/src/DSL/Aggs/Bucket/GlobalAgg.php index 9fd6f86..7d581d2 100644 --- a/src/DSL/Aggs/Bucket/GlobalAgg.php +++ b/src/DSL/Aggs/Bucket/GlobalAgg.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'histogram'; /** * Interval size for each bucket. @@ -28,7 +19,7 @@ public function field($field) * @param float $interval * @return static */ - public function interval($interval) + public function interval(float $interval): static { return $this->addProperty('interval', $interval); } @@ -39,7 +30,7 @@ public function interval($interval) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -50,7 +41,7 @@ public function minDocCount($minDocCount) * @param mixed $bounds * @return static */ - public function extendedBounds($bounds) + public function extendedBounds($bounds): static { return $this->addProperty('extended_bounds', $bounds); } @@ -61,7 +52,7 @@ public function extendedBounds($bounds) * @param mixed $order * @return static */ - public function order($order) + public function order($order): static { return $this->addProperty('order', $order); } @@ -72,7 +63,7 @@ public function order($order) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } @@ -83,7 +74,7 @@ public function keyed($keyed) * @param float $missing * @return static */ - public function missing($missing) + public function missing(float $missing): static { return $this->addProperty('missing', $missing); } @@ -94,7 +85,7 @@ public function missing($missing) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } @@ -105,7 +96,7 @@ public function format($format) * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } @@ -116,7 +107,7 @@ public function script($script) * @param float $offset * @return static */ - public function offset($offset) + public function offset(float $offset): static { return $this->addProperty('offset', $offset); } @@ -127,7 +118,7 @@ public function offset($offset) * @param mixed $hardBounds * @return static */ - public function hardBounds($hardBounds) + public function hardBounds($hardBounds): static { return $this->addProperty('hard_bounds', $hardBounds); } diff --git a/src/DSL/Aggs/Bucket/IpPrefix.php b/src/DSL/Aggs/Bucket/IpPrefix.php index 8d90deb..b59655b 100644 --- a/src/DSL/Aggs/Bucket/IpPrefix.php +++ b/src/DSL/Aggs/Bucket/IpPrefix.php @@ -1,21 +1,14 @@ addProperty('field', $field); - } + protected string $_key = 'ip_prefix'; /** * Length of the network prefix. @@ -23,7 +16,7 @@ public function field($field) * @param int $length * @return static */ - public function prefixLength($length) + public function prefixLength(int $length): static { return $this->addProperty('prefix_length', $length); } @@ -32,7 +25,7 @@ public function prefixLength($length) * @param int $length * @return static */ - public function minPrefixLength($length) + public function minPrefixLength(int $length): static { return $this->addProperty('min_prefix_length', $length); } diff --git a/src/DSL/Aggs/Bucket/IpRange.php b/src/DSL/Aggs/Bucket/IpRange.php index 46661ec..3ca179b 100644 --- a/src/DSL/Aggs/Bucket/IpRange.php +++ b/src/DSL/Aggs/Bucket/IpRange.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'ip_range'; /** * Array of IP range definitions for bucketing. @@ -28,7 +19,7 @@ public function field($field) * @param array $ranges * @return static */ - public function ranges($ranges) + public function ranges(array $ranges): static { return $this->addProperty('ranges', $ranges); } @@ -39,7 +30,7 @@ public function ranges($ranges) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } @@ -50,7 +41,7 @@ public function keyed($keyed) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Bucket/Missing.php b/src/DSL/Aggs/Bucket/Missing.php index bea6610..5da5b46 100644 --- a/src/DSL/Aggs/Bucket/Missing.php +++ b/src/DSL/Aggs/Bucket/Missing.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'missing'; /** * Value to treat as missing for the field. @@ -28,7 +19,7 @@ public function field($field) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Bucket/MultiTerms.php b/src/DSL/Aggs/Bucket/MultiTerms.php index 4d3859d..15d73bb 100644 --- a/src/DSL/Aggs/Bucket/MultiTerms.php +++ b/src/DSL/Aggs/Bucket/MultiTerms.php @@ -1,18 +1,20 @@ addProperty('terms', $terms, true); } @@ -21,7 +23,7 @@ public function terms($terms) * @param mixed $order * @return static */ - public function order($order) + public function order($order): static { return $this->addProperty('order', $order); } @@ -30,7 +32,7 @@ public function order($order) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -39,7 +41,7 @@ public function size($size) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } @@ -48,7 +50,7 @@ public function shardSize($shardSize) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -57,7 +59,7 @@ public function minDocCount($minDocCount) * @param int $shardMinDocCount * @return static */ - public function shardMinDocCount($shardMinDocCount) + public function shardMinDocCount(int $shardMinDocCount): static { return $this->addProperty('shard_min_doc_count', $shardMinDocCount); } @@ -66,7 +68,7 @@ public function shardMinDocCount($shardMinDocCount) * @param string $collectMode * @return static */ - public function collectMode($collectMode) + public function collectMode(string $collectMode): static { return $this->addProperty('collect_mode', $collectMode); } diff --git a/src/DSL/Aggs/Bucket/Nested.php b/src/DSL/Aggs/Bucket/Nested.php index d30200b..2c69bad 100644 --- a/src/DSL/Aggs/Bucket/Nested.php +++ b/src/DSL/Aggs/Bucket/Nested.php @@ -1,5 +1,7 @@ addProperty('path', $path); } @@ -28,7 +30,7 @@ public function path($path) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Aggs/Bucket/ParentAgg.php b/src/DSL/Aggs/Bucket/ParentAgg.php index b60e61b..c3a0cfd 100644 --- a/src/DSL/Aggs/Bucket/ParentAgg.php +++ b/src/DSL/Aggs/Bucket/ParentAgg.php @@ -1,5 +1,7 @@ addProperty('type', $type); } diff --git a/src/DSL/Aggs/Bucket/RandomSampler.php b/src/DSL/Aggs/Bucket/RandomSampler.php index de1b946..03a93f6 100644 --- a/src/DSL/Aggs/Bucket/RandomSampler.php +++ b/src/DSL/Aggs/Bucket/RandomSampler.php @@ -1,5 +1,7 @@ addProperty('probability', $probability); } @@ -28,19 +30,8 @@ public function probability($probability) * @param int $seed * @return static */ - public function seed($seed) + public function seed(int $seed): static { return $this->addProperty('seed', $seed); } - - /** - * Field used to maintain consistent random ordering across shards. - * - * @param string $field - * @return static - */ - public function field($field) - { - return $this->addProperty('field', $field); - } } diff --git a/src/DSL/Aggs/Bucket/Range.php b/src/DSL/Aggs/Bucket/Range.php index b488c66..24b2acf 100644 --- a/src/DSL/Aggs/Bucket/Range.php +++ b/src/DSL/Aggs/Bucket/Range.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'range'; /** * Array of range definitions for bucketing. @@ -28,7 +19,7 @@ public function field($field) * @param array $ranges * @return static */ - public function ranges($ranges) + public function ranges(array $ranges): static { return $this->addProperty('ranges', $ranges); } @@ -39,7 +30,7 @@ public function ranges($ranges) * @param bool $keyed * @return static */ - public function keyed($keyed) + public function keyed(bool $keyed): static { return $this->addProperty('keyed', $keyed); } @@ -50,7 +41,7 @@ public function keyed($keyed) * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } @@ -61,7 +52,7 @@ public function script($script) * @param float $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Bucket/RareTerms.php b/src/DSL/Aggs/Bucket/RareTerms.php index 55d678e..f89e835 100644 --- a/src/DSL/Aggs/Bucket/RareTerms.php +++ b/src/DSL/Aggs/Bucket/RareTerms.php @@ -1,27 +1,20 @@ addProperty('field', $field); - } + protected string $_key = 'rare_terms'; /** * @param int $maxDocCount * @return static */ - public function maxDocCount($maxDocCount) + public function maxDocCount(int $maxDocCount): static { return $this->addProperty('max_doc_count', $maxDocCount); } @@ -30,7 +23,7 @@ public function maxDocCount($maxDocCount) * @param mixed $precision * @return static */ - public function precision($precision) + public function precision($precision): static { return $this->addProperty('precision', $precision); } @@ -39,7 +32,7 @@ public function precision($precision) * @param mixed $include * @return static */ - public function include($include) + public function include($include): static { return $this->addProperty('include', $include); } @@ -48,7 +41,7 @@ public function include($include) * @param mixed $exclude * @return static */ - public function exclude($exclude) + public function exclude($exclude): static { return $this->addProperty('exclude', $exclude); } @@ -57,7 +50,7 @@ public function exclude($exclude) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } @@ -66,7 +59,7 @@ public function missing($missing) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } diff --git a/src/DSL/Aggs/Bucket/ReverseNested.php b/src/DSL/Aggs/Bucket/ReverseNested.php index ca434eb..b8c0292 100644 --- a/src/DSL/Aggs/Bucket/ReverseNested.php +++ b/src/DSL/Aggs/Bucket/ReverseNested.php @@ -1,5 +1,7 @@ addProperty('path', $path); } diff --git a/src/DSL/Aggs/Bucket/SignificantTerms.php b/src/DSL/Aggs/Bucket/SignificantTerms.php index 54fe10c..e933b57 100644 --- a/src/DSL/Aggs/Bucket/SignificantTerms.php +++ b/src/DSL/Aggs/Bucket/SignificantTerms.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'significant_terms'; /** * Maximum number of significant terms to return. @@ -28,7 +19,7 @@ public function field($field) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -39,7 +30,7 @@ public function size($size) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } @@ -50,7 +41,7 @@ public function shardSize($shardSize) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -61,7 +52,7 @@ public function minDocCount($minDocCount) * @param int $shardMinDocCount * @return static */ - public function shardMinDocCount($shardMinDocCount) + public function shardMinDocCount(int $shardMinDocCount): static { return $this->addProperty('shard_min_doc_count', $shardMinDocCount); } @@ -72,7 +63,7 @@ public function shardMinDocCount($shardMinDocCount) * @param mixed $include * @return static */ - public function include($include) + public function include($include): static { return $this->addProperty('include', $include); } @@ -83,7 +74,7 @@ public function include($include) * @param mixed $exclude * @return static */ - public function exclude($exclude) + public function exclude($exclude): static { return $this->addProperty('exclude', $exclude); } @@ -94,7 +85,7 @@ public function exclude($exclude) * @param mixed $backgroundFilter * @return static */ - public function backgroundFilter($backgroundFilter) + public function backgroundFilter($backgroundFilter): static { return $this->addProperty('background_filter', $backgroundFilter); } @@ -105,7 +96,7 @@ public function backgroundFilter($backgroundFilter) * @param string $executionHint * @return static */ - public function executionHint($executionHint) + public function executionHint(string $executionHint): static { return $this->addProperty('execution_hint', $executionHint); } diff --git a/src/DSL/Aggs/Bucket/SignificantText.php b/src/DSL/Aggs/Bucket/SignificantText.php index d07832b..f7736f2 100644 --- a/src/DSL/Aggs/Bucket/SignificantText.php +++ b/src/DSL/Aggs/Bucket/SignificantText.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'significant_text'; /** * Maximum number of significant terms to return. @@ -28,7 +19,7 @@ public function field($field) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -39,7 +30,7 @@ public function size($size) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } @@ -50,7 +41,7 @@ public function shardSize($shardSize) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -61,7 +52,7 @@ public function minDocCount($minDocCount) * @param int $shardMinDocCount * @return static */ - public function shardMinDocCount($shardMinDocCount) + public function shardMinDocCount(int $shardMinDocCount): static { return $this->addProperty('shard_min_doc_count', $shardMinDocCount); } @@ -72,7 +63,7 @@ public function shardMinDocCount($shardMinDocCount) * @param mixed $include * @return static */ - public function include($include) + public function include($include): static { return $this->addProperty('include', $include); } @@ -83,7 +74,7 @@ public function include($include) * @param mixed $exclude * @return static */ - public function exclude($exclude) + public function exclude($exclude): static { return $this->addProperty('exclude', $exclude); } @@ -94,7 +85,7 @@ public function exclude($exclude) * @param mixed $backgroundFilter * @return static */ - public function backgroundFilter($backgroundFilter) + public function backgroundFilter($backgroundFilter): static { return $this->addProperty('background_filter', $backgroundFilter); } @@ -105,7 +96,7 @@ public function backgroundFilter($backgroundFilter) * @param bool $filter * @return static */ - public function filterDuplicateText($filter) + public function filterDuplicateText(bool $filter): static { return $this->addProperty('filter_duplicate_text', $filter); } diff --git a/src/DSL/Aggs/Bucket/Terms.php b/src/DSL/Aggs/Bucket/Terms.php index ad6531d..76526fa 100644 --- a/src/DSL/Aggs/Bucket/Terms.php +++ b/src/DSL/Aggs/Bucket/Terms.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'terms'; /** * Maximum number of term buckets to return. @@ -28,7 +19,7 @@ public function field($field) * @param int $size * @return static */ - public function size($size) + public function size(int $size): static { return $this->addProperty('size', $size); } @@ -39,7 +30,7 @@ public function size($size) * @param mixed $order * @return static */ - public function order($order) + public function order($order): static { return $this->addProperty('order', $order); } @@ -50,7 +41,7 @@ public function order($order) * @param int $minDocCount * @return static */ - public function minDocCount($minDocCount) + public function minDocCount(int $minDocCount): static { return $this->addProperty('min_doc_count', $minDocCount); } @@ -61,7 +52,7 @@ public function minDocCount($minDocCount) * @param int $shardSize * @return static */ - public function shardSize($shardSize) + public function shardSize(int $shardSize): static { return $this->addProperty('shard_size', $shardSize); } @@ -72,7 +63,7 @@ public function shardSize($shardSize) * @param bool $show * @return static */ - public function showTermDocCountError($show) + public function showTermDocCountError(bool $show): static { return $this->addProperty('show_term_doc_count_error', $show); } @@ -83,7 +74,7 @@ public function showTermDocCountError($show) * @param int $shardMinDocCount * @return static */ - public function shardMinDocCount($shardMinDocCount) + public function shardMinDocCount(int $shardMinDocCount): static { return $this->addProperty('shard_min_doc_count', $shardMinDocCount); } @@ -94,7 +85,7 @@ public function shardMinDocCount($shardMinDocCount) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } @@ -105,7 +96,7 @@ public function missing($missing) * @param string $collectMode * @return static */ - public function collectMode($collectMode) + public function collectMode(string $collectMode): static { return $this->addProperty('collect_mode', $collectMode); } @@ -116,7 +107,7 @@ public function collectMode($collectMode) * @param mixed $include * @return static */ - public function include($include) + public function include($include): static { return $this->addProperty('include', $include); } @@ -127,7 +118,7 @@ public function include($include) * @param mixed $exclude * @return static */ - public function exclude($exclude) + public function exclude($exclude): static { return $this->addProperty('exclude', $exclude); } @@ -138,7 +129,7 @@ public function exclude($exclude) * @param string $executionHint * @return static */ - public function executionHint($executionHint) + public function executionHint(string $executionHint): static { return $this->addProperty('execution_hint', $executionHint); } diff --git a/src/DSL/Aggs/Bucket/TimeSeries.php b/src/DSL/Aggs/Bucket/TimeSeries.php index 2497ae8..f170918 100644 --- a/src/DSL/Aggs/Bucket/TimeSeries.php +++ b/src/DSL/Aggs/Bucket/TimeSeries.php @@ -1,27 +1,20 @@ addProperty('field', $field); - } + protected string $_key = 'time_series'; /** * @param string $calendarInterval * @return static */ - public function calendarInterval($calendarInterval) + public function calendarInterval(string $calendarInterval): static { return $this->addProperty('calendar_interval', $calendarInterval); } @@ -30,7 +23,7 @@ public function calendarInterval($calendarInterval) * @param string $fixedInterval * @return static */ - public function fixedInterval($fixedInterval) + public function fixedInterval(string $fixedInterval): static { return $this->addProperty('fixed_interval', $fixedInterval); } @@ -39,7 +32,7 @@ public function fixedInterval($fixedInterval) * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Bucket/VariableWidthHistogram.php b/src/DSL/Aggs/Bucket/VariableWidthHistogram.php index 1f4d3ed..8f987eb 100644 --- a/src/DSL/Aggs/Bucket/VariableWidthHistogram.php +++ b/src/DSL/Aggs/Bucket/VariableWidthHistogram.php @@ -1,27 +1,20 @@ addProperty('field', $field); - } + protected string $_key = 'variable_width_histogram'; /** * @param int $buckets * @return static */ - public function buckets($buckets) + public function buckets(int $buckets): static { return $this->addProperty('buckets', $buckets); } @@ -30,7 +23,7 @@ public function buckets($buckets) * @param int $shardBuckets * @return static */ - public function shardBuckets($shardBuckets) + public function shardBuckets(int $shardBuckets): static { return $this->addProperty('shard_buckets', $shardBuckets); } diff --git a/src/DSL/Aggs/Metric.php b/src/DSL/Aggs/Metric.php index d66e88a..f7af4f0 100644 --- a/src/DSL/Aggs/Metric.php +++ b/src/DSL/Aggs/Metric.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'avg'; /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Metric/Cardinality.php b/src/DSL/Aggs/Metric/Cardinality.php index 9f45379..dacea20 100644 --- a/src/DSL/Aggs/Metric/Cardinality.php +++ b/src/DSL/Aggs/Metric/Cardinality.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'cardinality'; /** * Controls the precision of the count. @@ -28,29 +19,29 @@ public function field($field) * @param int $threshold * @return static */ - public function precisionThreshold($threshold) + public function precisionThreshold(int $threshold): static { return $this->addProperty('precision_threshold', $threshold); } /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Metric/ExtendedStats.php b/src/DSL/Aggs/Metric/ExtendedStats.php index 616fd76..4a01725 100644 --- a/src/DSL/Aggs/Metric/ExtendedStats.php +++ b/src/DSL/Aggs/Metric/ExtendedStats.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'extended_stats'; /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } @@ -50,7 +41,7 @@ public function script($script) * @param int $sigma * @return static */ - public function sigma($sigma) + public function sigma(int $sigma): static { return $this->addProperty('sigma', $sigma); } diff --git a/src/DSL/Aggs/Metric/Max.php b/src/DSL/Aggs/Metric/Max.php index cb71a35..11775a9 100644 --- a/src/DSL/Aggs/Metric/Max.php +++ b/src/DSL/Aggs/Metric/Max.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'max'; /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Metric/Min.php b/src/DSL/Aggs/Metric/Min.php index cb9fd7c..94bf2d6 100644 --- a/src/DSL/Aggs/Metric/Min.php +++ b/src/DSL/Aggs/Metric/Min.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'min'; /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Metric/Stats.php b/src/DSL/Aggs/Metric/Stats.php index 9b7ac44..1903766 100644 --- a/src/DSL/Aggs/Metric/Stats.php +++ b/src/DSL/Aggs/Metric/Stats.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'stats'; /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Metric/Sum.php b/src/DSL/Aggs/Metric/Sum.php index f86dfbc..c59dd63 100644 --- a/src/DSL/Aggs/Metric/Sum.php +++ b/src/DSL/Aggs/Metric/Sum.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'sum'; /** - * (Optional) The value to use when the field is missing. + * The value to use when the field is missing. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Metric/ValueCount.php b/src/DSL/Aggs/Metric/ValueCount.php index bd7ef87..684e837 100644 --- a/src/DSL/Aggs/Metric/ValueCount.php +++ b/src/DSL/Aggs/Metric/ValueCount.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'value_count'; /** - * (Optional) The script to use for the aggregation. + * The script to use for the aggregation. * * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } diff --git a/src/DSL/Aggs/Pipeline.php b/src/DSL/Aggs/Pipeline.php index 48b1461..3be32cf 100644 --- a/src/DSL/Aggs/Pipeline.php +++ b/src/DSL/Aggs/Pipeline.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -39,18 +41,18 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } /** - * (Optional) The value to use when the aggregation is missing a value. + * The value to use when the aggregation is missing a value. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Pipeline/BucketScript.php b/src/DSL/Aggs/Pipeline/BucketScript.php index 7df06b0..7da6e36 100644 --- a/src/DSL/Aggs/Pipeline/BucketScript.php +++ b/src/DSL/Aggs/Pipeline/BucketScript.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string|callable $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', $script); } @@ -39,7 +41,7 @@ public function script($script) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -50,7 +52,7 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } diff --git a/src/DSL/Aggs/Pipeline/CumulativeSum.php b/src/DSL/Aggs/Pipeline/CumulativeSum.php index a484122..0da75e1 100644 --- a/src/DSL/Aggs/Pipeline/CumulativeSum.php +++ b/src/DSL/Aggs/Pipeline/CumulativeSum.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } diff --git a/src/DSL/Aggs/Pipeline/Derivative.php b/src/DSL/Aggs/Pipeline/Derivative.php index d087cc7..d8305a3 100644 --- a/src/DSL/Aggs/Pipeline/Derivative.php +++ b/src/DSL/Aggs/Pipeline/Derivative.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -39,7 +41,7 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } @@ -50,7 +52,7 @@ public function format($format) * @param string $unit * @return static */ - public function unit($unit) + public function unit(string $unit): static { return $this->addProperty('unit', $unit); } diff --git a/src/DSL/Aggs/Pipeline/MaxBucket.php b/src/DSL/Aggs/Pipeline/MaxBucket.php index ea5942c..faa7ff5 100644 --- a/src/DSL/Aggs/Pipeline/MaxBucket.php +++ b/src/DSL/Aggs/Pipeline/MaxBucket.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -39,18 +41,18 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } /** - * (Optional) The value to use when the aggregation is missing a value. + * The value to use when the aggregation is missing a value. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Pipeline/MinBucket.php b/src/DSL/Aggs/Pipeline/MinBucket.php index 7cf0cbe..12b0810 100644 --- a/src/DSL/Aggs/Pipeline/MinBucket.php +++ b/src/DSL/Aggs/Pipeline/MinBucket.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -39,18 +41,18 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } /** - * (Optional) The value to use when the aggregation is missing a value. + * The value to use when the aggregation is missing a value. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Pipeline/StatsBucket.php b/src/DSL/Aggs/Pipeline/StatsBucket.php index 8eb4520..45af167 100644 --- a/src/DSL/Aggs/Pipeline/StatsBucket.php +++ b/src/DSL/Aggs/Pipeline/StatsBucket.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -39,18 +41,18 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } /** - * (Optional) The value to use when the aggregation is missing a value. + * The value to use when the aggregation is missing a value. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Aggs/Pipeline/SumBucket.php b/src/DSL/Aggs/Pipeline/SumBucket.php index 07a68d0..dcd5d8d 100644 --- a/src/DSL/Aggs/Pipeline/SumBucket.php +++ b/src/DSL/Aggs/Pipeline/SumBucket.php @@ -1,5 +1,7 @@ addProperty('buckets_path', $path); } @@ -28,7 +30,7 @@ public function bucketsPath($path) * @param string $policy * @return static */ - public function gapPolicy($policy) + public function gapPolicy(string $policy): static { return $this->addProperty('gap_policy', $policy); } @@ -39,18 +41,18 @@ public function gapPolicy($policy) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } /** - * (Optional) The value to use when the aggregation is missing a value. + * The value to use when the aggregation is missing a value. * * @param mixed $missing * @return static */ - public function missing($missing) + public function missing($missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Node.php b/src/DSL/Node.php index 3f60791..0df9aa1 100644 --- a/src/DSL/Node.php +++ b/src/DSL/Node.php @@ -1,5 +1,7 @@ |null + */ + protected ?array $_properties = null; + + /** + * Raw whole-value pass-through. When set, toArray() emits this value + * verbatim — for nodes constructed with a single non-array, non-closure + * argument (a wrapped Node, a FilterAgg filter query, etc.). * - * @var array|mixed|null + * @var mixed */ - protected $_properties; + protected $_raw; /** * Raw scalar value stored separately from properties. @@ -33,14 +47,14 @@ abstract class Node * * @var string */ - protected $_valueKey = 'value'; + protected string $_valueKey = 'value'; /** * Whether to use a field name as the top-level attribute of a node. * * @var bool */ - protected $_isPropertyField = false; + protected bool $_fieldKeyed = false; /** * The field name used as the top-level attribute of a node. @@ -54,14 +68,14 @@ abstract class Node * * @var bool */ - protected $_multi = false; + protected bool $_multi = false; /** * The Elasticsearch query or aggregation type identifier. * * @var string */ - protected $_key; + protected string $_key; /** * Initialize the node. @@ -83,12 +97,14 @@ public function __construct($field = null, $value = null) $this->fromKeyValue($field, $value); } elseif ($field instanceof Closure) { $this->fromClosure($field); - } elseif ($this->_isPropertyField && is_array($field)) { + } elseif ($this->_fieldKeyed && is_array($field)) { $this->fromArrayField($field); - } elseif ($this->_isPropertyField && is_scalar($field)) { + } elseif ($this->_fieldKeyed && is_scalar($field)) { $this->fromScalar($field); - } else { + } elseif (is_array($field)) { $this->_properties = $field; + } elseif ($field !== null) { + $this->_raw = $field; } } @@ -105,10 +121,12 @@ protected function fromKeyValue($field, $value): void } elseif (is_scalar($value)) { $this->_rawValue = $value; $this->_properties = []; - } else { + } elseif (is_array($value)) { $this->_properties = $value; + } else { + $this->_raw = $value; } - if ($this->_isPropertyField) { + if ($this->_fieldKeyed) { $this->field($field); } } @@ -135,8 +153,10 @@ protected function fromArrayField(array $field): void if (is_scalar($val)) { $this->_rawValue = $val; $this->_properties = []; - } else { + } elseif (is_array($val)) { $this->_properties = $val; + } else { + $this->_raw = $val; } break; } @@ -156,12 +176,12 @@ protected function fromScalar($value): void /** * Set whether this node uses a field name as the top-level attribute. * - * @param bool $isPropertyField + * @param bool $fieldKeyed * @return static */ - protected function isPropertyField($isPropertyField) + protected function fieldKeyed(bool $fieldKeyed): static { - $this->_isPropertyField = $isPropertyField; + $this->_fieldKeyed = $fieldKeyed; return $this; } @@ -171,19 +191,7 @@ protected function isPropertyField($isPropertyField) * @param bool $multi * @return static */ - protected function multi($multi) - { - $this->_multi = $multi; - return $this; - } - - /** - * Set whether the node supports multiple clauses. - * - * @param bool $multi - * @return static - */ - protected function setMulti($multi) + protected function multi(bool $multi): static { $this->_multi = $multi; return $this; @@ -194,7 +202,7 @@ protected function setMulti($multi) * * @return bool */ - protected function isMulti() + protected function isMulti(): bool { return $this->_multi; } @@ -204,7 +212,7 @@ protected function isMulti() * * @return string */ - public function key() + public function key(): string { return $this->_key; } @@ -215,9 +223,9 @@ public function key() * @param string $field * @return static */ - public function field($field) + public function field($field): static { - if ($this->_isPropertyField) { + if ($this->_fieldKeyed) { $this->_field = $field; } else { $this->_properties['field'] = $field; @@ -233,7 +241,7 @@ public function field($field) * @param bool $append * @return static */ - public function addProperty($attribute, $value, $append = false) + public function addProperty($attribute, $value, $append = false): static { if ($append) { $this->_properties[$attribute][] = $value; @@ -253,7 +261,7 @@ public function addProperty($attribute, $value, $append = false) * @param mixed $value * @return static */ - public static function create($field = null, $value = null) + public static function create($field = null, $value = null): static { if ($value === null && $field instanceof static) { return $field; @@ -267,7 +275,7 @@ public static function create($field = null, $value = null) * @param array $properties * @return array */ - protected function resolveProperties(array $properties) + protected function resolveProperties(array $properties): array { foreach ($properties as $key => $property) { if ($property instanceof Query) { @@ -287,28 +295,29 @@ protected function resolveProperties(array $properties) * Serialize to an Elasticsearch DSL array. * * Recursively resolves nested Query and Node instances. - * When _isPropertyField is true, wraps properties under the field name. + * When _fieldKeyed is true, wraps properties under the field name. * * @return array|mixed */ public function toArray() { - if ($this->_rawValue !== null) { - if (empty($this->_properties)) { + if ($this->_raw !== null) { + $properties = $this->_raw; + } elseif ($this->_rawValue !== null) { + $props = $this->_properties ?? []; + if ($props === []) { $properties = $this->_rawValue; } else { - $properties = $this->resolveProperties($this->_properties); + $properties = $this->resolveProperties($props); if (!isset($properties[$this->_valueKey])) { $properties = array_merge([$this->_valueKey => $this->_rawValue], $properties); } } } else { - $properties = is_array($this->_properties) - ? $this->resolveProperties($this->_properties) - : $this->_properties; + $properties = $this->_properties === null ? null : $this->resolveProperties($this->_properties); } - if ($this->_isPropertyField) { + if ($this->_fieldKeyed) { return [$this->_field => $properties]; } return $properties; @@ -321,9 +330,11 @@ public function toArray() * @param int $depth * @return string */ - public function toJson($flags = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT, $depth = 512) + public function toJson(int $flags = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT, int $depth = 512): string { - return json_encode($this->toArray(), $flags, $depth); + $json = json_encode($this->toArray(), $flags, $depth); + + return $json === false ? '' : $json; } /** @@ -331,7 +342,7 @@ public function toJson($flags = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT, $dep * * @return string */ - public function __toString() + public function __toString(): string { return $this->toJson(); } @@ -343,7 +354,7 @@ public function __toString() * @param float $boost * @return static */ - public function boost($boost) + public function boost($boost): static { return $this->addProperty('boost', $boost); } diff --git a/src/DSL/Param.php b/src/DSL/Param.php index 49c0dd8..ba982e3 100644 --- a/src/DSL/Param.php +++ b/src/DSL/Param.php @@ -1,5 +1,7 @@ field($field); @@ -32,24 +34,13 @@ public static function create($field = null, $value = null) } /** - * The field to collapse the result set on. - * - * @param string $field - * @return static - */ - public function field($field) - { - return $this->addProperty('field', $field); - } - - /** - * (Optional) Expand each collapsed top hit with the inner_hits option. + * Expand each collapsed top hit with the inner_hits option. * * @param string $name * @param mixed $hits * @return static */ - public function innerHits($name, $hits = null) + public function innerHits(string $name, $hits = null): static { return $this->addProperty('inner_hits', ['name' => $name] + (array)$hits); } @@ -60,7 +51,7 @@ public function innerHits($name, $hits = null) * @param int $max * @return static */ - public function maxConcurrentGroupSearches($max) + public function maxConcurrentGroupSearches(int $max): static { return $this->addProperty('max_concurrent_group_searches', $max); } diff --git a/src/DSL/Params/Highlight.php b/src/DSL/Params/Highlight.php index 9f8347b..460f116 100644 --- a/src/DSL/Params/Highlight.php +++ b/src/DSL/Params/Highlight.php @@ -1,5 +1,7 @@ field($field); @@ -34,13 +36,13 @@ public static function create($field = null, $value = null) } /** - * (Required) Add a field to highlight. Empty settings produces `{}`. + * Add a field to highlight. Empty settings produces `{}`. * * @param string $field * @param array $settings * @return static */ - public function field($field, $settings = []) + public function field($field, array $settings = []): static { $value = empty($settings) ? new stdClass() : $settings; $this->_properties['fields'][$field] = $value; @@ -53,7 +55,7 @@ public function field($field, $settings = []) * @param array $tags * @return static */ - public function preTags($tags) + public function preTags(array $tags): static { return $this->addProperty('pre_tags', $tags); } @@ -64,7 +66,7 @@ public function preTags($tags) * @param array $tags * @return static */ - public function postTags($tags) + public function postTags(array $tags): static { return $this->addProperty('post_tags', $tags); } @@ -75,7 +77,7 @@ public function postTags($tags) * @param int $size * @return static */ - public function fragmentSize($size) + public function fragmentSize(int $size): static { return $this->addProperty('fragment_size', $size); } @@ -86,7 +88,7 @@ public function fragmentSize($size) * @param int $num * @return static */ - public function numberOfFragments($num) + public function numberOfFragments(int $num): static { return $this->addProperty('number_of_fragments', $num); } @@ -97,7 +99,7 @@ public function numberOfFragments($num) * @param string $encoder * @return static */ - public function encoder($encoder) + public function encoder(string $encoder): static { return $this->addProperty('encoder', $encoder); } @@ -108,18 +110,18 @@ public function encoder($encoder) * @param string $order * @return static */ - public function order($order) + public function order(string $order): static { return $this->addProperty('order', $order); } /** - * (Optional) Highlight against a query other than the search query. + * Highlight against a query other than the search query. * * @param mixed $query * @return static */ - public function highlightQuery($query) + public function highlightQuery($query): static { return $this->addProperty('highlight_query', Query::create($query)); } @@ -130,7 +132,7 @@ public function highlightQuery($query) * @param string $type * @return static */ - public function type($type) + public function type(string $type): static { return $this->addProperty('type', $type); } @@ -141,7 +143,7 @@ public function type($type) * @param string $scanner * @return static */ - public function boundaryScanner($scanner) + public function boundaryScanner(string $scanner): static { return $this->addProperty('boundary_scanner', $scanner); } @@ -152,7 +154,7 @@ public function boundaryScanner($scanner) * @param string $locale * @return static */ - public function boundaryScannerLocale($locale) + public function boundaryScannerLocale(string $locale): static { return $this->addProperty('boundary_scanner_locale', $locale); } @@ -163,7 +165,7 @@ public function boundaryScannerLocale($locale) * @param int $max * @return static */ - public function boundaryMaxScan($max) + public function boundaryMaxScan(int $max): static { return $this->addProperty('boundary_max_scan', $max); } @@ -174,7 +176,7 @@ public function boundaryMaxScan($max) * @param int $size * @return static */ - public function noMatchSize($size) + public function noMatchSize(int $size): static { return $this->addProperty('no_match_size', $size); } @@ -185,7 +187,7 @@ public function noMatchSize($size) * @param string $fragmenter * @return static */ - public function fragmenter($fragmenter) + public function fragmenter(string $fragmenter): static { return $this->addProperty('fragmenter', $fragmenter); } diff --git a/src/DSL/Params/Knn.php b/src/DSL/Params/Knn.php index 01f80c2..358a382 100644 --- a/src/DSL/Params/Knn.php +++ b/src/DSL/Params/Knn.php @@ -1,5 +1,7 @@ addProperty('field', $field); - } + protected string $_key = 'knn'; /** * The query vector to search for. @@ -32,7 +23,7 @@ public function field($field) * @param array $vector * @return static */ - public function queryVector($vector) + public function queryVector(array $vector): static { return $this->addProperty('query_vector', $vector); } @@ -44,7 +35,7 @@ public function queryVector($vector) * @param int $k * @return static */ - public function k($k) + public function k(int $k): static { return $this->addProperty('k', $k); } @@ -56,7 +47,7 @@ public function k($k) * @param int $num * @return static */ - public function numCandidates($num) + public function numCandidates(int $num): static { return $this->addProperty('num_candidates', $num); } @@ -68,7 +59,7 @@ public function numCandidates($num) * @param float $similarity * @return static */ - public function similarity($similarity) + public function similarity(float $similarity): static { return $this->addProperty('similarity', $similarity); } @@ -79,41 +70,41 @@ public function similarity($similarity) * @param float $boost * @return static */ - public function boost($boost) + public function boost($boost): static { return $this->addProperty('boost', $boost); } /** - * (Optional) Pre-filter applied during kNN search. Accepts a closure, + * Pre-filter applied during kNN search. Accepts a closure, * array, or Query object. * * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { return $this->addProperty('filter', Query::create($filter)); } /** - * (Optional) Inner hits configuration for nested kNN search. + * Inner hits configuration for nested kNN search. * * @param mixed $innerHits * @return static */ - public function innerHits($innerHits) + public function innerHits($innerHits): static { return $this->addProperty('inner_hits', $innerHits); } /** - * (Optional) Rescore vector configuration for quantized vector rescoring. + * Rescore vector configuration for quantized vector rescoring. * * @param array $rescoreVector * @return static */ - public function rescoreVector($rescoreVector) + public function rescoreVector(array $rescoreVector): static { return $this->addProperty('rescore_vector', $rescoreVector); } diff --git a/src/DSL/Params/Rescore.php b/src/DSL/Params/Rescore.php index cef3e20..733229c 100644 --- a/src/DSL/Params/Rescore.php +++ b/src/DSL/Params/Rescore.php @@ -1,5 +1,7 @@ addProperty('window_size', $size); } /** - * (Required) The query to use for rescoring. + * The query to use for rescoring. * * @param mixed $query * @return static */ - public function query($query) + public function query($query): static { $this->_properties['query']['rescore_query'] = Query::create($query); return $this; @@ -44,7 +46,7 @@ public function query($query) * @param float $weight * @return static */ - public function rescoreQueryWeight($weight) + public function rescoreQueryWeight(float $weight): static { $this->_properties['query']['rescore_query_weight'] = $weight; return $this; @@ -56,7 +58,7 @@ public function rescoreQueryWeight($weight) * @param float $weight * @return static */ - public function queryWeight($weight) + public function queryWeight(float $weight): static { $this->_properties['query']['query_weight'] = $weight; return $this; @@ -69,7 +71,7 @@ public function queryWeight($weight) * @param string $mode * @return static */ - public function scoreMode($mode) + public function scoreMode(string $mode): static { $this->_properties['query']['score_mode'] = $mode; return $this; diff --git a/src/DSL/Params/Suggest.php b/src/DSL/Params/Suggest.php index 79eef40..0d53ef2 100644 --- a/src/DSL/Params/Suggest.php +++ b/src/DSL/Params/Suggest.php @@ -1,5 +1,7 @@ ['field' => $field]]; if ($text !== null) { @@ -38,7 +40,7 @@ public function term($alias, $field, $text = null) * @param string|null $prefix * @return static */ - public function completion($alias, $field, $prefix = null) + public function completion(string $alias, string $field, ?string $prefix = null): static { $suggest = ['completion' => ['field' => $field]]; if ($prefix !== null) { @@ -55,7 +57,7 @@ public function completion($alias, $field, $prefix = null) * @param string|null $text * @return static */ - public function phrase($alias, $field, $text = null) + public function phrase(string $alias, string $field, ?string $text = null): static { $suggest = ['phrase' => ['field' => $field]]; if ($text !== null) { diff --git a/src/DSL/Queries/Compound.php b/src/DSL/Queries/Compound.php index a6a2836..79ad381 100644 --- a/src/DSL/Queries/Compound.php +++ b/src/DSL/Queries/Compound.php @@ -1,5 +1,7 @@ addClause('must', $must); } @@ -33,7 +35,7 @@ public function must($must) * @param mixed $should * @return static */ - public function should($should) + public function should($should): static { return $this->addClause('should', $should); } @@ -45,7 +47,7 @@ public function should($should) * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { return $this->addClause('filter', $filter); } @@ -57,7 +59,7 @@ public function filter($filter) * @param mixed $mustNot * @return static */ - public function mustNot($mustNot) + public function mustNot($mustNot): static { return $this->addClause('must_not', $mustNot); } @@ -69,10 +71,10 @@ public function mustNot($mustNot) * * For other valid values, see the minimum_should_match parameter. * - * @param int $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } diff --git a/src/DSL/Queries/Compound/Boosting.php b/src/DSL/Queries/Compound/Boosting.php index 4279c18..c668cc5 100644 --- a/src/DSL/Queries/Compound/Boosting.php +++ b/src/DSL/Queries/Compound/Boosting.php @@ -1,5 +1,7 @@ addProperty('positive', Query::create($positive)); } @@ -29,7 +31,7 @@ public function positive($positive) * @param mixed $negative * @return static */ - public function negative($negative) + public function negative($negative): static { return $this->addProperty('negative', Query::create($negative)); } @@ -40,7 +42,7 @@ public function negative($negative) * @param float $negativeBoost * @return static */ - public function negativeBoost($negativeBoost) + public function negativeBoost(float $negativeBoost): static { return $this->addProperty('negative_boost', $negativeBoost); } diff --git a/src/DSL/Queries/Compound/ConstantScore.php b/src/DSL/Queries/Compound/ConstantScore.php index 4101f4c..80ba278 100644 --- a/src/DSL/Queries/Compound/ConstantScore.php +++ b/src/DSL/Queries/Compound/ConstantScore.php @@ -1,5 +1,7 @@ addProperty('filter', Query::create($query)); } diff --git a/src/DSL/Queries/Compound/DisjunctionMax.php b/src/DSL/Queries/Compound/DisjunctionMax.php index ec0a92d..5b63895 100644 --- a/src/DSL/Queries/Compound/DisjunctionMax.php +++ b/src/DSL/Queries/Compound/DisjunctionMax.php @@ -1,5 +1,7 @@ addClause('queries', $queries); } @@ -32,7 +34,7 @@ public function queries($queries) * @param float $tieBreaker * @return static */ - public function tieBreaker($tieBreaker) + public function tieBreaker(float $tieBreaker): static { return $this->addProperty('tie_breaker', $tieBreaker); } diff --git a/src/DSL/Queries/Compound/FunctionScore.php b/src/DSL/Queries/Compound/FunctionScore.php index d92fff5..ca16b3d 100644 --- a/src/DSL/Queries/Compound/FunctionScore.php +++ b/src/DSL/Queries/Compound/FunctionScore.php @@ -1,5 +1,7 @@ addProperty('score_mode', $scoreMode); } /** - * (Optional) Defines how the newly computed function score is combined with the query score. + * Defines how the newly computed function score is combined with the query score. * Options: multiply (default), replace, sum, avg, max, min. * * @param string $boostMode * @return static */ - public function boostMode($boostMode) + public function boostMode(string $boostMode): static { return $this->addProperty('boost_mode', $boostMode); } /** - * (Optional) Excludes documents that do not meet the specified score threshold. + * Excludes documents that do not meet the specified score threshold. * * @param float $minScore * @return static */ - public function minScore($minScore) + public function minScore(float $minScore): static { return $this->addProperty('min_score', $minScore); } /** - * (Optional) Restricts the new score to not exceed the specified limit. Defaults to FLT_MAX. + * Restricts the new score to not exceed the specified limit. Defaults to FLT_MAX. * * @param float $maxBoost * @return static */ - public function maxBoost($maxBoost) + public function maxBoost(float $maxBoost): static { return $this->addProperty('max_boost', $maxBoost); } /** - * (Required) The query to be scored. + * The query to be scored. * * @param mixed $query * @return static */ - public function query($query) + public function query($query): static { return $this->addProperty('query', Query::create($query)); } /** - * (Optional) Array of score functions to apply. + * Array of score functions to apply. * * @param array $functions * @return static */ - public function functions($functions) + public function functions(array $functions): static { return $this->addProperty('functions', $functions); } /** - * (Optional) Appends a score function to the functions array. + * Appends a score function to the functions array. * * @param mixed $function * @return static */ - public function addFunction($function) + public function addFunction($function): static { return $this->addProperty('functions', Function_::create($function), true); } @@ -114,7 +116,7 @@ public function toArray() $properties = $this->resolveProperties($properties); - if ($this->_isPropertyField) { + if ($this->_fieldKeyed) { return [$this->_field => $properties]; } return $properties; diff --git a/src/DSL/Queries/Compound/Functions/Exp.php b/src/DSL/Queries/Compound/Functions/Exp.php index 97bd842..2516317 100644 --- a/src/DSL/Queries/Compound/Functions/Exp.php +++ b/src/DSL/Queries/Compound/Functions/Exp.php @@ -1,5 +1,7 @@ addProperty('origin', $origin); } /** - * (Required) Defines the distance from origin + offset at which the computed score will equal the decay parameter. + * Defines the distance from origin + offset at which the computed score will equal the decay parameter. * * @param mixed $scale * @return static */ - public function scale($scale) + public function scale($scale): static { return $this->addProperty('scale', $scale); } /** - * (Optional) If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. + * If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. * * @param mixed $offset * @return static */ - public function offset($offset) + public function offset($offset): static { return $this->addProperty('offset', $offset); } /** - * (Optional) Defines how documents are scored at the distance given at scale. Defaults to 0.5. + * Defines how documents are scored at the distance given at scale. Defaults to 0.5. * * @param float $decay * @return static */ - public function decay($decay) + public function decay(float $decay): static { return $this->addProperty('decay', $decay); } diff --git a/src/DSL/Queries/Compound/Functions/FieldValueFactor.php b/src/DSL/Queries/Compound/Functions/FieldValueFactor.php index fdb4f41..667455e 100644 --- a/src/DSL/Queries/Compound/Functions/FieldValueFactor.php +++ b/src/DSL/Queries/Compound/Functions/FieldValueFactor.php @@ -1,23 +1,14 @@ addProperty('field', $field); - } + protected string $_key = 'field_value_factor'; /** * Optional factor to multiply the field value with, defaults to 1. @@ -25,7 +16,7 @@ public function field($field) * @param float $factor * @return static */ - public function factor($factor) + public function factor(float $factor): static { return $this->addProperty('factor', $factor); } @@ -36,7 +27,7 @@ public function factor($factor) * @param string $modifier * @return static */ - public function modifier($modifier) + public function modifier(string $modifier): static { return $this->addProperty('modifier', $modifier); } @@ -44,10 +35,10 @@ public function modifier($modifier) /** * Value used if the document doesn’t have that field. The modifier and factor are still applied to it as though it were read from the document. * - * @param mixed $missing + * @param string|int|float|bool $missing * @return static */ - public function missing($missing) + public function missing(string|int|float|bool $missing): static { return $this->addProperty('missing', $missing); } diff --git a/src/DSL/Queries/Compound/Functions/Function_.php b/src/DSL/Queries/Compound/Functions/Function_.php index cd09444..186e1d1 100644 --- a/src/DSL/Queries/Compound/Functions/Function_.php +++ b/src/DSL/Queries/Compound/Functions/Function_.php @@ -1,5 +1,7 @@ addProperty('filter', Query::create($filter)); } /** - * (Optional) Multiplies the score by the provided weight value. + * Multiplies the score by the provided weight value. * * @param float $weight * @return static */ - public function weight($weight) + public function weight(float $weight): static { return $this->addProperty('weight', $weight); } /** - * (Optional) Generates uniformly distributed random scores from 0 up to but not including 1. + * Generates uniformly distributed random scores from 0 up to but not including 1. * * @param mixed $randomScore * @return static */ - public function randomScore($randomScore = null) + public function randomScore($randomScore = null): static { return $this->addProperty('random_score', RandomScore::create($randomScore)); } /** - * (Optional) Wraps another query and customizes the scoring using a script. + * Wraps another query and customizes the scoring using a script. * * @param mixed $scriptScore * @return static */ - public function scriptScore($scriptScore) + public function scriptScore($scriptScore): static { return $this->addProperty('script_score', ScriptScore::create($scriptScore)); } /** - * (Optional) Sets the script for script_score using a Script object or closure. + * Sets the script for script_score using a Script object or closure. * * @param mixed $script * @return static */ - public function script($script) + public function script($script): static { $scriptScore = (new ScriptScore())->script($script); return $this->addProperty('script_score', $scriptScore); } /** - * (Optional) Uses a numeric field value to influence the score. + * Uses a numeric field value to influence the score. * * @param mixed $field * @param mixed $fieldValueFactor * @return static */ - public function fieldValueFactor($field, $fieldValueFactor = null) + public function fieldValueFactor($field, $fieldValueFactor = null): static { return $this->addProperty('field_value_factor', FieldValueFactor::create($field, $fieldValueFactor)); } /** - * (Optional) Scores documents using normal (Gaussian) decay based on distance from an origin point. + * Scores documents using normal (Gaussian) decay based on distance from an origin point. * * @param mixed $field * @param mixed $gauss * @return static */ - public function gauss($field, $gauss = null) + public function gauss($field, $gauss = null): static { return $this->addProperty('gauss', Gauss::create($field, $gauss)); } /** - * (Optional) Scores documents using linear decay based on distance from an origin point. + * Scores documents using linear decay based on distance from an origin point. * * @param mixed $field * @param mixed $linear * @return static */ - public function linear($field, $linear = null) + public function linear($field, $linear = null): static { return $this->addProperty('linear', Linear::create($field, $linear)); } /** - * (Optional) Scores documents using exponential decay based on distance from an origin point. + * Scores documents using exponential decay based on distance from an origin point. * * @param mixed $field * @param mixed $exp * @return static */ - public function exp($field, $exp = null) + public function exp($field, $exp = null): static { return $this->addProperty('exp', Exp::create($field, $exp)); } diff --git a/src/DSL/Queries/Compound/Functions/Gauss.php b/src/DSL/Queries/Compound/Functions/Gauss.php index 5bd3fa4..4bdaa3b 100644 --- a/src/DSL/Queries/Compound/Functions/Gauss.php +++ b/src/DSL/Queries/Compound/Functions/Gauss.php @@ -1,5 +1,7 @@ addProperty('origin', $origin); } /** - * (Required) Defines the distance from origin + offset at which the computed score will equal the decay parameter. + * Defines the distance from origin + offset at which the computed score will equal the decay parameter. * * @param mixed $scale * @return static */ - public function scale($scale) + public function scale($scale): static { return $this->addProperty('scale', $scale); } /** - * (Optional) If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. + * If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. * * @param mixed $offset * @return static */ - public function offset($offset) + public function offset($offset): static { return $this->addProperty('offset', $offset); } /** - * (Optional) Defines how documents are scored at the distance given at scale. Defaults to 0.5. + * Defines how documents are scored at the distance given at scale. Defaults to 0.5. * * @param float $decay * @return static */ - public function decay($decay) + public function decay(float $decay): static { return $this->addProperty('decay', $decay); } diff --git a/src/DSL/Queries/Compound/Functions/Linear.php b/src/DSL/Queries/Compound/Functions/Linear.php index 32fe187..65a6896 100644 --- a/src/DSL/Queries/Compound/Functions/Linear.php +++ b/src/DSL/Queries/Compound/Functions/Linear.php @@ -1,5 +1,7 @@ addProperty('origin', $origin); } /** - * (Required) Defines the distance from origin + offset at which the computed score will equal the decay parameter. + * Defines the distance from origin + offset at which the computed score will equal the decay parameter. * * @param mixed $scale * @return static */ - public function scale($scale) + public function scale($scale): static { return $this->addProperty('scale', $scale); } /** - * (Optional) If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. + * If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. * * @param mixed $offset * @return static */ - public function offset($offset) + public function offset($offset): static { return $this->addProperty('offset', $offset); } /** - * (Optional) Defines how documents are scored at the distance given at scale. Defaults to 0.5. + * Defines how documents are scored at the distance given at scale. Defaults to 0.5. * * @param float $decay * @return static */ - public function decay($decay) + public function decay(float $decay): static { return $this->addProperty('decay', $decay); } diff --git a/src/DSL/Queries/Compound/Functions/RandomScore.php b/src/DSL/Queries/Compound/Functions/RandomScore.php index 4a98aa9..25a6979 100644 --- a/src/DSL/Queries/Compound/Functions/RandomScore.php +++ b/src/DSL/Queries/Compound/Functions/RandomScore.php @@ -1,5 +1,7 @@ addProperty('seed', $seed); } - /** - * (Optional) Field used in combination with the seed to compute reproducible random scores. - * - * @param string $field - * @return static - */ - public function field($field) - { - return $this->addProperty('field', $field); - } - /** * {@inheritdoc} */ diff --git a/src/DSL/Queries/Compound/Functions/ScriptScore.php b/src/DSL/Queries/Compound/Functions/ScriptScore.php index 8175b3b..fbeea46 100644 --- a/src/DSL/Queries/Compound/Functions/ScriptScore.php +++ b/src/DSL/Queries/Compound/Functions/ScriptScore.php @@ -1,5 +1,7 @@ addProperty('script', Script::create($script)); } diff --git a/src/DSL/Queries/FullText.php b/src/DSL/Queries/FullText.php index 666c3fb..21b6808 100644 --- a/src/DSL/Queries/FullText.php +++ b/src/DSL/Queries/FullText.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -35,7 +37,7 @@ public function query($query) * @param array $fields * @return static */ - public function fields($fields) + public function fields(array $fields): static { return $this->addProperty('fields', $fields); } @@ -47,7 +49,7 @@ public function fields($fields) * @param bool $autoGenerateSynonymsPhraseQuery * @return static */ - public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery) + public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static { return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); } @@ -59,7 +61,7 @@ public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery * @param string $operator * @return static */ - public function operator($operator) + public function operator(string $operator): static { return $this->addProperty('operator', $operator); } @@ -68,10 +70,10 @@ public function operator($operator) * Minimum number of clauses that must match for a * document to be returned. * - * @param string $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -84,7 +86,7 @@ public function minimumShouldMatch($minimumShouldMatch) * @param string $zeroTermsQuery * @return static */ - public function zeroTermsQuery($zeroTermsQuery) + public function zeroTermsQuery(string $zeroTermsQuery): static { return $this->addProperty('zero_terms_query', $zeroTermsQuery); } diff --git a/src/DSL/Queries/FullText/Intervals.php b/src/DSL/Queries/FullText/Intervals.php index 077167f..9b1b01d 100644 --- a/src/DSL/Queries/FullText/Intervals.php +++ b/src/DSL/Queries/FullText/Intervals.php @@ -1,5 +1,7 @@ */ protected $_intervals = []; @@ -24,7 +26,7 @@ class Intervals extends Node * @param mixed $match * @return static */ - public function match($match) + public function match($match): static { $this->_intervals[] = Intervals\Match_::create($match); return $this; @@ -37,7 +39,7 @@ public function match($match) * @param mixed $prefix * @return static */ - public function prefix($prefix) + public function prefix($prefix): static { $this->_intervals[] = Intervals\Prefix::create($prefix); return $this; @@ -49,7 +51,7 @@ public function prefix($prefix) * @param mixed $wildcard * @return static */ - public function wildcard($wildcard) + public function wildcard($wildcard): static { $this->_intervals[] = Intervals\Wildcard::create($wildcard); return $this; @@ -62,7 +64,7 @@ public function wildcard($wildcard) * @param mixed $fuzzy * @return static */ - public function fuzzy($fuzzy) + public function fuzzy($fuzzy): static { $this->_intervals[] = Intervals\Fuzzy::create($fuzzy); return $this; @@ -74,7 +76,7 @@ public function fuzzy($fuzzy) * @param mixed $range * @return static */ - public function range($range) + public function range($range): static { $this->_intervals[] = Intervals\Range::create($range); return $this; @@ -87,7 +89,7 @@ public function range($range) * @param mixed $allOf * @return static */ - public function allOf($allOf) + public function allOf($allOf): static { $this->_intervals[] = Intervals\AllOf::create($allOf); return $this; @@ -100,7 +102,7 @@ public function allOf($allOf) * @param mixed $anyOf * @return static */ - public function anyOf($anyOf) + public function anyOf($anyOf): static { $this->_intervals[] = Intervals\AnyOf::create($anyOf); return $this; @@ -127,7 +129,7 @@ public function toArray() $properties = $resolved; } - if ($this->_isPropertyField) { + if ($this->_fieldKeyed) { return [$this->_field => $properties]; } return $properties; diff --git a/src/DSL/Queries/FullText/Intervals/AllOf.php b/src/DSL/Queries/FullText/Intervals/AllOf.php index 817a3ec..777cf1b 100644 --- a/src/DSL/Queries/FullText/Intervals/AllOf.php +++ b/src/DSL/Queries/FullText/Intervals/AllOf.php @@ -1,5 +1,7 @@ isPropertyField(false) + ->fieldKeyed(false) ->multi(true); return $this->addProperty('intervals', $intervals); } @@ -33,10 +35,10 @@ public function intervals($intervals) * @param mixed $interval * @return static */ - public function addInterval($interval) + public function addInterval($interval): static { if (!isset($this->_properties['intervals'])) { - $this->_properties['intervals'] = (new Intervals())->isPropertyField(false)->multi(true); + $this->_properties['intervals'] = (new Intervals())->fieldKeyed(false)->multi(true); } $target = $this->_properties['intervals']; if ($interval instanceof \Closure) { @@ -55,7 +57,7 @@ public function addInterval($interval) * @param int $maxGaps * @return static */ - public function maxGaps($maxGaps) + public function maxGaps(int $maxGaps): static { return $this->addProperty('max_gaps', $maxGaps); } @@ -67,7 +69,7 @@ public function maxGaps($maxGaps) * @param bool $ordered * @return static */ - public function ordered($ordered) + public function ordered(bool $ordered): static { return $this->addProperty('ordered', $ordered); } @@ -79,7 +81,7 @@ public function ordered($ordered) * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { return $this->addProperty('filter', $filter); } diff --git a/src/DSL/Queries/FullText/Intervals/AnyOf.php b/src/DSL/Queries/FullText/Intervals/AnyOf.php index b1da1e6..44bc2eb 100644 --- a/src/DSL/Queries/FullText/Intervals/AnyOf.php +++ b/src/DSL/Queries/FullText/Intervals/AnyOf.php @@ -1,5 +1,7 @@ isPropertyField(false) + ->fieldKeyed(false) ->multi(true); return $this->addProperty('intervals', $intervals); } @@ -32,10 +34,10 @@ public function intervals($intervals) * @param mixed $interval * @return static */ - public function addInterval($interval) + public function addInterval($interval): static { if (!isset($this->_properties['intervals'])) { - $this->_properties['intervals'] = (new Intervals())->isPropertyField(false)->multi(true); + $this->_properties['intervals'] = (new Intervals())->fieldKeyed(false)->multi(true); } $target = $this->_properties['intervals']; if ($interval instanceof \Closure) { @@ -53,7 +55,7 @@ public function addInterval($interval) * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { return $this->addProperty('filter', Filter::create($filter)); } diff --git a/src/DSL/Queries/FullText/Intervals/Filter.php b/src/DSL/Queries/FullText/Intervals/Filter.php index 940b5a2..a2ae9a0 100644 --- a/src/DSL/Queries/FullText/Intervals/Filter.php +++ b/src/DSL/Queries/FullText/Intervals/Filter.php @@ -1,5 +1,7 @@ addProperty('after', Query::create($after)); } @@ -31,7 +35,7 @@ public function after($after) * @param mixed $before * @return static */ - public function before($before) + public function before($before): static { return $this->addProperty('before', Query::create($before)); } @@ -43,7 +47,7 @@ public function before($before) * @param mixed $containedBy * @return static */ - public function containedBy($containedBy) + public function containedBy($containedBy): static { return $this->addProperty('contained_by', Query::create($containedBy)); } @@ -55,7 +59,7 @@ public function containedBy($containedBy) * @param mixed $containing * @return static */ - public function containing($containing) + public function containing($containing): static { return $this->addProperty('containing', Query::create($containing)); } @@ -67,7 +71,7 @@ public function containing($containing) * @param mixed $notContaining * @return static */ - public function notContaining($notContaining) + public function notContaining($notContaining): static { return $this->addProperty('not_containing', Query::create($notContaining)); } @@ -79,7 +83,7 @@ public function notContaining($notContaining) * @param mixed $overlapping * @return static */ - public function overlapping($overlapping) + public function overlapping($overlapping): static { return $this->addProperty('overlapping', Query::create($overlapping)); } @@ -92,7 +96,7 @@ public function overlapping($overlapping) * @param mixed $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', Script::create($script)); } @@ -104,7 +108,7 @@ public function script($script) * @param mixed $notContainedBy * @return static */ - public function notContainedBy($notContainedBy) + public function notContainedBy($notContainedBy): static { return $this->addProperty('not_contained_by', Query::create($notContainedBy)); } @@ -116,7 +120,7 @@ public function notContainedBy($notContainedBy) * @param mixed $notOverlapping * @return static */ - public function notOverlapping($notOverlapping) + public function notOverlapping($notOverlapping): static { return $this->addProperty('not_overlapping', Query::create($notOverlapping)); } diff --git a/src/DSL/Queries/FullText/Intervals/Fuzzy.php b/src/DSL/Queries/FullText/Intervals/Fuzzy.php index 1a62ed3..9638bf8 100644 --- a/src/DSL/Queries/FullText/Intervals/Fuzzy.php +++ b/src/DSL/Queries/FullText/Intervals/Fuzzy.php @@ -1,5 +1,7 @@ addProperty('term', $term); } @@ -31,7 +33,7 @@ public function term($term) * @param int $prefixLength * @return static */ - public function prefixLength($prefixLength) + public function prefixLength(int $prefixLength): static { return $this->addProperty('prefix_length', $prefixLength); } @@ -43,7 +45,7 @@ public function prefixLength($prefixLength) * @param bool $transpositions * @return static */ - public function transpositions($transpositions) + public function transpositions(bool $transpositions): static { return $this->addProperty('transpositions', $transpositions); } @@ -52,10 +54,10 @@ public function transpositions($transpositions) * Maximum edit distance allowed for matching. * Defaults to auto. * - * @param string $fuzziness + * @param int|string $fuzziness * @return static */ - public function fuzziness($fuzziness) + public function fuzziness(int|string $fuzziness): static { return $this->addProperty('fuzziness', $fuzziness); } @@ -67,7 +69,7 @@ public function fuzziness($fuzziness) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -80,7 +82,7 @@ public function analyzer($analyzer) * @param string $useField * @return static */ - public function useField($useField) + public function useField(string $useField): static { return $this->addProperty('use_field', $useField); } diff --git a/src/DSL/Queries/FullText/Intervals/Match_.php b/src/DSL/Queries/FullText/Intervals/Match_.php index 6c7e8f9..1cadd4a 100644 --- a/src/DSL/Queries/FullText/Intervals/Match_.php +++ b/src/DSL/Queries/FullText/Intervals/Match_.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -33,7 +35,7 @@ public function query($query) * @param int $maxGaps * @return static */ - public function maxGaps($maxGaps) + public function maxGaps(int $maxGaps): static { return $this->addProperty('max_gaps', $maxGaps); } @@ -45,7 +47,7 @@ public function maxGaps($maxGaps) * @param bool $ordered * @return static */ - public function ordered($ordered = false) + public function ordered(bool $ordered = false): static { return $this->addProperty('ordered', $ordered); } @@ -57,7 +59,7 @@ public function ordered($ordered = false) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -68,7 +70,7 @@ public function analyzer($analyzer) * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { return $this->addProperty('filter', Filter::create($filter)); } @@ -81,7 +83,7 @@ public function filter($filter) * @param string $useField * @return static */ - public function useField($useField) + public function useField(string $useField): static { return $this->addProperty('use_field', $useField); } diff --git a/src/DSL/Queries/FullText/Intervals/Prefix.php b/src/DSL/Queries/FullText/Intervals/Prefix.php index 2ff087e..13eaef4 100644 --- a/src/DSL/Queries/FullText/Intervals/Prefix.php +++ b/src/DSL/Queries/FullText/Intervals/Prefix.php @@ -1,5 +1,7 @@ addProperty('prefix', $prefix); } @@ -32,7 +34,7 @@ public function prefix($prefix) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -45,7 +47,7 @@ public function analyzer($analyzer) * @param string $userField * @return static */ - public function useField($userField) + public function useField(string $userField): static { return $this->addProperty('use_field', $userField); } diff --git a/src/DSL/Queries/FullText/Intervals/Range.php b/src/DSL/Queries/FullText/Intervals/Range.php index 9237c3d..bfb7a6e 100644 --- a/src/DSL/Queries/FullText/Intervals/Range.php +++ b/src/DSL/Queries/FullText/Intervals/Range.php @@ -1,5 +1,7 @@ addProperty('gte', $gte); } /** - * (Optional) Greater than the specified value. + * Greater than the specified value. * - * @param mixed $gt + * @param string|int|float|bool $gt * @return static */ - public function gt($gt) + public function gt(string|int|float|bool $gt): static { return $this->addProperty('gt', $gt); } /** - * (Optional) Less than or equal to the specified value. + * Less than or equal to the specified value. * - * @param mixed $lte + * @param string|int|float|bool $lte * @return static */ - public function lte($lte) + public function lte(string|int|float|bool $lte): static { return $this->addProperty('lte', $lte); } /** - * (Optional) Less than the specified value. + * Less than the specified value. * - * @param mixed $lt + * @param string|int|float|bool $lt * @return static */ - public function lt($lt) + public function lt(string|int|float|bool $lt): static { return $this->addProperty('lt', $lt); } @@ -66,7 +68,7 @@ public function lt($lt) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -78,7 +80,7 @@ public function analyzer($analyzer) * @param string $useField * @return static */ - public function useField($useField) + public function useField(string $useField): static { return $this->addProperty('use_field', $useField); } diff --git a/src/DSL/Queries/FullText/Intervals/Wildcard.php b/src/DSL/Queries/FullText/Intervals/Wildcard.php index 0a3174c..43fe8e3 100644 --- a/src/DSL/Queries/FullText/Intervals/Wildcard.php +++ b/src/DSL/Queries/FullText/Intervals/Wildcard.php @@ -1,5 +1,7 @@ addProperty('pattern', $pattern); } @@ -32,7 +34,7 @@ public function pattern($pattern) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -45,7 +47,7 @@ public function analyzer($analyzer) * @param string $useField * @return static */ - public function useField($useField) + public function useField(string $useField): static { return $this->addProperty('use_field', $useField); } diff --git a/src/DSL/Queries/FullText/MatchBoolPrefix.php b/src/DSL/Queries/FullText/MatchBoolPrefix.php index 9d41172..50ee452 100644 --- a/src/DSL/Queries/FullText/MatchBoolPrefix.php +++ b/src/DSL/Queries/FullText/MatchBoolPrefix.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -37,7 +39,7 @@ public function query($query) * @param int $maxExpansions * @return static */ - public function maxExpansions($maxExpansions) + public function maxExpansions(int $maxExpansions): static { return $this->addProperty('max_expansions', $maxExpansions); } @@ -49,7 +51,7 @@ public function maxExpansions($maxExpansions) * @param bool $lenient * @return static */ - public function lenient($lenient) + public function lenient(bool $lenient): static { return $this->addProperty('lenient', $lenient); } @@ -61,7 +63,7 @@ public function lenient($lenient) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -70,10 +72,10 @@ public function analyzer($analyzer) * Minimum number of clauses that must match for a * document to be returned. * - * @param string $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -81,10 +83,10 @@ public function minimumShouldMatch($minimumShouldMatch) /** * Maximum edit distance allowed for fuzzy matching. * - * @param string $fuzziness + * @param int|string $fuzziness * @return static */ - public function fuzziness($fuzziness) + public function fuzziness(int|string $fuzziness): static { return $this->addProperty('fuzziness', $fuzziness); } @@ -96,7 +98,7 @@ public function fuzziness($fuzziness) * @param int $prefixLength * @return static */ - public function prefixLength($prefixLength) + public function prefixLength(int $prefixLength): static { return $this->addProperty('prefix_length', $prefixLength); } @@ -108,7 +110,7 @@ public function prefixLength($prefixLength) * @param bool $fuzzyTranspositions * @return static */ - public function fuzzyTranspositions($fuzzyTranspositions) + public function fuzzyTranspositions(bool $fuzzyTranspositions): static { return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); } @@ -119,7 +121,7 @@ public function fuzzyTranspositions($fuzzyTranspositions) * @param string $fuzzyRewrite * @return static */ - public function fuzzyRewrite($fuzzyRewrite) + public function fuzzyRewrite(string $fuzzyRewrite): static { return $this->addProperty('fuzzy_rewrite', $fuzzyRewrite); } @@ -131,7 +133,7 @@ public function fuzzyRewrite($fuzzyRewrite) * @param string $operator * @return static */ - public function operator($operator) + public function operator(string $operator): static { return $this->addProperty('operator', $operator); } diff --git a/src/DSL/Queries/FullText/MatchPhrase.php b/src/DSL/Queries/FullText/MatchPhrase.php index 2ca8a03..83df915 100644 --- a/src/DSL/Queries/FullText/MatchPhrase.php +++ b/src/DSL/Queries/FullText/MatchPhrase.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -37,7 +39,7 @@ public function query($query) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -49,7 +51,7 @@ public function analyzer($analyzer) * @param int $slop * @return static */ - public function slop($slop) + public function slop(int $slop): static { return $this->addProperty('slop', $slop); } @@ -62,7 +64,7 @@ public function slop($slop) * @param string $zeroTermsQuery * @return static */ - public function zeroTermsQuery($zeroTermsQuery) + public function zeroTermsQuery(string $zeroTermsQuery): static { return $this->addProperty('zero_terms_query', $zeroTermsQuery); } diff --git a/src/DSL/Queries/FullText/MatchPhrasePrefix.php b/src/DSL/Queries/FullText/MatchPhrasePrefix.php index ee99983..c907d57 100644 --- a/src/DSL/Queries/FullText/MatchPhrasePrefix.php +++ b/src/DSL/Queries/FullText/MatchPhrasePrefix.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -38,7 +40,7 @@ public function query($query) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -50,7 +52,7 @@ public function analyzer($analyzer) * @param int $maxExpansions * @return static */ - public function maxExpansions($maxExpansions) + public function maxExpansions(int $maxExpansions): static { return $this->addProperty('max_expansions', $maxExpansions); } @@ -62,7 +64,7 @@ public function maxExpansions($maxExpansions) * @param int $slop * @return static */ - public function slop($slop) + public function slop(int $slop): static { return $this->addProperty('slop', $slop); } @@ -75,7 +77,7 @@ public function slop($slop) * @param string $zeroTermsQuery * @return static */ - public function zeroTermsQuery($zeroTermsQuery) + public function zeroTermsQuery(string $zeroTermsQuery): static { return $this->addProperty('zero_terms_query', $zeroTermsQuery); } diff --git a/src/DSL/Queries/FullText/Match_.php b/src/DSL/Queries/FullText/Match_.php index f57ca8b..45c8947 100644 --- a/src/DSL/Queries/FullText/Match_.php +++ b/src/DSL/Queries/FullText/Match_.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -39,7 +41,7 @@ public function query($query) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -51,7 +53,7 @@ public function analyzer($analyzer) * @param bool $autoGenerateSynonymsPhraseQuery * @return static */ - public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery) + public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static { return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); } @@ -60,10 +62,10 @@ public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery * Maximum edit distance allowed for matching. * See Fuzziness for valid values and more information. * - * @param string $fuzziness + * @param int|string $fuzziness * @return static */ - public function fuzziness($fuzziness) + public function fuzziness(int|string $fuzziness): static { return $this->addProperty('fuzziness', $fuzziness); } @@ -75,7 +77,7 @@ public function fuzziness($fuzziness) * @param int $maxExpansions * @return static */ - public function maxExpansions($maxExpansions) + public function maxExpansions(int $maxExpansions): static { return $this->addProperty('max_expansions', $maxExpansions); } @@ -87,7 +89,7 @@ public function maxExpansions($maxExpansions) * @param int $prefixLength * @return static */ - public function prefixLength($prefixLength) + public function prefixLength(int $prefixLength): static { return $this->addProperty('prefix_length', $prefixLength); } @@ -99,7 +101,7 @@ public function prefixLength($prefixLength) * @param bool $fuzzyTranspositions * @return static */ - public function fuzzyTranspositions($fuzzyTranspositions) + public function fuzzyTranspositions(bool $fuzzyTranspositions): static { return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); } @@ -112,7 +114,7 @@ public function fuzzyTranspositions($fuzzyTranspositions) * @param string $fuzzyRewrite * @return static */ - public function fuzzyRewrite($fuzzyRewrite) + public function fuzzyRewrite(string $fuzzyRewrite): static { return $this->addProperty('fuzzy_rewrite', $fuzzyRewrite); } @@ -124,7 +126,7 @@ public function fuzzyRewrite($fuzzyRewrite) * @param bool $lenient * @return static */ - public function lenient($lenient) + public function lenient(bool $lenient): static { return $this->addProperty('lenient', $lenient); } @@ -136,7 +138,7 @@ public function lenient($lenient) * @param string $operator * @return static */ - public function operator($operator) + public function operator(string $operator): static { return $this->addProperty('operator', $operator); } @@ -145,10 +147,10 @@ public function operator($operator) * Minimum number of clauses that must match for a * document to be returned. * - * @param string $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -161,7 +163,7 @@ public function minimumShouldMatch($minimumShouldMatch) * @param string $zeroTermsQuery * @return static */ - public function zeroTermsQuery($zeroTermsQuery) + public function zeroTermsQuery(string $zeroTermsQuery): static { return $this->addProperty('zero_terms_query', $zeroTermsQuery); } diff --git a/src/DSL/Queries/FullText/MultiMatch.php b/src/DSL/Queries/FullText/MultiMatch.php index 768bec5..048c222 100644 --- a/src/DSL/Queries/FullText/MultiMatch.php +++ b/src/DSL/Queries/FullText/MultiMatch.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -33,7 +35,7 @@ public function query($query) * @param array $fields * @return static */ - public function fields($fields) + public function fields(array $fields): static { return $this->addProperty('fields', $fields); } @@ -46,7 +48,7 @@ public function fields($fields) * @param string $type * @return static */ - public function type($type) + public function type(string $type): static { return $this->addProperty('type', $type); } @@ -58,7 +60,7 @@ public function type($type) * @param string $operator * @return static */ - public function operator($operator) + public function operator(string $operator): static { return $this->addProperty('operator', $operator); } @@ -70,7 +72,7 @@ public function operator($operator) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -79,10 +81,10 @@ public function analyzer($analyzer) * Minimum number of clauses that must match for a * document to be returned. * - * @param string $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -94,7 +96,7 @@ public function minimumShouldMatch($minimumShouldMatch) * @param float $tieBreaker * @return static */ - public function tieBreaker($tieBreaker) + public function tieBreaker(float $tieBreaker): static { return $this->addProperty('tie_breaker', $tieBreaker); } @@ -102,10 +104,10 @@ public function tieBreaker($tieBreaker) /** * Maximum edit distance allowed for fuzzy matching. * - * @param string $fuzziness + * @param int|string $fuzziness * @return static */ - public function fuzziness($fuzziness) + public function fuzziness(int|string $fuzziness): static { return $this->addProperty('fuzziness', $fuzziness); } @@ -117,7 +119,7 @@ public function fuzziness($fuzziness) * @param int $prefixLength * @return static */ - public function prefixLength($prefixLength) + public function prefixLength(int $prefixLength): static { return $this->addProperty('prefix_length', $prefixLength); } @@ -129,7 +131,7 @@ public function prefixLength($prefixLength) * @param int $maxExpansions * @return static */ - public function maxExpansions($maxExpansions) + public function maxExpansions(int $maxExpansions): static { return $this->addProperty('max_expansions', $maxExpansions); } @@ -141,7 +143,7 @@ public function maxExpansions($maxExpansions) * @param bool $fuzzyTranspositions * @return static */ - public function fuzzyTranspositions($fuzzyTranspositions) + public function fuzzyTranspositions(bool $fuzzyTranspositions): static { return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); } @@ -152,7 +154,7 @@ public function fuzzyTranspositions($fuzzyTranspositions) * @param string $fuzzyRewrite * @return static */ - public function fuzzyRewrite($fuzzyRewrite) + public function fuzzyRewrite(string $fuzzyRewrite): static { return $this->addProperty('fuzzy_rewrite', $fuzzyRewrite); } @@ -164,7 +166,7 @@ public function fuzzyRewrite($fuzzyRewrite) * @param bool $lenient * @return static */ - public function lenient($lenient) + public function lenient(bool $lenient): static { return $this->addProperty('lenient', $lenient); } @@ -177,7 +179,7 @@ public function lenient($lenient) * @param string $zeroTermsQuery * @return static */ - public function zeroTermsQuery($zeroTermsQuery) + public function zeroTermsQuery(string $zeroTermsQuery): static { return $this->addProperty('zero_terms_query', $zeroTermsQuery); } @@ -189,7 +191,7 @@ public function zeroTermsQuery($zeroTermsQuery) * @param int $slop * @return static */ - public function slop($slop) + public function slop(int $slop): static { return $this->addProperty('slop', $slop); } @@ -201,7 +203,7 @@ public function slop($slop) * @param bool $autoGenerateSynonymsPhraseQuery * @return static */ - public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery) + public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static { return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); } diff --git a/src/DSL/Queries/FullText/QueryString.php b/src/DSL/Queries/FullText/QueryString.php index 8446b3e..1d4b757 100644 --- a/src/DSL/Queries/FullText/QueryString.php +++ b/src/DSL/Queries/FullText/QueryString.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -32,7 +34,7 @@ public function query($query) * @param string $defaultField * @return static */ - public function defaultField($defaultField) + public function defaultField(string $defaultField): static { return $this->addProperty('default_field', $defaultField); } @@ -44,7 +46,7 @@ public function defaultField($defaultField) * @param bool $allowLeadingWildcard * @return static */ - public function allowLeadingWildcard($allowLeadingWildcard) + public function allowLeadingWildcard(bool $allowLeadingWildcard): static { return $this->addProperty('allow_leading_wildcard', $allowLeadingWildcard); } @@ -57,7 +59,7 @@ public function allowLeadingWildcard($allowLeadingWildcard) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -69,7 +71,7 @@ public function analyzer($analyzer) * @param bool $autoGenerateSynonymsPhraseQuery * @return static */ - public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery) + public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static { return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); } @@ -82,7 +84,7 @@ public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery * @param string $defaultOperator * @return static */ - public function defaultOperator($defaultOperator) + public function defaultOperator(string $defaultOperator): static { return $this->addProperty('default_operator', $defaultOperator); } @@ -94,7 +96,7 @@ public function defaultOperator($defaultOperator) * @param bool $enablePositionIncrements * @return static */ - public function enablePositionIncrements($enablePositionIncrements) + public function enablePositionIncrements(bool $enablePositionIncrements): static { return $this->addProperty('enable_position_increments', $enablePositionIncrements); } @@ -106,7 +108,7 @@ public function enablePositionIncrements($enablePositionIncrements) * @param array $fields * @return static */ - public function fields($fields) + public function fields(array $fields): static { return $this->addProperty('fields', $fields); } @@ -114,10 +116,10 @@ public function fields($fields) /** * Maximum edit distance allowed for fuzzy matching. * - * @param string $fuzziness + * @param int|string $fuzziness * @return static */ - public function fuzziness($fuzziness) + public function fuzziness(int|string $fuzziness): static { return $this->addProperty('fuzziness', $fuzziness); } @@ -129,7 +131,7 @@ public function fuzziness($fuzziness) * @param int $fuzzyMaxExpansions * @return static */ - public function fuzzyMaxExpansions($fuzzyMaxExpansions) + public function fuzzyMaxExpansions(int $fuzzyMaxExpansions): static { return $this->addProperty('fuzzy_max_expansions', $fuzzyMaxExpansions); } @@ -141,7 +143,7 @@ public function fuzzyMaxExpansions($fuzzyMaxExpansions) * @param int $fuzzyPrefixLength * @return static */ - public function fuzzyPrefixLength($fuzzyPrefixLength) + public function fuzzyPrefixLength(int $fuzzyPrefixLength): static { return $this->addProperty('fuzzy_prefix_length', $fuzzyPrefixLength); } @@ -153,7 +155,7 @@ public function fuzzyPrefixLength($fuzzyPrefixLength) * @param bool $fuzzyTranspositions * @return static */ - public function fuzzyTranspositions($fuzzyTranspositions) + public function fuzzyTranspositions(bool $fuzzyTranspositions): static { return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); } @@ -165,7 +167,7 @@ public function fuzzyTranspositions($fuzzyTranspositions) * @param bool $lenient * @return static */ - public function lenient($lenient) + public function lenient(bool $lenient): static { return $this->addProperty('lenient', $lenient); } @@ -177,7 +179,7 @@ public function lenient($lenient) * @param int $maxDeterminizedStates * @return static */ - public function maxDeterminizedStates($maxDeterminizedStates) + public function maxDeterminizedStates(int $maxDeterminizedStates): static { return $this->addProperty('max_determinized_states', $maxDeterminizedStates); } @@ -186,10 +188,10 @@ public function maxDeterminizedStates($maxDeterminizedStates) * Minimum number of clauses that must match for a * document to be returned. * - * @param string $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -202,7 +204,7 @@ public function minimumShouldMatch($minimumShouldMatch) * @param string $quoteAnalyzer * @return static */ - public function quoteAnalyzer($quoteAnalyzer) + public function quoteAnalyzer(string $quoteAnalyzer): static { return $this->addProperty('quote_analyzer', $quoteAnalyzer); } @@ -215,7 +217,7 @@ public function quoteAnalyzer($quoteAnalyzer) * @param int $phraseSlop * @return static */ - public function phraseSlop($phraseSlop) + public function phraseSlop(int $phraseSlop): static { return $this->addProperty('phrase_slop', $phraseSlop); } @@ -228,7 +230,7 @@ public function phraseSlop($phraseSlop) * @param string $quoteFieldSuffix * @return static */ - public function quoteFieldSuffix($quoteFieldSuffix) + public function quoteFieldSuffix(string $quoteFieldSuffix): static { return $this->addProperty('quote_field_suffix', $quoteFieldSuffix); } @@ -239,7 +241,7 @@ public function quoteFieldSuffix($quoteFieldSuffix) * @param string $rewrite * @return static */ - public function rewrite($rewrite) + public function rewrite(string $rewrite): static { return $this->addProperty('rewrite', $rewrite); } @@ -251,7 +253,7 @@ public function rewrite($rewrite) * @param string $timeZone * @return static */ - public function timeZone($timeZone) + public function timeZone(string $timeZone): static { return $this->addProperty('time_zone', $timeZone); } @@ -264,7 +266,7 @@ public function timeZone($timeZone) * @param string $type * @return static */ - public function type($type) + public function type(string $type): static { return $this->addProperty('type', $type); } @@ -276,7 +278,7 @@ public function type($type) * @param bool $analyzeWildcard * @return static */ - public function analyzeWildcard($analyzeWildcard) + public function analyzeWildcard(bool $analyzeWildcard): static { return $this->addProperty('analyze_wildcard', $analyzeWildcard); } @@ -288,7 +290,7 @@ public function analyzeWildcard($analyzeWildcard) * @param float $tieBreaker * @return static */ - public function tieBreaker($tieBreaker) + public function tieBreaker(float $tieBreaker): static { return $this->addProperty('tie_breaker', $tieBreaker); } diff --git a/src/DSL/Queries/FullText/SimpleQueryString.php b/src/DSL/Queries/FullText/SimpleQueryString.php index 5b475c9..84666d3 100644 --- a/src/DSL/Queries/FullText/SimpleQueryString.php +++ b/src/DSL/Queries/FullText/SimpleQueryString.php @@ -1,5 +1,7 @@ addProperty('query', $query); } @@ -33,7 +35,7 @@ public function query($query) * @param array $fields * @return static */ - public function fields($fields) + public function fields(array $fields): static { return $this->addProperty('fields', $fields); } @@ -46,7 +48,7 @@ public function fields($fields) * @param string $defaultOperator * @return static */ - public function defaultOperator($defaultOperator) + public function defaultOperator(string $defaultOperator): static { return $this->addProperty('default_operator', $defaultOperator); } @@ -58,7 +60,7 @@ public function defaultOperator($defaultOperator) * @param bool $analyzeWildcard * @return static */ - public function analyzeWildcard($analyzeWildcard) + public function analyzeWildcard(bool $analyzeWildcard): static { return $this->addProperty('analyze_wildcard', $analyzeWildcard); } @@ -71,7 +73,7 @@ public function analyzeWildcard($analyzeWildcard) * @param string $analyzer * @return static */ - public function analyzer($analyzer) + public function analyzer(string $analyzer): static { return $this->addProperty('analyzer', $analyzer); } @@ -83,7 +85,7 @@ public function analyzer($analyzer) * @param bool $autoGenerateSynonymsPhraseQuery * @return static */ - public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery) + public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static { return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); } @@ -95,7 +97,7 @@ public function autoGenerateSynonymsPhraseQuery($autoGenerateSynonymsPhraseQuery * @param string $flags * @return static */ - public function flags($flags) + public function flags(string $flags): static { return $this->addProperty('flags', $flags); } @@ -107,7 +109,7 @@ public function flags($flags) * @param int $fuzzyMaxExpansions * @return static */ - public function fuzzyMaxExpansions($fuzzyMaxExpansions) + public function fuzzyMaxExpansions(int $fuzzyMaxExpansions): static { return $this->addProperty('fuzzy_max_expansions', $fuzzyMaxExpansions); } @@ -119,7 +121,7 @@ public function fuzzyMaxExpansions($fuzzyMaxExpansions) * @param int $fuzzyPrefixLength * @return static */ - public function fuzzyPrefixLength($fuzzyPrefixLength) + public function fuzzyPrefixLength(int $fuzzyPrefixLength): static { return $this->addProperty('fuzzy_prefix_length', $fuzzyPrefixLength); } @@ -131,7 +133,7 @@ public function fuzzyPrefixLength($fuzzyPrefixLength) * @param bool $fuzzyTranspositions * @return static */ - public function fuzzyTranspositions($fuzzyTranspositions) + public function fuzzyTranspositions(bool $fuzzyTranspositions): static { return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); } @@ -143,7 +145,7 @@ public function fuzzyTranspositions($fuzzyTranspositions) * @param bool $lenient * @return static */ - public function lenient($lenient) + public function lenient(bool $lenient): static { return $this->addProperty('lenient', $lenient); } @@ -152,10 +154,10 @@ public function lenient($lenient) * Minimum number of clauses that must match for a * document to be returned. * - * @param string $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -168,7 +170,7 @@ public function minimumShouldMatch($minimumShouldMatch) * @param string $quoteFieldSuffix * @return static */ - public function quoteFieldSuffix($quoteFieldSuffix) + public function quoteFieldSuffix(string $quoteFieldSuffix): static { return $this->addProperty('quote_field_suffix', $quoteFieldSuffix); } diff --git a/src/DSL/Queries/Geo.php b/src/DSL/Queries/Geo.php index ddddf22..631bbb3 100644 --- a/src/DSL/Queries/Geo.php +++ b/src/DSL/Queries/Geo.php @@ -1,5 +1,7 @@ addProperty('top_left', $topLeft); } @@ -32,7 +34,7 @@ public function topLeft($topLeft) * @param mixed $bottomRight * @return static */ - public function bottomRight($bottomRight) + public function bottomRight($bottomRight): static { return $this->addProperty('bottom_right', $bottomRight); } @@ -43,7 +45,7 @@ public function bottomRight($bottomRight) * @param float $top * @return static */ - public function top($top) + public function top(float $top): static { return $this->addProperty('top', $top); } @@ -54,7 +56,7 @@ public function top($top) * @param float $left * @return static */ - public function left($left) + public function left(float $left): static { return $this->addProperty('left', $left); } @@ -65,7 +67,7 @@ public function left($left) * @param float $bottom * @return static */ - public function bottom($bottom) + public function bottom(float $bottom): static { return $this->addProperty('bottom', $bottom); } @@ -76,7 +78,7 @@ public function bottom($bottom) * @param float $right * @return static */ - public function right($right) + public function right(float $right): static { return $this->addProperty('right', $right); } @@ -87,7 +89,7 @@ public function right($right) * @param string $wkt * @return static */ - public function wkt($wkt) + public function wkt(string $wkt): static { return $this->addProperty('wkt', $wkt); } @@ -98,7 +100,7 @@ public function wkt($wkt) * @param mixed $topRight * @return static */ - public function topRight($topRight) + public function topRight($topRight): static { return $this->addProperty('top_right', $topRight); } @@ -109,7 +111,7 @@ public function topRight($topRight) * @param mixed $bottomLeft * @return static */ - public function bottomLeft($bottomLeft) + public function bottomLeft($bottomLeft): static { return $this->addProperty('bottom_left', $bottomLeft); } @@ -121,7 +123,7 @@ public function bottomLeft($bottomLeft) * @param string $validationMethod * @return static */ - public function validationMethod($validationMethod) + public function validationMethod(string $validationMethod): static { return $this->addProperty('validation_method', $validationMethod); } @@ -133,7 +135,7 @@ public function validationMethod($validationMethod) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Queries/Geo/GeoDistance.php b/src/DSL/Queries/Geo/GeoDistance.php index fca2402..6f5b892 100644 --- a/src/DSL/Queries/Geo/GeoDistance.php +++ b/src/DSL/Queries/Geo/GeoDistance.php @@ -1,5 +1,7 @@ addProperty('distance', $distance); } @@ -39,7 +41,7 @@ public function distance($distance) * @param mixed $location * @return static */ - public function location($field, $location) + public function location(string $field, $location): static { return $this->addProperty($field, $location); } @@ -51,7 +53,7 @@ public function location($field, $location) * @param string $distanceType * @return static */ - public function distanceType($distanceType) + public function distanceType(string $distanceType): static { return $this->addProperty('distance_type', $distanceType); } @@ -64,7 +66,7 @@ public function distanceType($distanceType) * @SuppressWarnings(PHPMD.CamelCaseParameterName) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ - public function _name($_name) + public function _name(string $_name): static { return $this->addProperty('_name', $_name); } @@ -76,7 +78,7 @@ public function _name($_name) * @param string $validationMethod * @return static */ - public function validationMethod($validationMethod) + public function validationMethod(string $validationMethod): static { return $this->addProperty('validation_method', $validationMethod); } diff --git a/src/DSL/Queries/Geo/GeoGrid.php b/src/DSL/Queries/Geo/GeoGrid.php index d6fdb98..64bea1d 100644 --- a/src/DSL/Queries/Geo/GeoGrid.php +++ b/src/DSL/Queries/Geo/GeoGrid.php @@ -1,5 +1,7 @@ addProperty('geohex', $geohex); } @@ -35,7 +37,7 @@ public function geohex($geohex) * @param string $geotile * @return static */ - public function geotile($geotile) + public function geotile(string $geotile): static { return $this->addProperty('geotile', $geotile); } @@ -47,7 +49,7 @@ public function geotile($geotile) * @param string $geohash * @return static */ - public function geohash($geohash) + public function geohash(string $geohash): static { return $this->addProperty('geohash', $geohash); } diff --git a/src/DSL/Queries/Geo/GeoPolygon.php b/src/DSL/Queries/Geo/GeoPolygon.php index d456e23..9e3fbbf 100644 --- a/src/DSL/Queries/Geo/GeoPolygon.php +++ b/src/DSL/Queries/Geo/GeoPolygon.php @@ -1,5 +1,7 @@ > $points * @return static */ - public function points($points) + public function points(array $points): static { return $this->addProperty('points', $points); } @@ -34,7 +36,7 @@ public function points($points) * @param string $validationMethod * @return static */ - public function validationMethod($validationMethod) + public function validationMethod(string $validationMethod): static { return $this->addProperty('validation_method', $validationMethod); } @@ -46,7 +48,7 @@ public function validationMethod($validationMethod) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Queries/Geo/GeoShape.php b/src/DSL/Queries/Geo/GeoShape.php index 638ed51..2dfb933 100644 --- a/src/DSL/Queries/Geo/GeoShape.php +++ b/src/DSL/Queries/Geo/GeoShape.php @@ -1,5 +1,7 @@ addProperty('shape', $shape); } @@ -37,7 +39,7 @@ public function shape($shape) * @param string $relation * @return static */ - public function relation($relation) + public function relation(string $relation): static { return $this->addProperty('relation', $relation); } @@ -49,7 +51,7 @@ public function relation($relation) * @param mixed $indexedShape * @return static */ - public function indexedShape($indexedShape) + public function indexedShape($indexedShape): static { return $this->addProperty('indexed_shape', $indexedShape); } @@ -61,7 +63,7 @@ public function indexedShape($indexedShape) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Queries/Joining.php b/src/DSL/Queries/Joining.php index d814469..bb35ae9 100644 --- a/src/DSL/Queries/Joining.php +++ b/src/DSL/Queries/Joining.php @@ -1,5 +1,7 @@ addProperty('type', $type); } @@ -32,7 +34,7 @@ public function type($type) * @param mixed $query * @return static */ - public function query($query) + public function query($query): static { return $this->addProperty('query', Query::create($query)); } @@ -44,7 +46,7 @@ public function query($query) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } @@ -56,7 +58,7 @@ public function ignoreUnmapped($ignoreUnmapped) * @param int $maxChildren * @return static */ - public function maxChildren($maxChildren) + public function maxChildren(int $maxChildren): static { return $this->addProperty('max_children', $maxChildren); } @@ -69,7 +71,7 @@ public function maxChildren($maxChildren) * @param int $minChildren * @return static */ - public function minChildren($minChildren) + public function minChildren(int $minChildren): static { return $this->addProperty('min_children', $minChildren); } @@ -81,7 +83,7 @@ public function minChildren($minChildren) * @param string $scoreMode * @return static */ - public function scoreMode($scoreMode) + public function scoreMode(string $scoreMode): static { return $this->addProperty('score_mode', $scoreMode); } diff --git a/src/DSL/Queries/Joining/HasParent.php b/src/DSL/Queries/Joining/HasParent.php index 17c0c16..f13d68c 100644 --- a/src/DSL/Queries/Joining/HasParent.php +++ b/src/DSL/Queries/Joining/HasParent.php @@ -1,5 +1,7 @@ addProperty('parent_type', $parentType); } @@ -32,7 +34,7 @@ public function parentType($parentType) * @param mixed $query * @return static */ - public function query($query) + public function query($query): static { return $this->addProperty('query', Query::create($query)); } @@ -44,7 +46,7 @@ public function query($query) * @param bool $score * @return static */ - public function score($score) + public function score(bool $score): static { return $this->addProperty('score', $score); } @@ -56,7 +58,7 @@ public function score($score) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Queries/Joining/Nested.php b/src/DSL/Queries/Joining/Nested.php index 4849437..97c762f 100644 --- a/src/DSL/Queries/Joining/Nested.php +++ b/src/DSL/Queries/Joining/Nested.php @@ -1,5 +1,7 @@ path($field); @@ -38,7 +40,7 @@ public static function create($field = null, $value = null) * @param string $path * @return static */ - public function path($path) + public function path(string $path): static { return $this->addProperty('path', $path); } @@ -50,7 +52,7 @@ public function path($path) * @param mixed $query * @return static */ - public function query($query) + public function query($query): static { return $this->addProperty('query', Query::create($query)); } @@ -62,7 +64,7 @@ public function query($query) * @param string $scoreMode * @return static */ - public function scoreMode($scoreMode) + public function scoreMode(string $scoreMode): static { return $this->addProperty('score_mode', $scoreMode); } @@ -74,7 +76,7 @@ public function scoreMode($scoreMode) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Queries/Joining/ParentId.php b/src/DSL/Queries/Joining/ParentId.php index 6be7e8a..040b300 100644 --- a/src/DSL/Queries/Joining/ParentId.php +++ b/src/DSL/Queries/Joining/ParentId.php @@ -1,5 +1,7 @@ addProperty('type', $type); } @@ -30,7 +32,7 @@ public function type($type) * @param string $id * @return static */ - public function id($id) + public function id(string $id): static { return $this->addProperty('id', $id); } @@ -42,7 +44,7 @@ public function id($id) * @param bool $ignoreUnmapped * @return static */ - public function ignoreUnmapped($ignoreUnmapped) + public function ignoreUnmapped(bool $ignoreUnmapped): static { return $this->addProperty('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/DSL/Queries/MatchAll.php b/src/DSL/Queries/MatchAll.php index efb892a..337b63f 100644 --- a/src/DSL/Queries/MatchAll.php +++ b/src/DSL/Queries/MatchAll.php @@ -1,5 +1,7 @@ addProperty('id', $id); } /** - * (Optional) The script language. Defaults to painless. + * The script language. Defaults to painless. * * @param string $lang * @return static */ - public function lang($lang) + public function lang(string $lang): static { return $this->addProperty('lang', $lang); } /** - * (Required) The inline script source to execute. + * The inline script source to execute. * * @param string $source * @return static */ - public function source($source) + public function source(string $source): static { return $this->addProperty('source', $source); } /** - * (Optional) Named parameters passed into the script. + * Named parameters passed into the script. * * @param array $params * @return static */ - public function params($params) + public function params(array $params): static { return $this->addProperty('params', $params); } diff --git a/src/DSL/Queries/Shape.php b/src/DSL/Queries/Shape.php index 1980745..1c2710a 100644 --- a/src/DSL/Queries/Shape.php +++ b/src/DSL/Queries/Shape.php @@ -1,5 +1,7 @@ addProperty('shape', $shape); } @@ -35,7 +37,7 @@ public function shape($shape) * @param string $relation * @return static */ - public function relation($relation) + public function relation(string $relation): static { return $this->addProperty('relation', $relation); } @@ -47,7 +49,7 @@ public function relation($relation) * @param mixed $indexedShape * @return static */ - public function indexedShape($indexedShape) + public function indexedShape($indexedShape): static { return $this->addProperty('indexed_shape', $indexedShape); } diff --git a/src/DSL/Queries/Span.php b/src/DSL/Queries/Span.php index 22bffbc..c083640 100644 --- a/src/DSL/Queries/Span.php +++ b/src/DSL/Queries/Span.php @@ -1,5 +1,7 @@ addProperty('little', Query::create($little)); } @@ -29,7 +31,7 @@ public function little($little) * @param mixed $big * @return static */ - public function big($big) + public function big($big): static { return $this->addProperty('big', Query::create($big)); } diff --git a/src/DSL/Queries/Span/SpanFieldMasking.php b/src/DSL/Queries/Span/SpanFieldMasking.php index ea62edf..5be991e 100644 --- a/src/DSL/Queries/Span/SpanFieldMasking.php +++ b/src/DSL/Queries/Span/SpanFieldMasking.php @@ -1,5 +1,7 @@ addProperty('query', Query::create($query)); } - - /** - * The masked field to use for the span query. - * - * @param string $field - * @return static - */ - public function field($field) - { - return $this->addProperty('field', $field); - } } diff --git a/src/DSL/Queries/Span/SpanFirst.php b/src/DSL/Queries/Span/SpanFirst.php index 2881f43..fc21193 100644 --- a/src/DSL/Queries/Span/SpanFirst.php +++ b/src/DSL/Queries/Span/SpanFirst.php @@ -1,5 +1,7 @@ addProperty('match', Query::create($match)); } @@ -29,7 +31,7 @@ public function match($match) * @param int $end * @return static */ - public function end($end) + public function end(int $end): static { return $this->addProperty('end', $end); } diff --git a/src/DSL/Queries/Span/SpanMulti.php b/src/DSL/Queries/Span/SpanMulti.php index ecdad4a..ebe0ffe 100644 --- a/src/DSL/Queries/Span/SpanMulti.php +++ b/src/DSL/Queries/Span/SpanMulti.php @@ -1,5 +1,7 @@ addProperty('match', Query::create($match)); } diff --git a/src/DSL/Queries/Span/SpanNear.php b/src/DSL/Queries/Span/SpanNear.php index eaa8f20..c7b49a5 100644 --- a/src/DSL/Queries/Span/SpanNear.php +++ b/src/DSL/Queries/Span/SpanNear.php @@ -1,5 +1,7 @@ addClause('clauses', $clauses); } @@ -32,7 +34,7 @@ public function clauses($clauses) * @param int $slop * @return static */ - public function slop($slop) + public function slop(int $slop): static { return $this->addProperty('slop', $slop); } @@ -43,7 +45,7 @@ public function slop($slop) * @param bool $inOrder * @return static */ - public function inOrder($inOrder) + public function inOrder(bool $inOrder): static { return $this->addProperty('in_order', $inOrder); } diff --git a/src/DSL/Queries/Span/SpanNot.php b/src/DSL/Queries/Span/SpanNot.php index 31b77c3..785f810 100644 --- a/src/DSL/Queries/Span/SpanNot.php +++ b/src/DSL/Queries/Span/SpanNot.php @@ -1,5 +1,7 @@ addProperty('include', Query::create($include)); } @@ -29,7 +31,7 @@ public function include($include) * @param mixed $exclude * @return static */ - public function exclude($exclude) + public function exclude($exclude): static { return $this->addProperty('exclude', Query::create($exclude)); } @@ -40,7 +42,7 @@ public function exclude($exclude) * @param int $pre * @return static */ - public function pre($pre) + public function pre(int $pre): static { return $this->addProperty('pre', $pre); } @@ -51,7 +53,7 @@ public function pre($pre) * @param int $post * @return static */ - public function post($post) + public function post(int $post): static { return $this->addProperty('post', $post); } @@ -62,7 +64,7 @@ public function post($post) * @param int $dist * @return static */ - public function dist($dist) + public function dist(int $dist): static { return $this->addProperty('dist', $dist); } diff --git a/src/DSL/Queries/Span/SpanOr.php b/src/DSL/Queries/Span/SpanOr.php index 3999878..2da6c7d 100644 --- a/src/DSL/Queries/Span/SpanOr.php +++ b/src/DSL/Queries/Span/SpanOr.php @@ -1,5 +1,7 @@ addClause('clauses', $clauses); } diff --git a/src/DSL/Queries/Span/SpanTerm.php b/src/DSL/Queries/Span/SpanTerm.php index ad34f62..972f096 100644 --- a/src/DSL/Queries/Span/SpanTerm.php +++ b/src/DSL/Queries/Span/SpanTerm.php @@ -1,5 +1,7 @@ addProperty('term', $term); } @@ -28,10 +30,10 @@ public function term($term) /** * The value of the term to match (alias for the field value). * - * @param string $value + * @param string|int|float|bool $value * @return static */ - public function value($value) + public function value(string|int|float|bool $value): static { return $this->addProperty('value', $value); } diff --git a/src/DSL/Queries/Span/SpanWithin.php b/src/DSL/Queries/Span/SpanWithin.php index d60ca32..08edb3e 100644 --- a/src/DSL/Queries/Span/SpanWithin.php +++ b/src/DSL/Queries/Span/SpanWithin.php @@ -1,5 +1,7 @@ addProperty('little', Query::create($little)); } @@ -29,7 +31,7 @@ public function little($little) * @param mixed $big * @return static */ - public function big($big) + public function big($big): static { return $this->addProperty('big', Query::create($big)); } diff --git a/src/DSL/Queries/Specialized.php b/src/DSL/Queries/Specialized.php index 445d49c..1667af0 100644 --- a/src/DSL/Queries/Specialized.php +++ b/src/DSL/Queries/Specialized.php @@ -1,5 +1,7 @@ addProperty('origin', $origin); } @@ -25,10 +27,10 @@ public function origin($origin) /** * Distance from the origin at which relevance scores receive half of the boost value. * - * @param mixed $pivot + * @param string $pivot * @return static */ - public function pivot($pivot) + public function pivot(string $pivot): static { return $this->addProperty('pivot', $pivot); } diff --git a/src/DSL/Queries/Specialized/MoreLikeThis.php b/src/DSL/Queries/Specialized/MoreLikeThis.php index d7ab65b..4c7c6b1 100644 --- a/src/DSL/Queries/Specialized/MoreLikeThis.php +++ b/src/DSL/Queries/Specialized/MoreLikeThis.php @@ -1,5 +1,7 @@ $array * @return static */ - public function fields($array) + public function fields(array $array): static { return $this->addProperty('fields', $array); } @@ -28,7 +30,7 @@ public function fields($array) * @param mixed $string * @return static */ - public function like($string) + public function like($string): static { return $this->addProperty('like', $string); } @@ -39,7 +41,7 @@ public function like($string) * @param int $int * @return static */ - public function minTermFreq($int) + public function minTermFreq(int $int): static { return $this->addProperty('min_term_freq', $int); } @@ -50,7 +52,7 @@ public function minTermFreq($int) * @param int $int * @return static */ - public function maxQueryTerms($int) + public function maxQueryTerms(int $int): static { return $this->addProperty('max_query_terms', $int); } diff --git a/src/DSL/Queries/Specialized/Percolate.php b/src/DSL/Queries/Specialized/Percolate.php index 74d882e..61bf1a3 100644 --- a/src/DSL/Queries/Specialized/Percolate.php +++ b/src/DSL/Queries/Specialized/Percolate.php @@ -1,5 +1,7 @@ addProperty('document', $document); } diff --git a/src/DSL/Queries/Specialized/Pinned.php b/src/DSL/Queries/Specialized/Pinned.php index 0ed91d5..361bebc 100644 --- a/src/DSL/Queries/Specialized/Pinned.php +++ b/src/DSL/Queries/Specialized/Pinned.php @@ -1,5 +1,7 @@ $ids * @return static */ - public function ids($ids) + public function ids(array $ids): static { return $this->addProperty('ids', $ids); } @@ -29,7 +31,7 @@ public function ids($ids) * @param mixed $organic * @return static */ - public function organic($organic) + public function organic($organic): static { return $this->addProperty('organic', Query::create($organic)); } @@ -40,7 +42,7 @@ public function organic($organic) * @param mixed $doc * @return static */ - public function doc($doc) + public function doc($doc): static { return $this->addProperty('doc', $doc); } diff --git a/src/DSL/Queries/Specialized/RankFeature.php b/src/DSL/Queries/Specialized/RankFeature.php index 0cd8746..011b217 100644 --- a/src/DSL/Queries/Specialized/RankFeature.php +++ b/src/DSL/Queries/Specialized/RankFeature.php @@ -1,5 +1,7 @@ addProperty('saturation', $saturation); } @@ -28,7 +30,7 @@ public function saturation($saturation) * @param mixed $log * @return static */ - public function log($log) + public function log($log): static { return $this->addProperty('log', $log); } @@ -39,7 +41,7 @@ public function log($log) * @param mixed $sigmoid * @return static */ - public function sigmoid($sigmoid) + public function sigmoid($sigmoid): static { return $this->addProperty('sigmoid', $sigmoid); } @@ -50,7 +52,7 @@ public function sigmoid($sigmoid) * @param mixed $linear * @return static */ - public function linear($linear) + public function linear($linear): static { return $this->addProperty('linear', $linear); } diff --git a/src/DSL/Queries/Specialized/Script.php b/src/DSL/Queries/Specialized/Script.php index a51cd1e..e670d0b 100644 --- a/src/DSL/Queries/Specialized/Script.php +++ b/src/DSL/Queries/Specialized/Script.php @@ -1,5 +1,7 @@ addProperty('script', \ElasticKit\DSL\Queries\Script::create($script)); } diff --git a/src/DSL/Queries/Specialized/ScriptScore.php b/src/DSL/Queries/Specialized/ScriptScore.php index d58091b..aa9a94e 100644 --- a/src/DSL/Queries/Specialized/ScriptScore.php +++ b/src/DSL/Queries/Specialized/ScriptScore.php @@ -1,5 +1,7 @@ addProperty('query', Query::create($query)); } @@ -29,7 +31,7 @@ public function query($query) * @param mixed $script * @return static */ - public function script($script) + public function script($script): static { return $this->addProperty('script', \ElasticKit\DSL\Queries\Script::create($script)); } @@ -40,7 +42,7 @@ public function script($script) * @param float $minScore * @return static */ - public function minScore($minScore) + public function minScore(float $minScore): static { return $this->addProperty('min_score', Query::create($minScore)); } diff --git a/src/DSL/Queries/Specialized/Wrapper.php b/src/DSL/Queries/Specialized/Wrapper.php index 53f8b4d..84335df 100644 --- a/src/DSL/Queries/Specialized/Wrapper.php +++ b/src/DSL/Queries/Specialized/Wrapper.php @@ -1,5 +1,7 @@ query($field); @@ -35,7 +37,7 @@ public static function create($field = null, $value = null) * @param string $query * @return static */ - public function query($query) + public function query(string $query): static { return $this->addProperty('query', $query); } diff --git a/src/DSL/Queries/TermLevel.php b/src/DSL/Queries/TermLevel.php index 7e06f7a..946130d 100644 --- a/src/DSL/Queries/TermLevel.php +++ b/src/DSL/Queries/TermLevel.php @@ -1,5 +1,7 @@ . @@ -16,7 +18,7 @@ class Fuzzy extends Node * @param string $value * @return static */ - public function value($value) + public function value(string $value): static { return $this->addProperty('value', $value); } @@ -24,10 +26,10 @@ public function value($value) /** * Maximum edit distance allowed for matching. See Fuzziness for valid values and more information. * - * @param string $fuzziness + * @param int|string $fuzziness * @return static */ - public function fuzziness($fuzziness) + public function fuzziness(int|string $fuzziness): static { return $this->addProperty('fuzziness', $fuzziness); } @@ -38,7 +40,7 @@ public function fuzziness($fuzziness) * @param int $maxExpansions * @return static */ - public function maxExpansions($maxExpansions) + public function maxExpansions(int $maxExpansions): static { return $this->addProperty('max_expansions', $maxExpansions); } @@ -49,7 +51,7 @@ public function maxExpansions($maxExpansions) * @param int $prefixLength * @return static */ - public function prefixLength($prefixLength) + public function prefixLength(int $prefixLength): static { return $this->addProperty('prefix_length', $prefixLength); } @@ -60,7 +62,7 @@ public function prefixLength($prefixLength) * @param bool $transpositions * @return static */ - public function transpositions($transpositions) + public function transpositions(bool $transpositions): static { return $this->addProperty('transpositions', $transpositions); } @@ -71,7 +73,7 @@ public function transpositions($transpositions) * @param string $rewrite * @return static */ - public function rewrite($rewrite) + public function rewrite(string $rewrite): static { return $this->addProperty('rewrite', $rewrite); } diff --git a/src/DSL/Queries/TermLevel/IDs.php b/src/DSL/Queries/TermLevel/IDs.php index 2f36123..73efe22 100644 --- a/src/DSL/Queries/TermLevel/IDs.php +++ b/src/DSL/Queries/TermLevel/IDs.php @@ -1,5 +1,7 @@ $values * @return static */ - public function values($values) + public function values(array $values): static { return $this->addProperty('values', $values); } diff --git a/src/DSL/Queries/TermLevel/Prefix.php b/src/DSL/Queries/TermLevel/Prefix.php index 609dc7b..6f6305a 100644 --- a/src/DSL/Queries/TermLevel/Prefix.php +++ b/src/DSL/Queries/TermLevel/Prefix.php @@ -1,14 +1,16 @@ . @@ -16,7 +18,7 @@ class Prefix extends Node * @param string $value * @return static */ - public function value($value) + public function value(string $value): static { return $this->addProperty('value', $value); } @@ -27,7 +29,7 @@ public function value($value) * @param string $rewrite * @return static */ - public function rewrite($rewrite) + public function rewrite(string $rewrite): static { return $this->addProperty('rewrite', $rewrite); } @@ -38,7 +40,7 @@ public function rewrite($rewrite) * @param bool $caseInsensitive * @return static */ - public function caseInsensitive($caseInsensitive) + public function caseInsensitive(bool $caseInsensitive): static { return $this->addProperty('case_insensitive', $caseInsensitive); } diff --git a/src/DSL/Queries/TermLevel/Range.php b/src/DSL/Queries/TermLevel/Range.php index 71d191b..9686872 100644 --- a/src/DSL/Queries/TermLevel/Range.php +++ b/src/DSL/Queries/TermLevel/Range.php @@ -1,5 +1,7 @@ addProperty('gte', $gte); } /** - * (Optional) Greater than. + * Greater than. * - * @param mixed $gt + * @param string|int|float|bool $gt * @return static */ - public function gt($gt) + public function gt(string|int|float|bool $gt): static { return $this->addProperty('gt', $gt); } /** - * (Optional) Less than or equal to. + * Less than or equal to. * - * @param mixed $lte + * @param string|int|float|bool $lte * @return static */ - public function lte($lte) + public function lte(string|int|float|bool $lte): static { return $this->addProperty('lte', $lte); } /** - * (Optional) Less than. + * Less than. * - * @param mixed $lt + * @param string|int|float|bool $lt * @return static */ - public function lt($lt) + public function lt(string|int|float|bool $lt): static { return $this->addProperty('lt', $lt); } @@ -69,7 +71,7 @@ public function lt($lt) * @param string $format * @return static */ - public function format($format) + public function format(string $format): static { return $this->addProperty('format', $format); } @@ -87,7 +89,7 @@ public function format($format) * @param string $relation * @return static */ - public function relation($relation) + public function relation(string $relation): static { return $this->addProperty('relation', $relation); } @@ -98,7 +100,7 @@ public function relation($relation) * @param string $timeZone * @return static */ - public function timeZone($timeZone) + public function timeZone(string $timeZone): static { return $this->addProperty('time_zone', $timeZone); } diff --git a/src/DSL/Queries/TermLevel/Regexp.php b/src/DSL/Queries/TermLevel/Regexp.php index 80ed83c..f8db581 100644 --- a/src/DSL/Queries/TermLevel/Regexp.php +++ b/src/DSL/Queries/TermLevel/Regexp.php @@ -1,14 +1,16 @@ . For a list of supported operators, see Regular expression syntax. @@ -20,7 +22,7 @@ class Regexp extends Node * @param string $value * @return static */ - public function value($value) + public function value(string $value): static { return $this->addProperty('value', $value); } @@ -31,7 +33,7 @@ public function value($value) * @param string $flags * @return static */ - public function flags($flags) + public function flags(string $flags): static { return $this->addProperty('flags', $flags); } @@ -42,7 +44,7 @@ public function flags($flags) * @param bool $caseInsensitive * @return static */ - public function caseInsensitive($caseInsensitive) + public function caseInsensitive(bool $caseInsensitive): static { return $this->addProperty('case_insensitive', $caseInsensitive); } @@ -57,7 +59,7 @@ public function caseInsensitive($caseInsensitive) * @param int $maxDeterminizedStates * @return static */ - public function maxDeterminizedStates($maxDeterminizedStates) + public function maxDeterminizedStates(int $maxDeterminizedStates): static { return $this->addProperty('max_determinized_states', $maxDeterminizedStates); } @@ -68,7 +70,7 @@ public function maxDeterminizedStates($maxDeterminizedStates) * @param string $rewrite * @return static */ - public function rewrite($rewrite) + public function rewrite(string $rewrite): static { return $this->addProperty('rewrite', $rewrite); } diff --git a/src/DSL/Queries/TermLevel/Term.php b/src/DSL/Queries/TermLevel/Term.php index 699d9cf..1ab8da5 100644 --- a/src/DSL/Queries/TermLevel/Term.php +++ b/src/DSL/Queries/TermLevel/Term.php @@ -1,5 +1,7 @@ . To return a document, the term must exactly match the field value, including whitespace and capitalization. * - * @param string $value + * @param string|int|float|bool $value * @return static */ - public function value($value) + public function value(string|int|float|bool $value): static { return $this->addProperty('value', $value); } @@ -40,7 +42,7 @@ public function value($value) * @return static * @version 7.10.0 */ - public function caseInsensitive($caseInsensitive) + public function caseInsensitive(bool $caseInsensitive): static { return $this->addProperty('case_insensitive', $caseInsensitive); } diff --git a/src/DSL/Queries/TermLevel/Terms.php b/src/DSL/Queries/TermLevel/Terms.php index e980715..ab8cb59 100644 --- a/src/DSL/Queries/TermLevel/Terms.php +++ b/src/DSL/Queries/TermLevel/Terms.php @@ -1,14 +1,16 @@ $values + * @param array $values * @return static */ - public function values($field, $values) + public function values(string $field, array $values): static { return $this->addProperty($field, $values); } diff --git a/src/DSL/Queries/TermLevel/TermsSet.php b/src/DSL/Queries/TermLevel/TermsSet.php index e3a5669..470f82f 100644 --- a/src/DSL/Queries/TermLevel/TermsSet.php +++ b/src/DSL/Queries/TermLevel/TermsSet.php @@ -1,5 +1,7 @@ . To return a document, a required number of terms must exactly match the field values, including whitespace and capitalization. * * The required number of matching terms is defined in the minimum_should_match, minimum_should_match_field or minimum_should_match_script parameters. Exactly one of these parameters must be provided. * - * @param array $terms + * @param array $terms * @return static */ - public function terms($terms) + public function terms(array $terms): static { return $this->addProperty('terms', $terms); } /** - * (Optional) Specification for the number of matching terms required to return a document. + * Specification for the number of matching terms required to return a document. * * For valid values, see minimum_should_match parameter. * - * @param mixed $minimumShouldMatch + * @param int|string $minimumShouldMatch * @return static */ - public function minimumShouldMatch($minimumShouldMatch) + public function minimumShouldMatch(int|string $minimumShouldMatch): static { return $this->addProperty('minimum_should_match', $minimumShouldMatch); } @@ -44,7 +46,7 @@ public function minimumShouldMatch($minimumShouldMatch) * @param string $field * @return static */ - public function minimumShouldMatchField($field) + public function minimumShouldMatchField(string $field): static { return $this->addProperty('minimum_should_match_field', $field); } @@ -59,7 +61,7 @@ public function minimumShouldMatchField($field) * @param mixed $minimumShouldMatchScript * @return static */ - public function minimumShouldMatchScript($minimumShouldMatchScript) + public function minimumShouldMatchScript($minimumShouldMatchScript): static { return $this->addProperty('minimum_should_match_script', Script::create($minimumShouldMatchScript)); } diff --git a/src/DSL/Queries/TermLevel/Wildcard.php b/src/DSL/Queries/TermLevel/Wildcard.php index aaaff69..1efa192 100644 --- a/src/DSL/Queries/TermLevel/Wildcard.php +++ b/src/DSL/Queries/TermLevel/Wildcard.php @@ -1,14 +1,16 @@ addProperty('case_insensitive', $caseInsensitive); } @@ -28,7 +30,7 @@ public function caseInsensitive($caseInsensitive) * @param string $rewrite * @return static */ - public function rewrite($rewrite) + public function rewrite(string $rewrite): static { return $this->addProperty('rewrite', $rewrite); } @@ -45,7 +47,7 @@ public function rewrite($rewrite) * @param string $value * @return static */ - public function value($value) + public function value(string $value): static { return $this->addProperty('value', $value); } @@ -56,7 +58,7 @@ public function value($value) * @param string $wildcard * @return static */ - public function wildcard($wildcard) + public function wildcard(string $wildcard): static { return $this->addProperty('wildcard', $wildcard); } diff --git a/src/DSL/Query.php b/src/DSL/Query.php index 93d41db..57cff33 100644 --- a/src/DSL/Query.php +++ b/src/DSL/Query.php @@ -1,5 +1,7 @@ _multi = $multi; - return $this; - } - /** * Whether the query supports multiple clauses. * * @return bool */ - protected function isMulti() + protected function isMulti(): bool { return $this->_multi; } @@ -106,7 +96,7 @@ public function __construct($field = null, $value = null) } elseif (is_array($field)) { $this->fromArray($field); } elseif ($field !== null) { - $this->_properties = $field; + $this->_raw = $field; } } @@ -132,7 +122,7 @@ protected function fromArray(array $field): void * * @return array */ - public function getQueries() + public function getQueries(): array { return $this->_queries; } @@ -143,7 +133,7 @@ public function getQueries() * @param mixed $query * @return $this */ - public function addQuery($query) + public function addQuery($query): static { $this->_queries[] = $query; return $this; @@ -157,7 +147,7 @@ public function addQuery($query) * @param mixed $default * @return $this */ - public function when($condition, $query, $default = null) + public function when($condition, $query, $default = null): static { $truthy = is_callable($condition) ? $condition() : $condition; @@ -183,7 +173,7 @@ public function when($condition, $query, $default = null) * @return $this * @throws \BadMethodCallException if called with a string alias and no definition */ - public function aggs($alias, $aggs = null) + public function aggs($alias, $aggs = null): static { if ($aggs === null && !is_string($alias)) { $aggs = $alias; @@ -234,9 +224,9 @@ public function aggs($alias, $aggs = null) * * @return array */ - public function toArray() + public function toArray(): array { - $dsl = is_array($this->_properties) ? $this->resolveProperties($this->_properties) : []; + $dsl = $this->_properties !== null ? $this->resolveProperties($this->_properties) : []; $query = $this->buildQuery(); if (!empty($query)) { @@ -303,7 +293,7 @@ private function buildQuery() * @param array $dsl * @return void */ - private function buildAggs(array &$dsl) + private function buildAggs(array &$dsl): void { if (empty($this->_aggregations)) { return; @@ -320,7 +310,7 @@ private function buildAggs(array &$dsl) * @param array $dsl * @return void */ - private function buildParams(array &$dsl) + private function buildParams(array &$dsl): void { foreach ($this->_params as $key => $value) { if ($value instanceof Query) { diff --git a/src/DSL/Support/ClausesSupport.php b/src/DSL/Support/ClausesSupport.php index a80534e..8a45877 100644 --- a/src/DSL/Support/ClausesSupport.php +++ b/src/DSL/Support/ClausesSupport.php @@ -1,5 +1,7 @@ Date: Tue, 16 Jun 2026 00:04:48 +0800 Subject: [PATCH 16/24] =?UTF-8?q?refactor(dsl)!:=20=E7=BB=9F=E4=B8=80=20Bu?= =?UTF-8?q?cket=20=E8=81=9A=E5=90=88=E5=91=BD=E5=90=8D=E5=B9=B6=E7=AE=80?= =?UTF-8?q?=E5=8C=96=20Node=20=E5=8F=96=E5=80=BC=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FilterAgg/GlobalAgg/ParentAgg 重命名为 Filter/Global_/Parent_(去 Agg 后缀对齐 ES 关键字,global/parent 为 PHP 保留字加 _) - setFilter()/globalAggregation() 改名 filter()/global() - Node 移除 $_raw 整体透传机制,$_rawValue 重命名为 $_value 并加联合类型;scalar 构造分支不再限定 _fieldKeyed - Query 同步移除 $_raw 分支;新增 rector.php 现代化规则配置 Co-Authored-By: Claude --- src/DSL/Aggs/Bucket.php | 16 +++---- .../Aggs/Bucket/{FilterAgg.php => Filter.php} | 11 +++-- .../Bucket/{GlobalAgg.php => Global_.php} | 2 +- .../Bucket/{ParentAgg.php => Parent_.php} | 2 +- src/DSL/Node.php | 45 ++++++------------- src/DSL/Query.php | 2 - tests/AggsTest.php | 2 +- 7 files changed, 32 insertions(+), 48 deletions(-) rename src/DSL/Aggs/Bucket/{FilterAgg.php => Filter.php} (71%) rename src/DSL/Aggs/Bucket/{GlobalAgg.php => Global_.php} (93%) rename src/DSL/Aggs/Bucket/{ParentAgg.php => Parent_.php} (94%) diff --git a/src/DSL/Aggs/Bucket.php b/src/DSL/Aggs/Bucket.php index b9336c1..4d11bcb 100644 --- a/src/DSL/Aggs/Bucket.php +++ b/src/DSL/Aggs/Bucket.php @@ -11,9 +11,9 @@ use ElasticKit\DSL\Aggs\Bucket\DateHistogram; use ElasticKit\DSL\Aggs\Bucket\DateRange; use ElasticKit\DSL\Aggs\Bucket\DiversifiedSampler; -use ElasticKit\DSL\Aggs\Bucket\FilterAgg; +use ElasticKit\DSL\Aggs\Bucket\Filter; use ElasticKit\DSL\Aggs\Bucket\Filters; -use ElasticKit\DSL\Aggs\Bucket\GlobalAgg; +use ElasticKit\DSL\Aggs\Bucket\Global_; use ElasticKit\DSL\Aggs\Bucket\FrequentItemSets; use ElasticKit\DSL\Aggs\Bucket\GeoDistance; use ElasticKit\DSL\Aggs\Bucket\GeoHashGrid; @@ -25,7 +25,7 @@ use ElasticKit\DSL\Aggs\Bucket\Missing; use ElasticKit\DSL\Aggs\Bucket\MultiTerms; use ElasticKit\DSL\Aggs\Bucket\Nested; -use ElasticKit\DSL\Aggs\Bucket\ParentAgg; +use ElasticKit\DSL\Aggs\Bucket\Parent_; use ElasticKit\DSL\Aggs\Bucket\RandomSampler; use ElasticKit\DSL\Aggs\Bucket\Range; use ElasticKit\DSL\Aggs\Bucket\RareTerms; @@ -57,8 +57,8 @@ public function terms($params) */ public function filter($filter) { - $instance = new FilterAgg(); - $instance->setFilter($filter); + $instance = new Filter(); + $instance->filter($filter); return $this->node($instance); } @@ -210,9 +210,9 @@ public function geotileGrid($params) * * @return static */ - public function globalAggregation() + public function global() { - return $this->node(new GlobalAgg()); + return $this->node(new Global_()); } /** @@ -289,7 +289,7 @@ public function nested($params) */ public function parent($params) { - return $this->node(ParentAgg::create($params)); + return $this->node(Parent_::create($params)); } /** diff --git a/src/DSL/Aggs/Bucket/FilterAgg.php b/src/DSL/Aggs/Bucket/Filter.php similarity index 71% rename from src/DSL/Aggs/Bucket/FilterAgg.php rename to src/DSL/Aggs/Bucket/Filter.php index 630b2d8..5eb9abe 100644 --- a/src/DSL/Aggs/Bucket/FilterAgg.php +++ b/src/DSL/Aggs/Bucket/Filter.php @@ -10,19 +10,22 @@ /** * A single bucket aggregation that limits documents matching a query. */ -class FilterAgg extends Node +class Filter extends Node { protected string $_key = 'filter'; + /** @var mixed */ + protected $_filter; + /** * The filter query to apply. * * @param mixed $filter * @return static */ - public function setFilter($filter): static + public function filter($filter): static { - $this->_raw = $filter; + $this->_filter = $filter; return $this; } @@ -33,6 +36,6 @@ public function setFilter($filter): static */ public function toArray() { - return Query::create($this->_raw)->toArray()['query']; + return Query::create($this->_filter)->toArray()['query']; } } diff --git a/src/DSL/Aggs/Bucket/GlobalAgg.php b/src/DSL/Aggs/Bucket/Global_.php similarity index 93% rename from src/DSL/Aggs/Bucket/GlobalAgg.php rename to src/DSL/Aggs/Bucket/Global_.php index 7d581d2..8efd193 100644 --- a/src/DSL/Aggs/Bucket/GlobalAgg.php +++ b/src/DSL/Aggs/Bucket/Global_.php @@ -10,7 +10,7 @@ /** * A single bucket aggregation that defines all documents within the search context. */ -class GlobalAgg extends Node +class Global_ extends Node { protected string $_key = 'global'; diff --git a/src/DSL/Aggs/Bucket/ParentAgg.php b/src/DSL/Aggs/Bucket/Parent_.php similarity index 94% rename from src/DSL/Aggs/Bucket/ParentAgg.php rename to src/DSL/Aggs/Bucket/Parent_.php index c3a0cfd..9de4c8d 100644 --- a/src/DSL/Aggs/Bucket/ParentAgg.php +++ b/src/DSL/Aggs/Bucket/Parent_.php @@ -9,7 +9,7 @@ /** * A bucket aggregation that aggregates on parent documents from a join field. */ -class ParentAgg extends Node +class Parent_ extends Node { protected string $_key = 'parent'; diff --git a/src/DSL/Node.php b/src/DSL/Node.php index 0df9aa1..5aa823f 100644 --- a/src/DSL/Node.php +++ b/src/DSL/Node.php @@ -16,33 +16,23 @@ abstract class Node /** * Properties owned by a node. Either an array of attributes, or null when * the node carries no properties (empty construction / empty closure, - * which serializes to null). Whole-value pass-through uses $_raw; - * field-value shorthand uses $_rawValue. + * which serializes to null). Field-value shorthand uses $_value. * * @var array|null */ protected ?array $_properties = null; /** - * Raw whole-value pass-through. When set, toArray() emits this value - * verbatim — for nodes constructed with a single non-array, non-closure - * argument (a wrapped Node, a FilterAgg filter query, etc.). - * - * @var mixed - */ - protected $_raw; - - /** - * Raw scalar value stored separately from properties. + * Scalar value stored separately from properties. * When set, toArray() outputs shorthand (field => value) if no extra * properties exist, or promotes it under $_valueKey when properties are present. * * @var scalar|null */ - protected $_rawValue; + protected int|float|string|bool|null $_value = null; /** - * The key used when promoting $_rawValue into the properties array. + * The key used when promoting $_value into the properties array. * Override in subclasses that use a different key (e.g. 'query' for match queries). * * @var string @@ -61,7 +51,7 @@ abstract class Node * * @var string */ - protected $_field; + protected string $_field; /** * Whether the node supports multiple clauses. @@ -86,9 +76,10 @@ abstract class Node * - new Term('status', fn($t) => ...) — K,V closure * - new Term([...]) — array properties * - new Term(fn($t) => ...) — closure + * - new Script('_score * ...') — bare scalar (whole node value) * - new Term() — empty * - * @param mixed $field Properties, field name, closure, or null + * @param mixed $field Properties, field name, closure, scalar value, or null * @param mixed $value Value/properties/closure when using two-arg mode */ public function __construct($field = null, $value = null) @@ -99,12 +90,10 @@ public function __construct($field = null, $value = null) $this->fromClosure($field); } elseif ($this->_fieldKeyed && is_array($field)) { $this->fromArrayField($field); - } elseif ($this->_fieldKeyed && is_scalar($field)) { + } elseif (is_scalar($field)) { $this->fromScalar($field); } elseif (is_array($field)) { $this->_properties = $field; - } elseif ($field !== null) { - $this->_raw = $field; } } @@ -119,12 +108,10 @@ protected function fromKeyValue($field, $value): void if ($value instanceof Closure) { $value($this); } elseif (is_scalar($value)) { - $this->_rawValue = $value; + $this->_value = $value; $this->_properties = []; } elseif (is_array($value)) { $this->_properties = $value; - } else { - $this->_raw = $value; } if ($this->_fieldKeyed) { $this->field($field); @@ -151,12 +138,10 @@ protected function fromArrayField(array $field): void foreach ($field as $key => $val) { $this->field($key); if (is_scalar($val)) { - $this->_rawValue = $val; + $this->_value = $val; $this->_properties = []; } elseif (is_array($val)) { $this->_properties = $val; - } else { - $this->_raw = $val; } break; } @@ -169,7 +154,7 @@ protected function fromArrayField(array $field): void */ protected function fromScalar($value): void { - $this->_rawValue = $value; + $this->_value = $value; $this->_properties = []; } @@ -301,16 +286,14 @@ protected function resolveProperties(array $properties): array */ public function toArray() { - if ($this->_raw !== null) { - $properties = $this->_raw; - } elseif ($this->_rawValue !== null) { + if ($this->_value !== null) { $props = $this->_properties ?? []; if ($props === []) { - $properties = $this->_rawValue; + $properties = $this->_value; } else { $properties = $this->resolveProperties($props); if (!isset($properties[$this->_valueKey])) { - $properties = array_merge([$this->_valueKey => $this->_rawValue], $properties); + $properties = array_merge([$this->_valueKey => $this->_value], $properties); } } } else { diff --git a/src/DSL/Query.php b/src/DSL/Query.php index 57cff33..8ce35cd 100644 --- a/src/DSL/Query.php +++ b/src/DSL/Query.php @@ -95,8 +95,6 @@ public function __construct($field = null, $value = null) $this->_queries[] = $field; } elseif (is_array($field)) { $this->fromArray($field); - } elseif ($field !== null) { - $this->_raw = $field; } } diff --git a/tests/AggsTest.php b/tests/AggsTest.php index 2b39e8d..6de118f 100644 --- a/tests/AggsTest.php +++ b/tests/AggsTest.php @@ -745,7 +745,7 @@ public function testGlobalAggregation() $query = new Query(); $query->matchAll(); $query->aggs('all', function ($a) { - $a->globalAggregation(); + $a->global(); }); $this->assertQuery($expectedJson, $query); } From ab4d70ae13e7b79515b51eada1bb00e4c4a136f6 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 19 Jun 2026 01:31:59 +0800 Subject: [PATCH 17/24] =?UTF-8?q?refactor(dsl):=20=E7=BB=9F=E4=B8=80=20lea?= =?UTF-8?q?f=20setter=20=E5=8F=82=E6=95=B0=E5=90=8D=E4=B8=BA=20$value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 所有非 trait class 的单参数 public 方法参数名统一为 $value, 避免 named arguments BC 风险。多参数方法和 trait 通用方法不受影响。 - 批量重命名约 350 个方法参数(含 docblock 和方法体同步) - 删除 Knn::boost() 重复方法 - 修复 Suggest docblock 类型写法不一致(string|null → ?string) - 修复 PHP_CS_FIXER_IGNORE_ENV 废弃警告 --- .php-cs-fixer.php | 3 +- composer.json | 4 +- src/DSL/Agg.php | 10 +- src/DSL/Aggs/Bucket.php | 62 ++++---- src/DSL/Aggs/Bucket/AdjacencyMatrix.php | 6 +- src/DSL/Aggs/Bucket/AutoDateHistogram.php | 30 ++-- src/DSL/Aggs/Bucket/CategorizeText.php | 54 +++---- src/DSL/Aggs/Bucket/Composite.php | 24 +-- src/DSL/Aggs/Bucket/DateHistogram.php | 72 ++++----- src/DSL/Aggs/Bucket/DateRange.php | 30 ++-- src/DSL/Aggs/Bucket/DiversifiedSampler.php | 18 +-- src/DSL/Aggs/Bucket/Filter.php | 6 +- src/DSL/Aggs/Bucket/Filters.php | 18 +-- src/DSL/Aggs/Bucket/FrequentItemSets.php | 24 +-- src/DSL/Aggs/Bucket/GeoDistance.php | 30 ++-- src/DSL/Aggs/Bucket/GeoHashGrid.php | 18 +-- src/DSL/Aggs/Bucket/GeohexGrid.php | 18 +-- src/DSL/Aggs/Bucket/GeotileGrid.php | 18 +-- src/DSL/Aggs/Bucket/Histogram.php | 60 ++++---- src/DSL/Aggs/Bucket/IpPrefix.php | 12 +- src/DSL/Aggs/Bucket/IpRange.php | 18 +-- src/DSL/Aggs/Bucket/Missing.php | 6 +- src/DSL/Aggs/Bucket/MultiTerms.php | 42 +++--- src/DSL/Aggs/Bucket/Nested.php | 12 +- src/DSL/Aggs/Bucket/Parent_.php | 6 +- src/DSL/Aggs/Bucket/RandomSampler.php | 12 +- src/DSL/Aggs/Bucket/Range.php | 24 +-- src/DSL/Aggs/Bucket/RareTerms.php | 36 ++--- src/DSL/Aggs/Bucket/ReverseNested.php | 6 +- src/DSL/Aggs/Bucket/SignificantTerms.php | 48 +++--- src/DSL/Aggs/Bucket/SignificantText.php | 48 +++--- src/DSL/Aggs/Bucket/Terms.php | 66 ++++----- src/DSL/Aggs/Bucket/TimeSeries.php | 18 +-- .../Aggs/Bucket/VariableWidthHistogram.php | 12 +- src/DSL/Aggs/Metric.php | 16 +- src/DSL/Aggs/Metric/Avg.php | 12 +- src/DSL/Aggs/Metric/Cardinality.php | 18 +-- src/DSL/Aggs/Metric/ExtendedStats.php | 18 +-- src/DSL/Aggs/Metric/Max.php | 12 +- src/DSL/Aggs/Metric/Min.php | 12 +- src/DSL/Aggs/Metric/Stats.php | 12 +- src/DSL/Aggs/Metric/Sum.php | 12 +- src/DSL/Aggs/Metric/ValueCount.php | 6 +- src/DSL/Aggs/Pipeline.php | 16 +- src/DSL/Aggs/Pipeline/AvgBucket.php | 24 +-- src/DSL/Aggs/Pipeline/BucketScript.php | 24 +-- src/DSL/Aggs/Pipeline/CumulativeSum.php | 12 +- src/DSL/Aggs/Pipeline/Derivative.php | 24 +-- src/DSL/Aggs/Pipeline/MaxBucket.php | 24 +-- src/DSL/Aggs/Pipeline/MinBucket.php | 24 +-- src/DSL/Aggs/Pipeline/StatsBucket.php | 24 +-- src/DSL/Aggs/Pipeline/SumBucket.php | 24 +-- src/DSL/Node.php | 16 +- src/DSL/Param.php | 58 ++++---- src/DSL/Params/Collapse.php | 6 +- src/DSL/Params/Highlight.php | 78 +++++----- src/DSL/Params/Knn.php | 53 +++---- src/DSL/Params/Rescore.php | 30 ++-- src/DSL/Params/Suggest.php | 6 +- src/DSL/Queries/Compound.php | 10 +- src/DSL/Queries/Compound/Boolean.php | 30 ++-- src/DSL/Queries/Compound/Boosting.php | 18 +-- src/DSL/Queries/Compound/ConstantScore.php | 6 +- src/DSL/Queries/Compound/DisjunctionMax.php | 12 +- src/DSL/Queries/Compound/FunctionScore.php | 42 +++--- src/DSL/Queries/Compound/Functions/Exp.php | 24 +-- .../Compound/Functions/FieldValueFactor.php | 18 +-- .../Queries/Compound/Functions/Function_.php | 32 ++-- src/DSL/Queries/Compound/Functions/Gauss.php | 24 +-- src/DSL/Queries/Compound/Functions/Linear.php | 24 +-- .../Compound/Functions/RandomScore.php | 6 +- .../Compound/Functions/ScriptScore.php | 6 +- src/DSL/Queries/FullText.php | 18 +-- src/DSL/Queries/FullText/CombinedFields.php | 36 ++--- src/DSL/Queries/FullText/Intervals.php | 38 ++--- src/DSL/Queries/FullText/Intervals/AllOf.php | 38 ++--- src/DSL/Queries/FullText/Intervals/AnyOf.php | 26 ++-- src/DSL/Queries/FullText/Intervals/Filter.php | 54 +++---- src/DSL/Queries/FullText/Intervals/Fuzzy.php | 36 ++--- src/DSL/Queries/FullText/Intervals/Match_.php | 36 ++--- src/DSL/Queries/FullText/Intervals/Prefix.php | 18 +-- src/DSL/Queries/FullText/Intervals/Range.php | 36 ++--- .../Queries/FullText/Intervals/Wildcard.php | 18 +-- src/DSL/Queries/FullText/MatchBoolPrefix.php | 60 ++++---- src/DSL/Queries/FullText/MatchPhrase.php | 24 +-- .../Queries/FullText/MatchPhrasePrefix.php | 30 ++-- src/DSL/Queries/FullText/Match_.php | 72 ++++----- src/DSL/Queries/FullText/MultiMatch.php | 96 ++++++------ src/DSL/Queries/FullText/QueryString.php | 138 +++++++++--------- .../Queries/FullText/SimpleQueryString.php | 78 +++++----- src/DSL/Queries/Geo.php | 10 +- src/DSL/Queries/Geo/GeoBoundingBox.php | 66 ++++----- src/DSL/Queries/Geo/GeoDistance.php | 26 ++-- src/DSL/Queries/Geo/GeoGrid.php | 18 +-- src/DSL/Queries/Geo/GeoPolygon.php | 18 +-- src/DSL/Queries/Geo/GeoShape.php | 24 +-- src/DSL/Queries/Joining.php | 8 +- src/DSL/Queries/Joining/HasChild.php | 36 ++--- src/DSL/Queries/Joining/HasParent.php | 24 +-- src/DSL/Queries/Joining/Nested.php | 24 +-- src/DSL/Queries/Joining/ParentId.php | 18 +-- src/DSL/Queries/MatchAll.php | 4 +- src/DSL/Queries/Script.php | 24 +-- src/DSL/Queries/Shape.php | 2 +- src/DSL/Queries/Shape/Shape.php | 18 +-- src/DSL/Queries/Span.php | 18 +-- src/DSL/Queries/Span/SpanContaining.php | 12 +- src/DSL/Queries/Span/SpanFieldMasking.php | 6 +- src/DSL/Queries/Span/SpanFirst.php | 12 +- src/DSL/Queries/Span/SpanMulti.php | 6 +- src/DSL/Queries/Span/SpanNear.php | 18 +-- src/DSL/Queries/Span/SpanNot.php | 30 ++-- src/DSL/Queries/Span/SpanOr.php | 6 +- src/DSL/Queries/Span/SpanTerm.php | 6 +- src/DSL/Queries/Span/SpanWithin.php | 12 +- src/DSL/Queries/Specialized.php | 16 +- .../Queries/Specialized/DistanceFeature.php | 12 +- src/DSL/Queries/Specialized/MoreLikeThis.php | 24 +-- src/DSL/Queries/Specialized/Percolate.php | 6 +- src/DSL/Queries/Specialized/Pinned.php | 18 +-- src/DSL/Queries/Specialized/RankFeature.php | 24 +-- src/DSL/Queries/Specialized/Script.php | 6 +- src/DSL/Queries/Specialized/ScriptScore.php | 18 +-- src/DSL/Queries/Specialized/Wrapper.php | 6 +- src/DSL/Queries/TermLevel.php | 20 +-- src/DSL/Queries/TermLevel/Fuzzy.php | 30 ++-- src/DSL/Queries/TermLevel/IDs.php | 6 +- src/DSL/Queries/TermLevel/Prefix.php | 12 +- src/DSL/Queries/TermLevel/Range.php | 42 +++--- src/DSL/Queries/TermLevel/Regexp.php | 24 +-- src/DSL/Queries/TermLevel/Term.php | 6 +- src/DSL/Queries/TermLevel/TermsSet.php | 24 +-- src/DSL/Queries/TermLevel/Wildcard.php | 18 +-- src/DSL/Query.php | 42 +++--- src/DSL/Support/ClausesSupport.php | 2 +- src/DSL/Support/RangeSupport.php | 2 +- 136 files changed, 1655 insertions(+), 1685 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 47a69ba..6bc47da 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -8,4 +8,5 @@ '@PSR12' => true, 'no_unused_imports' => true, ]) - ->setFinder($finder); + ->setFinder($finder) + ->setUnsupportedPhpVersionAllowed(true); diff --git a/composer.json b/composer.json index 058f8b6..ec1cc09 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,8 @@ ], "scripts": { "analyse": "phpstan analyse", - "cs-check": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff", - "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix" + "cs-check": "php-cs-fixer fix --dry-run --diff", + "cs-fix": "php-cs-fixer fix" }, "config": { "audit": { diff --git a/src/DSL/Agg.php b/src/DSL/Agg.php index 79a2aaa..7e41b01 100644 --- a/src/DSL/Agg.php +++ b/src/DSL/Agg.php @@ -94,12 +94,12 @@ protected function node($node): static * Similar to Node::field(), the alias wraps the output: * {"alias_name": {"terms": {"field": "status"}}}. * - * @param string $alias + * @param string $value * @return $this */ - public function alias($alias): static + public function alias($value): static { - $this->_alias = $alias; + $this->_alias = $value; return $this; } @@ -108,7 +108,7 @@ public function alias($alias): static * * @return string|null */ - public function getAlias() + public function getAlias(): ?string { return $this->_alias; } @@ -175,7 +175,7 @@ public function aggs($alias, $aggs = null): static * @param array $properties * @return array */ - protected function resolveProperties(array $properties) + protected function resolveProperties(array $properties): array { foreach ($properties as $key => $property) { if ($property instanceof Query) { diff --git a/src/DSL/Aggs/Bucket.php b/src/DSL/Aggs/Bucket.php index 4d11bcb..99fdb00 100644 --- a/src/DSL/Aggs/Bucket.php +++ b/src/DSL/Aggs/Bucket.php @@ -44,7 +44,7 @@ trait Bucket * @param mixed $params * @return static */ - public function terms($params) + public function terms($params): static { return $this->node(Terms::create(is_string($params) ? ['field' => $params] : $params)); } @@ -55,7 +55,7 @@ public function terms($params) * @param mixed $filter * @return static */ - public function filter($filter) + public function filter($filter): static { $instance = new Filter(); $instance->filter($filter); @@ -68,7 +68,7 @@ public function filter($filter) * @param mixed $params * @return static */ - public function filters($params) + public function filters($params): static { return $this->node(Filters::create($params)); } @@ -79,7 +79,7 @@ public function filters($params) * @param mixed $params * @return static */ - public function adjacencyMatrix($params) + public function adjacencyMatrix($params): static { return $this->node(AdjacencyMatrix::create($params)); } @@ -90,7 +90,7 @@ public function adjacencyMatrix($params) * @param mixed $params * @return static */ - public function autoDateHistogram($params) + public function autoDateHistogram($params): static { return $this->node(AutoDateHistogram::create(is_string($params) ? ['field' => $params] : $params)); } @@ -101,7 +101,7 @@ public function autoDateHistogram($params) * @param mixed $params * @return static */ - public function categorizeText($params) + public function categorizeText($params): static { return $this->node(CategorizeText::create(is_string($params) ? ['field' => $params] : $params)); } @@ -112,7 +112,7 @@ public function categorizeText($params) * @param mixed $params * @return static */ - public function composite($params) + public function composite($params): static { return $this->node(Composite::create($params)); } @@ -123,7 +123,7 @@ public function composite($params) * @param mixed $params * @return static */ - public function dateHistogram($params) + public function dateHistogram($params): static { return $this->node(DateHistogram::create(is_string($params) ? ['field' => $params] : $params)); } @@ -134,7 +134,7 @@ public function dateHistogram($params) * @param mixed $params * @return static */ - public function dateRange($params) + public function dateRange($params): static { return $this->node(DateRange::create(is_string($params) ? ['field' => $params] : $params)); } @@ -145,7 +145,7 @@ public function dateRange($params) * @param mixed $params * @return static */ - public function diversifiedSampler($params) + public function diversifiedSampler($params): static { return $this->node(DiversifiedSampler::create($params)); } @@ -156,7 +156,7 @@ public function diversifiedSampler($params) * @param mixed $params * @return static */ - public function frequentItemSets($params) + public function frequentItemSets($params): static { return $this->node(FrequentItemSets::create($params)); } @@ -167,7 +167,7 @@ public function frequentItemSets($params) * @param mixed $params * @return static */ - public function geoDistance($params) + public function geoDistance($params): static { return $this->node(GeoDistance::create(is_string($params) ? ['field' => $params] : $params)); } @@ -178,7 +178,7 @@ public function geoDistance($params) * @param mixed $params * @return static */ - public function geoHashGrid($params) + public function geoHashGrid($params): static { return $this->node(GeoHashGrid::create(is_string($params) ? ['field' => $params] : $params)); } @@ -189,7 +189,7 @@ public function geoHashGrid($params) * @param mixed $params * @return static */ - public function geohexGrid($params) + public function geohexGrid($params): static { return $this->node(GeohexGrid::create(is_string($params) ? ['field' => $params] : $params)); } @@ -200,7 +200,7 @@ public function geohexGrid($params) * @param mixed $params * @return static */ - public function geotileGrid($params) + public function geotileGrid($params): static { return $this->node(GeotileGrid::create(is_string($params) ? ['field' => $params] : $params)); } @@ -210,7 +210,7 @@ public function geotileGrid($params) * * @return static */ - public function global() + public function global(): static { return $this->node(new Global_()); } @@ -221,7 +221,7 @@ public function global() * @param mixed $params * @return static */ - public function histogram($params) + public function histogram($params): static { return $this->node(Histogram::create(is_string($params) ? ['field' => $params] : $params)); } @@ -232,7 +232,7 @@ public function histogram($params) * @param mixed $params * @return static */ - public function ipPrefix($params) + public function ipPrefix($params): static { return $this->node(IpPrefix::create(is_string($params) ? ['field' => $params] : $params)); } @@ -243,7 +243,7 @@ public function ipPrefix($params) * @param mixed $params * @return static */ - public function ipRange($params) + public function ipRange($params): static { return $this->node(IpRange::create($params)); } @@ -254,7 +254,7 @@ public function ipRange($params) * @param mixed $params * @return static */ - public function missing($params) + public function missing($params): static { return $this->node(Missing::create(is_string($params) ? ['field' => $params] : $params)); } @@ -265,7 +265,7 @@ public function missing($params) * @param mixed $params * @return static */ - public function multiTerms($params) + public function multiTerms($params): static { return $this->node(MultiTerms::create($params)); } @@ -276,7 +276,7 @@ public function multiTerms($params) * @param mixed $params * @return static */ - public function nested($params) + public function nested($params): static { return $this->node(Nested::create($params)); } @@ -287,7 +287,7 @@ public function nested($params) * @param mixed $params * @return static */ - public function parent($params) + public function parent($params): static { return $this->node(Parent_::create($params)); } @@ -298,7 +298,7 @@ public function parent($params) * @param mixed $params * @return static */ - public function randomSampler($params) + public function randomSampler($params): static { return $this->node(RandomSampler::create($params)); } @@ -309,7 +309,7 @@ public function randomSampler($params) * @param mixed $params * @return static */ - public function range($params) + public function range($params): static { return $this->node(Range::create(is_string($params) ? ['field' => $params] : $params)); } @@ -320,7 +320,7 @@ public function range($params) * @param mixed $params * @return static */ - public function rareTerms($params) + public function rareTerms($params): static { return $this->node(RareTerms::create(is_string($params) ? ['field' => $params] : $params)); } @@ -331,7 +331,7 @@ public function rareTerms($params) * @param mixed $params * @return static */ - public function reverseNested($params = []) + public function reverseNested($params = []): static { return $this->node(ReverseNested::create($params)); } @@ -342,7 +342,7 @@ public function reverseNested($params = []) * @param mixed $params * @return static */ - public function significantTerms($params) + public function significantTerms($params): static { return $this->node(SignificantTerms::create(is_string($params) ? ['field' => $params] : $params)); } @@ -353,7 +353,7 @@ public function significantTerms($params) * @param mixed $params * @return static */ - public function significantText($params) + public function significantText($params): static { return $this->node(SignificantText::create(is_string($params) ? ['field' => $params] : $params)); } @@ -364,7 +364,7 @@ public function significantText($params) * @param mixed $params * @return static */ - public function timeSeries($params) + public function timeSeries($params): static { return $this->node(TimeSeries::create($params)); } @@ -375,7 +375,7 @@ public function timeSeries($params) * @param mixed $params * @return static */ - public function variableWidthHistogram($params) + public function variableWidthHistogram($params): static { return $this->node(VariableWidthHistogram::create(is_string($params) ? ['field' => $params] : $params)); } diff --git a/src/DSL/Aggs/Bucket/AdjacencyMatrix.php b/src/DSL/Aggs/Bucket/AdjacencyMatrix.php index 36eb9a2..7bd2425 100644 --- a/src/DSL/Aggs/Bucket/AdjacencyMatrix.php +++ b/src/DSL/Aggs/Bucket/AdjacencyMatrix.php @@ -31,11 +31,11 @@ public function filters($key, $query): static /** * Separator used to concatenate filter names. Defaults to &. * - * @param string $separator + * @param string $value * @return static */ - public function separator(string $separator): static + public function separator(string $value): static { - return $this->addProperty('separator', $separator); + return $this->addProperty('separator', $value); } } diff --git a/src/DSL/Aggs/Bucket/AutoDateHistogram.php b/src/DSL/Aggs/Bucket/AutoDateHistogram.php index aa9fa77..518ec28 100644 --- a/src/DSL/Aggs/Bucket/AutoDateHistogram.php +++ b/src/DSL/Aggs/Bucket/AutoDateHistogram.php @@ -16,55 +16,55 @@ class AutoDateHistogram extends Node /** * Target number of buckets to return. * - * @param int $buckets + * @param int $value * @return static */ - public function buckets(int $buckets): static + public function buckets(int $value): static { - return $this->addProperty('buckets', $buckets); + return $this->addProperty('buckets', $value); } /** * Date format pattern for bucket keys. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * Time zone for bucketing. * - * @param string $timeZone + * @param string $value * @return static */ - public function timeZone(string $timeZone): static + public function timeZone(string $value): static { - return $this->addProperty('time_zone', $timeZone); + return $this->addProperty('time_zone', $value); } /** * Minimum interval to use when automatically determining buckets. * - * @param string $minimumInterval + * @param string $value * @return static */ - public function minimumInterval(string $minimumInterval): static + public function minimumInterval(string $value): static { - return $this->addProperty('minimum_interval', $minimumInterval); + return $this->addProperty('minimum_interval', $value); } /** * Value to use for documents missing the field value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Bucket/CategorizeText.php b/src/DSL/Aggs/Bucket/CategorizeText.php index 09f74e8..91bcdb5 100644 --- a/src/DSL/Aggs/Bucket/CategorizeText.php +++ b/src/DSL/Aggs/Bucket/CategorizeText.php @@ -16,99 +16,99 @@ class CategorizeText extends Node /** * Analyzer used for categorization. * - * @param mixed $categorizationAnalyzer + * @param mixed $value * @return static */ - public function categorizationAnalyzer($categorizationAnalyzer): static + public function categorizationAnalyzer($value): static { - return $this->addProperty('categorization_analyzer', $categorizationAnalyzer); + return $this->addProperty('categorization_analyzer', $value); } /** * Filters applied to each token before categorization. * - * @param array $categorizationFilters + * @param array $value * @return static */ - public function categorizationFilters(array $categorizationFilters): static + public function categorizationFilters(array $value): static { - return $this->addProperty('categorization_filters', $categorizationFilters); + return $this->addProperty('categorization_filters', $value); } /** * Maximum number of matched tokens to consider. * - * @param int $maxMatchedTokens + * @param int $value * @return static */ - public function maxMatchedTokens(int $maxMatchedTokens): static + public function maxMatchedTokens(int $value): static { - return $this->addProperty('max_matched_tokens', $maxMatchedTokens); + return $this->addProperty('max_matched_tokens', $value); } /** * Maximum number of unique tokens to consider. * - * @param int $maxUniqueTokens + * @param int $value * @return static */ - public function maxUniqueTokens(int $maxUniqueTokens): static + public function maxUniqueTokens(int $value): static { - return $this->addProperty('max_unique_tokens', $maxUniqueTokens); + return $this->addProperty('max_unique_tokens', $value); } /** * Minimum document count per bucket. * - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** * Minimum document count per shard. * - * @param int $shardMinDocCount + * @param int $value * @return static */ - public function shardMinDocCount(int $shardMinDocCount): static + public function shardMinDocCount(int $value): static { - return $this->addProperty('shard_min_doc_count', $shardMinDocCount); + return $this->addProperty('shard_min_doc_count', $value); } /** * Number of categories to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } /** * Similarity threshold for grouping categories. * - * @param float $similarityThreshold + * @param float $value * @return static */ - public function similarityThreshold(float $similarityThreshold): static + public function similarityThreshold(float $value): static { - return $this->addProperty('similarity_threshold', $similarityThreshold); + return $this->addProperty('similarity_threshold', $value); } /** * Maximum number of categories to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } } diff --git a/src/DSL/Aggs/Bucket/Composite.php b/src/DSL/Aggs/Bucket/Composite.php index c3a57ae..8614888 100644 --- a/src/DSL/Aggs/Bucket/Composite.php +++ b/src/DSL/Aggs/Bucket/Composite.php @@ -16,44 +16,44 @@ class Composite extends Node /** * List of source definitions used to build composite buckets. * - * @param mixed $sources + * @param mixed $value * @return static */ - public function sources($sources): static + public function sources($value): static { - return $this->addProperty('sources', $sources); + return $this->addProperty('sources', $value); } /** * Cursor value to resume pagination after a previous composite response. * - * @param mixed $after + * @param mixed $value * @return static */ - public function after($after): static + public function after($value): static { - return $this->addProperty('after', $after); + return $this->addProperty('after', $value); } /** * Sort order for composite buckets. * - * @param mixed $order + * @param mixed $value * @return static */ - public function order($order): static + public function order($value): static { - return $this->addProperty('order', $order); + return $this->addProperty('order', $value); } /** * Maximum number of composite buckets to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } } diff --git a/src/DSL/Aggs/Bucket/DateHistogram.php b/src/DSL/Aggs/Bucket/DateHistogram.php index e95c988..82110b2 100644 --- a/src/DSL/Aggs/Bucket/DateHistogram.php +++ b/src/DSL/Aggs/Bucket/DateHistogram.php @@ -16,132 +16,132 @@ class DateHistogram extends Node /** * Calendar-aware interval for bucketing (e.g. month, week). * - * @param string $calendarInterval + * @param string $value * @return static */ - public function calendarInterval(string $calendarInterval): static + public function calendarInterval(string $value): static { - return $this->addProperty('calendar_interval', $calendarInterval); + return $this->addProperty('calendar_interval', $value); } /** * Interval for bucketing. Deprecated in favor of calendar_interval or fixed_interval. * - * @param string $interval + * @param string $value * @return static */ - public function interval(string $interval): static + public function interval(string $value): static { - return $this->addProperty('interval', $interval); + return $this->addProperty('interval', $value); } /** * Fixed-unit interval for bucketing (e.g. 30d, 12h). * - * @param string $fixedInterval + * @param string $value * @return static */ - public function fixedInterval(string $fixedInterval): static + public function fixedInterval(string $value): static { - return $this->addProperty('fixed_interval', $fixedInterval); + return $this->addProperty('fixed_interval', $value); } /** * Date format pattern for bucket keys. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * Time zone for bucketing. * - * @param string $timeZone + * @param string $value * @return static */ - public function timeZone(string $timeZone): static + public function timeZone(string $value): static { - return $this->addProperty('time_zone', $timeZone); + return $this->addProperty('time_zone', $value); } /** * Minimum number of documents in a bucket to be returned. * - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** * Extends the bucket range beyond the data bounds. * - * @param mixed $extendedBounds + * @param mixed $value * @return static */ - public function extendedBounds($extendedBounds): static + public function extendedBounds($value): static { - return $this->addProperty('extended_bounds', $extendedBounds); + return $this->addProperty('extended_bounds', $value); } /** * Limits the bucket range to a bounded range. * - * @param mixed $hardBounds + * @param mixed $value * @return static */ - public function hardBounds($hardBounds): static + public function hardBounds($value): static { - return $this->addProperty('hard_bounds', $hardBounds); + return $this->addProperty('hard_bounds', $value); } /** * Sort order for buckets. * - * @param mixed $order + * @param mixed $value * @return static */ - public function order($order): static + public function order($value): static { - return $this->addProperty('order', $order); + return $this->addProperty('order', $value); } /** * Whether to return bucket keys as strings. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } /** * Value to use for documents missing the field value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * Offset for each bucket start time. * - * @param string $offset + * @param string $value * @return static */ - public function offset(string $offset): static + public function offset(string $value): static { - return $this->addProperty('offset', $offset); + return $this->addProperty('offset', $value); } } diff --git a/src/DSL/Aggs/Bucket/DateRange.php b/src/DSL/Aggs/Bucket/DateRange.php index cd19739..e62b25d 100644 --- a/src/DSL/Aggs/Bucket/DateRange.php +++ b/src/DSL/Aggs/Bucket/DateRange.php @@ -16,55 +16,55 @@ class DateRange extends Node /** * Array of range definitions for bucketing. * - * @param array $ranges + * @param array $value * @return static */ - public function ranges(array $ranges): static + public function ranges(array $value): static { - return $this->addProperty('ranges', $ranges); + return $this->addProperty('ranges', $value); } /** * Whether to return range buckets as a hash keyed by range key. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } /** * Date format pattern for range keys. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * Value to use for documents missing the field value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * Time zone for date calculations. * - * @param string $timeZone + * @param string $value * @return static */ - public function timeZone(string $timeZone): static + public function timeZone(string $value): static { - return $this->addProperty('time_zone', $timeZone); + return $this->addProperty('time_zone', $value); } } diff --git a/src/DSL/Aggs/Bucket/DiversifiedSampler.php b/src/DSL/Aggs/Bucket/DiversifiedSampler.php index d50f4b7..938127a 100644 --- a/src/DSL/Aggs/Bucket/DiversifiedSampler.php +++ b/src/DSL/Aggs/Bucket/DiversifiedSampler.php @@ -16,33 +16,33 @@ class DiversifiedSampler extends Node /** * Number of documents to sample per shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } /** * Maximum number of documents per unique value. * - * @param int $maxDocsPerValue + * @param int $value * @return static */ - public function maxDocsPerValue(int $maxDocsPerValue): static + public function maxDocsPerValue(int $value): static { - return $this->addProperty('max_docs_per_value', $maxDocsPerValue); + return $this->addProperty('max_docs_per_value', $value); } /** * Execution hint for the aggregation. * - * @param string $executionHint + * @param string $value * @return static */ - public function executionHint(string $executionHint): static + public function executionHint(string $value): static { - return $this->addProperty('execution_hint', $executionHint); + return $this->addProperty('execution_hint', $value); } } diff --git a/src/DSL/Aggs/Bucket/Filter.php b/src/DSL/Aggs/Bucket/Filter.php index 5eb9abe..0adf209 100644 --- a/src/DSL/Aggs/Bucket/Filter.php +++ b/src/DSL/Aggs/Bucket/Filter.php @@ -20,12 +20,12 @@ class Filter extends Node /** * The filter query to apply. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - $this->_filter = $filter; + $this->_filter = $value; return $this; } diff --git a/src/DSL/Aggs/Bucket/Filters.php b/src/DSL/Aggs/Bucket/Filters.php index 33282d8..0e42e6e 100644 --- a/src/DSL/Aggs/Bucket/Filters.php +++ b/src/DSL/Aggs/Bucket/Filters.php @@ -16,33 +16,33 @@ class Filters extends Node /** * Filter queries used to create buckets. * - * @param mixed $filters + * @param mixed $value * @return static */ - public function filters($filters): static + public function filters($value): static { - return $this->addProperty('filters', $filters); + return $this->addProperty('filters', $value); } /** * Key for the bucket that holds documents not matching any filter. * - * @param string $otherBucketKey + * @param string $value * @return static */ - public function otherBucketKey(string $otherBucketKey): static + public function otherBucketKey(string $value): static { - return $this->addProperty('other_bucket_key', $otherBucketKey); + return $this->addProperty('other_bucket_key', $value); } /** * Whether to return buckets as a hash keyed by filter name. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } } diff --git a/src/DSL/Aggs/Bucket/FrequentItemSets.php b/src/DSL/Aggs/Bucket/FrequentItemSets.php index 7fd11af..7a66431 100644 --- a/src/DSL/Aggs/Bucket/FrequentItemSets.php +++ b/src/DSL/Aggs/Bucket/FrequentItemSets.php @@ -16,44 +16,44 @@ class FrequentItemSets extends Node /** * Minimum size of an item set. * - * @param int $minimumSetSize + * @param int $value * @return static */ - public function minimumSetSize(int $minimumSetSize): static + public function minimumSetSize(int $value): static { - return $this->addProperty('minimum_set_size', $minimumSetSize); + return $this->addProperty('minimum_set_size', $value); } /** * Fields to analyze for frequent item sets. * - * @param array $fields + * @param array $value * @return static */ - public function fields(array $fields): static + public function fields(array $value): static { - return $this->addProperty('fields', $fields); + return $this->addProperty('fields', $value); } /** * Maximum number of item sets to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Query to filter documents before analysis. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addProperty('filter', $filter); + return $this->addProperty('filter', $value); } } diff --git a/src/DSL/Aggs/Bucket/GeoDistance.php b/src/DSL/Aggs/Bucket/GeoDistance.php index 8e05b02..77411db 100644 --- a/src/DSL/Aggs/Bucket/GeoDistance.php +++ b/src/DSL/Aggs/Bucket/GeoDistance.php @@ -16,55 +16,55 @@ class GeoDistance extends Node /** * The central geo point from which distances are measured. * - * @param mixed $origin + * @param mixed $value * @return static */ - public function origin($origin): static + public function origin($value): static { - return $this->addProperty('origin', $origin); + return $this->addProperty('origin', $value); } /** * Distance unit (e.g. km, mi, m). * - * @param string $unit + * @param string $value * @return static */ - public function unit(string $unit): static + public function unit(string $value): static { - return $this->addProperty('unit', $unit); + return $this->addProperty('unit', $value); } /** * How to compute the distance (arc or plane). * - * @param string $distanceType + * @param string $value * @return static */ - public function distanceType(string $distanceType): static + public function distanceType(string $value): static { - return $this->addProperty('distance_type', $distanceType); + return $this->addProperty('distance_type', $value); } /** * Array of distance range definitions for bucketing. * - * @param array $ranges + * @param array $value * @return static */ - public function ranges(array $ranges): static + public function ranges(array $value): static { - return $this->addProperty('ranges', $ranges); + return $this->addProperty('ranges', $value); } /** * Whether to return range buckets as a hash keyed by range key. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } } diff --git a/src/DSL/Aggs/Bucket/GeoHashGrid.php b/src/DSL/Aggs/Bucket/GeoHashGrid.php index 15b75b6..9e46e3b 100644 --- a/src/DSL/Aggs/Bucket/GeoHashGrid.php +++ b/src/DSL/Aggs/Bucket/GeoHashGrid.php @@ -16,33 +16,33 @@ class GeoHashGrid extends Node /** * Geohash precision (length) for grid cells. * - * @param int $precision + * @param int $value * @return static */ - public function precision(int $precision): static + public function precision(int $value): static { - return $this->addProperty('precision', $precision); + return $this->addProperty('precision', $value); } /** * Maximum number of geohash buckets to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Number of geohash buckets to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } } diff --git a/src/DSL/Aggs/Bucket/GeohexGrid.php b/src/DSL/Aggs/Bucket/GeohexGrid.php index d8ad854..5f93015 100644 --- a/src/DSL/Aggs/Bucket/GeohexGrid.php +++ b/src/DSL/Aggs/Bucket/GeohexGrid.php @@ -16,33 +16,33 @@ class GeohexGrid extends Node /** * H3 resolution for grid cells. * - * @param int $precision + * @param int $value * @return static */ - public function precision(int $precision): static + public function precision(int $value): static { - return $this->addProperty('precision', $precision); + return $this->addProperty('precision', $value); } /** * Maximum number of hex buckets to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Number of hex buckets to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } } diff --git a/src/DSL/Aggs/Bucket/GeotileGrid.php b/src/DSL/Aggs/Bucket/GeotileGrid.php index 2e95403..aa61d5a 100644 --- a/src/DSL/Aggs/Bucket/GeotileGrid.php +++ b/src/DSL/Aggs/Bucket/GeotileGrid.php @@ -16,33 +16,33 @@ class GeotileGrid extends Node /** * Zoom level (precision) for geotile grid cells. * - * @param int $precision + * @param int $value * @return static */ - public function precision(int $precision): static + public function precision(int $value): static { - return $this->addProperty('precision', $precision); + return $this->addProperty('precision', $value); } /** * Maximum number of geotile buckets to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Number of geotile buckets to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } } diff --git a/src/DSL/Aggs/Bucket/Histogram.php b/src/DSL/Aggs/Bucket/Histogram.php index 196eb5a..c721b42 100644 --- a/src/DSL/Aggs/Bucket/Histogram.php +++ b/src/DSL/Aggs/Bucket/Histogram.php @@ -16,110 +16,110 @@ class Histogram extends Node /** * Interval size for each bucket. * - * @param float $interval + * @param float $value * @return static */ - public function interval(float $interval): static + public function interval(float $value): static { - return $this->addProperty('interval', $interval); + return $this->addProperty('interval', $value); } /** * Minimum number of documents in a bucket to be returned. * - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** * Extends the bucket range beyond the data bounds. * - * @param mixed $bounds + * @param mixed $value * @return static */ - public function extendedBounds($bounds): static + public function extendedBounds($value): static { - return $this->addProperty('extended_bounds', $bounds); + return $this->addProperty('extended_bounds', $value); } /** * Sort order for buckets. * - * @param mixed $order + * @param mixed $value * @return static */ - public function order($order): static + public function order($value): static { - return $this->addProperty('order', $order); + return $this->addProperty('order', $value); } /** * Whether to return bucket keys as strings. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } /** * Value to use for documents missing the field value. * - * @param float $missing + * @param float $value * @return static */ - public function missing(float $missing): static + public function missing(float $value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * Format pattern for bucket key values. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * Script to compute the bucket value. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } /** * Offset for bucket starting values. * - * @param float $offset + * @param float $value * @return static */ - public function offset(float $offset): static + public function offset(float $value): static { - return $this->addProperty('offset', $offset); + return $this->addProperty('offset', $value); } /** * Limits the bucket range to a bounded range. * - * @param mixed $hardBounds + * @param mixed $value * @return static */ - public function hardBounds($hardBounds): static + public function hardBounds($value): static { - return $this->addProperty('hard_bounds', $hardBounds); + return $this->addProperty('hard_bounds', $value); } } diff --git a/src/DSL/Aggs/Bucket/IpPrefix.php b/src/DSL/Aggs/Bucket/IpPrefix.php index b59655b..433ad0c 100644 --- a/src/DSL/Aggs/Bucket/IpPrefix.php +++ b/src/DSL/Aggs/Bucket/IpPrefix.php @@ -13,20 +13,20 @@ class IpPrefix extends Node /** * Length of the network prefix. * - * @param int $length + * @param int $value * @return static */ - public function prefixLength(int $length): static + public function prefixLength(int $value): static { - return $this->addProperty('prefix_length', $length); + return $this->addProperty('prefix_length', $value); } /** - * @param int $length + * @param int $value * @return static */ - public function minPrefixLength(int $length): static + public function minPrefixLength(int $value): static { - return $this->addProperty('min_prefix_length', $length); + return $this->addProperty('min_prefix_length', $value); } } diff --git a/src/DSL/Aggs/Bucket/IpRange.php b/src/DSL/Aggs/Bucket/IpRange.php index 3ca179b..51f1cb3 100644 --- a/src/DSL/Aggs/Bucket/IpRange.php +++ b/src/DSL/Aggs/Bucket/IpRange.php @@ -16,33 +16,33 @@ class IpRange extends Node /** * Array of IP range definitions for bucketing. * - * @param array $ranges + * @param array $value * @return static */ - public function ranges(array $ranges): static + public function ranges(array $value): static { - return $this->addProperty('ranges', $ranges); + return $this->addProperty('ranges', $value); } /** * Whether to return range buckets as a hash keyed by range key. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } /** * Value to use for documents missing the field value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Bucket/Missing.php b/src/DSL/Aggs/Bucket/Missing.php index 5da5b46..c445f03 100644 --- a/src/DSL/Aggs/Bucket/Missing.php +++ b/src/DSL/Aggs/Bucket/Missing.php @@ -16,11 +16,11 @@ class Missing extends Node /** * Value to treat as missing for the field. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Bucket/MultiTerms.php b/src/DSL/Aggs/Bucket/MultiTerms.php index 15d73bb..98620b4 100644 --- a/src/DSL/Aggs/Bucket/MultiTerms.php +++ b/src/DSL/Aggs/Bucket/MultiTerms.php @@ -11,65 +11,65 @@ class MultiTerms extends Node protected string $_key = 'multi_terms'; /** - * @param mixed $terms + * @param mixed $value * @return static */ - public function terms($terms): static + public function terms($value): static { - return $this->addProperty('terms', $terms, true); + return $this->addProperty('terms', $value, true); } /** - * @param mixed $order + * @param mixed $value * @return static */ - public function order($order): static + public function order($value): static { - return $this->addProperty('order', $order); + return $this->addProperty('order', $value); } /** - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } /** - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** - * @param int $shardMinDocCount + * @param int $value * @return static */ - public function shardMinDocCount(int $shardMinDocCount): static + public function shardMinDocCount(int $value): static { - return $this->addProperty('shard_min_doc_count', $shardMinDocCount); + return $this->addProperty('shard_min_doc_count', $value); } /** - * @param string $collectMode + * @param string $value * @return static */ - public function collectMode(string $collectMode): static + public function collectMode(string $value): static { - return $this->addProperty('collect_mode', $collectMode); + return $this->addProperty('collect_mode', $value); } } diff --git a/src/DSL/Aggs/Bucket/Nested.php b/src/DSL/Aggs/Bucket/Nested.php index 2c69bad..5f185fc 100644 --- a/src/DSL/Aggs/Bucket/Nested.php +++ b/src/DSL/Aggs/Bucket/Nested.php @@ -16,22 +16,22 @@ class Nested extends Node /** * Path to the nested object to aggregate on. * - * @param string $path + * @param string $value * @return static */ - public function path(string $path): static + public function path(string $value): static { - return $this->addProperty('path', $path); + return $this->addProperty('path', $value); } /** * Whether to return an empty bucket instead of an error for unmapped nested types. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Aggs/Bucket/Parent_.php b/src/DSL/Aggs/Bucket/Parent_.php index 9de4c8d..82b4154 100644 --- a/src/DSL/Aggs/Bucket/Parent_.php +++ b/src/DSL/Aggs/Bucket/Parent_.php @@ -16,11 +16,11 @@ class Parent_ extends Node /** * The child type that identifies the parent documents to aggregate on. * - * @param string $type + * @param string $value * @return static */ - public function type(string $type): static + public function type(string $value): static { - return $this->addProperty('type', $type); + return $this->addProperty('type', $value); } } diff --git a/src/DSL/Aggs/Bucket/RandomSampler.php b/src/DSL/Aggs/Bucket/RandomSampler.php index 03a93f6..3e5217d 100644 --- a/src/DSL/Aggs/Bucket/RandomSampler.php +++ b/src/DSL/Aggs/Bucket/RandomSampler.php @@ -16,22 +16,22 @@ class RandomSampler extends Node /** * Probability that a document is included in the sample (between 0 and 1). * - * @param float $probability + * @param float $value * @return static */ - public function probability(float $probability): static + public function probability(float $value): static { - return $this->addProperty('probability', $probability); + return $this->addProperty('probability', $value); } /** * Seed for the random number generator to produce repeatable samples. * - * @param int $seed + * @param int $value * @return static */ - public function seed(int $seed): static + public function seed(int $value): static { - return $this->addProperty('seed', $seed); + return $this->addProperty('seed', $value); } } diff --git a/src/DSL/Aggs/Bucket/Range.php b/src/DSL/Aggs/Bucket/Range.php index 24b2acf..e87eaae 100644 --- a/src/DSL/Aggs/Bucket/Range.php +++ b/src/DSL/Aggs/Bucket/Range.php @@ -16,44 +16,44 @@ class Range extends Node /** * Array of range definitions for bucketing. * - * @param array $ranges + * @param array $value * @return static */ - public function ranges(array $ranges): static + public function ranges(array $value): static { - return $this->addProperty('ranges', $ranges); + return $this->addProperty('ranges', $value); } /** * Whether to return range buckets as a hash keyed by range key. * - * @param bool $keyed + * @param bool $value * @return static */ - public function keyed(bool $keyed): static + public function keyed(bool $value): static { - return $this->addProperty('keyed', $keyed); + return $this->addProperty('keyed', $value); } /** * Script to compute the bucket value. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } /** * Value to use for documents missing the field value. * - * @param float $missing + * @param float $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Bucket/RareTerms.php b/src/DSL/Aggs/Bucket/RareTerms.php index f89e835..ad0ae34 100644 --- a/src/DSL/Aggs/Bucket/RareTerms.php +++ b/src/DSL/Aggs/Bucket/RareTerms.php @@ -11,56 +11,56 @@ class RareTerms extends Node protected string $_key = 'rare_terms'; /** - * @param int $maxDocCount + * @param int $value * @return static */ - public function maxDocCount(int $maxDocCount): static + public function maxDocCount(int $value): static { - return $this->addProperty('max_doc_count', $maxDocCount); + return $this->addProperty('max_doc_count', $value); } /** - * @param mixed $precision + * @param mixed $value * @return static */ - public function precision($precision): static + public function precision($value): static { - return $this->addProperty('precision', $precision); + return $this->addProperty('precision', $value); } /** - * @param mixed $include + * @param mixed $value * @return static */ - public function include($include): static + public function include($value): static { - return $this->addProperty('include', $include); + return $this->addProperty('include', $value); } /** - * @param mixed $exclude + * @param mixed $value * @return static */ - public function exclude($exclude): static + public function exclude($value): static { - return $this->addProperty('exclude', $exclude); + return $this->addProperty('exclude', $value); } /** - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } } diff --git a/src/DSL/Aggs/Bucket/ReverseNested.php b/src/DSL/Aggs/Bucket/ReverseNested.php index b8c0292..39c8d64 100644 --- a/src/DSL/Aggs/Bucket/ReverseNested.php +++ b/src/DSL/Aggs/Bucket/ReverseNested.php @@ -27,11 +27,11 @@ public function toArray() /** * Path to the nested object to reverse out of. * - * @param string $path + * @param string $value * @return static */ - public function path(string $path): static + public function path(string $value): static { - return $this->addProperty('path', $path); + return $this->addProperty('path', $value); } } diff --git a/src/DSL/Aggs/Bucket/SignificantTerms.php b/src/DSL/Aggs/Bucket/SignificantTerms.php index e933b57..17fe658 100644 --- a/src/DSL/Aggs/Bucket/SignificantTerms.php +++ b/src/DSL/Aggs/Bucket/SignificantTerms.php @@ -16,88 +16,88 @@ class SignificantTerms extends Node /** * Maximum number of significant terms to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Number of candidate terms to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } /** * Minimum document count for a term to be returned. * - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** * Minimum document count for a term to be considered on each shard. * - * @param int $shardMinDocCount + * @param int $value * @return static */ - public function shardMinDocCount(int $shardMinDocCount): static + public function shardMinDocCount(int $value): static { - return $this->addProperty('shard_min_doc_count', $shardMinDocCount); + return $this->addProperty('shard_min_doc_count', $value); } /** * Terms to include in the aggregation. * - * @param mixed $include + * @param mixed $value * @return static */ - public function include($include): static + public function include($value): static { - return $this->addProperty('include', $include); + return $this->addProperty('include', $value); } /** * Terms to exclude from the aggregation. * - * @param mixed $exclude + * @param mixed $value * @return static */ - public function exclude($exclude): static + public function exclude($value): static { - return $this->addProperty('exclude', $exclude); + return $this->addProperty('exclude', $value); } /** * Query to filter the background document set for significance calculation. * - * @param mixed $backgroundFilter + * @param mixed $value * @return static */ - public function backgroundFilter($backgroundFilter): static + public function backgroundFilter($value): static { - return $this->addProperty('background_filter', $backgroundFilter); + return $this->addProperty('background_filter', $value); } /** * Execution hint for the aggregation mechanism. * - * @param string $executionHint + * @param string $value * @return static */ - public function executionHint(string $executionHint): static + public function executionHint(string $value): static { - return $this->addProperty('execution_hint', $executionHint); + return $this->addProperty('execution_hint', $value); } } diff --git a/src/DSL/Aggs/Bucket/SignificantText.php b/src/DSL/Aggs/Bucket/SignificantText.php index f7736f2..cd78ec1 100644 --- a/src/DSL/Aggs/Bucket/SignificantText.php +++ b/src/DSL/Aggs/Bucket/SignificantText.php @@ -16,88 +16,88 @@ class SignificantText extends Node /** * Maximum number of significant terms to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Number of candidate terms to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } /** * Minimum document count for a term to be returned. * - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** * Minimum document count for a term to be considered on each shard. * - * @param int $shardMinDocCount + * @param int $value * @return static */ - public function shardMinDocCount(int $shardMinDocCount): static + public function shardMinDocCount(int $value): static { - return $this->addProperty('shard_min_doc_count', $shardMinDocCount); + return $this->addProperty('shard_min_doc_count', $value); } /** * Terms to include in the aggregation. * - * @param mixed $include + * @param mixed $value * @return static */ - public function include($include): static + public function include($value): static { - return $this->addProperty('include', $include); + return $this->addProperty('include', $value); } /** * Terms to exclude from the aggregation. * - * @param mixed $exclude + * @param mixed $value * @return static */ - public function exclude($exclude): static + public function exclude($value): static { - return $this->addProperty('exclude', $exclude); + return $this->addProperty('exclude', $value); } /** * Query to filter the background document set for significance calculation. * - * @param mixed $backgroundFilter + * @param mixed $value * @return static */ - public function backgroundFilter($backgroundFilter): static + public function backgroundFilter($value): static { - return $this->addProperty('background_filter', $backgroundFilter); + return $this->addProperty('background_filter', $value); } /** * Whether to filter duplicate text before analysis. * - * @param bool $filter + * @param bool $value * @return static */ - public function filterDuplicateText(bool $filter): static + public function filterDuplicateText(bool $value): static { - return $this->addProperty('filter_duplicate_text', $filter); + return $this->addProperty('filter_duplicate_text', $value); } } diff --git a/src/DSL/Aggs/Bucket/Terms.php b/src/DSL/Aggs/Bucket/Terms.php index 76526fa..d7bf761 100644 --- a/src/DSL/Aggs/Bucket/Terms.php +++ b/src/DSL/Aggs/Bucket/Terms.php @@ -16,121 +16,121 @@ class Terms extends Node /** * Maximum number of term buckets to return. * - * @param int $size + * @param int $value * @return static */ - public function size(int $size): static + public function size(int $value): static { - return $this->addProperty('size', $size); + return $this->addProperty('size', $value); } /** * Sort order for term buckets. * - * @param mixed $order + * @param mixed $value * @return static */ - public function order($order): static + public function order($value): static { - return $this->addProperty('order', $order); + return $this->addProperty('order', $value); } /** * Minimum document count for a term bucket to be returned. * - * @param int $minDocCount + * @param int $value * @return static */ - public function minDocCount(int $minDocCount): static + public function minDocCount(int $value): static { - return $this->addProperty('min_doc_count', $minDocCount); + return $this->addProperty('min_doc_count', $value); } /** * Number of term buckets to return from each shard. * - * @param int $shardSize + * @param int $value * @return static */ - public function shardSize(int $shardSize): static + public function shardSize(int $value): static { - return $this->addProperty('shard_size', $shardSize); + return $this->addProperty('shard_size', $value); } /** * Whether to show document count error for each term. * - * @param bool $show + * @param bool $value * @return static */ - public function showTermDocCountError(bool $show): static + public function showTermDocCountError(bool $value): static { - return $this->addProperty('show_term_doc_count_error', $show); + return $this->addProperty('show_term_doc_count_error', $value); } /** * Minimum document count for a term to be considered on each shard. * - * @param int $shardMinDocCount + * @param int $value * @return static */ - public function shardMinDocCount(int $shardMinDocCount): static + public function shardMinDocCount(int $value): static { - return $this->addProperty('shard_min_doc_count', $shardMinDocCount); + return $this->addProperty('shard_min_doc_count', $value); } /** * Value to use for documents missing the field value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * Collection mode for the aggregation (breadth_first or depth_first). * - * @param string $collectMode + * @param string $value * @return static */ - public function collectMode(string $collectMode): static + public function collectMode(string $value): static { - return $this->addProperty('collect_mode', $collectMode); + return $this->addProperty('collect_mode', $value); } /** * Terms to include in the aggregation. * - * @param mixed $include + * @param mixed $value * @return static */ - public function include($include): static + public function include($value): static { - return $this->addProperty('include', $include); + return $this->addProperty('include', $value); } /** * Terms to exclude from the aggregation. * - * @param mixed $exclude + * @param mixed $value * @return static */ - public function exclude($exclude): static + public function exclude($value): static { - return $this->addProperty('exclude', $exclude); + return $this->addProperty('exclude', $value); } /** * Execution hint for the aggregation mechanism. * - * @param string $executionHint + * @param string $value * @return static */ - public function executionHint(string $executionHint): static + public function executionHint(string $value): static { - return $this->addProperty('execution_hint', $executionHint); + return $this->addProperty('execution_hint', $value); } } diff --git a/src/DSL/Aggs/Bucket/TimeSeries.php b/src/DSL/Aggs/Bucket/TimeSeries.php index f170918..0d0b144 100644 --- a/src/DSL/Aggs/Bucket/TimeSeries.php +++ b/src/DSL/Aggs/Bucket/TimeSeries.php @@ -11,29 +11,29 @@ class TimeSeries extends Node protected string $_key = 'time_series'; /** - * @param string $calendarInterval + * @param string $value * @return static */ - public function calendarInterval(string $calendarInterval): static + public function calendarInterval(string $value): static { - return $this->addProperty('calendar_interval', $calendarInterval); + return $this->addProperty('calendar_interval', $value); } /** - * @param string $fixedInterval + * @param string $value * @return static */ - public function fixedInterval(string $fixedInterval): static + public function fixedInterval(string $value): static { - return $this->addProperty('fixed_interval', $fixedInterval); + return $this->addProperty('fixed_interval', $value); } /** - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Bucket/VariableWidthHistogram.php b/src/DSL/Aggs/Bucket/VariableWidthHistogram.php index 8f987eb..df6091e 100644 --- a/src/DSL/Aggs/Bucket/VariableWidthHistogram.php +++ b/src/DSL/Aggs/Bucket/VariableWidthHistogram.php @@ -11,20 +11,20 @@ class VariableWidthHistogram extends Node protected string $_key = 'variable_width_histogram'; /** - * @param int $buckets + * @param int $value * @return static */ - public function buckets(int $buckets): static + public function buckets(int $value): static { - return $this->addProperty('buckets', $buckets); + return $this->addProperty('buckets', $value); } /** - * @param int $shardBuckets + * @param int $value * @return static */ - public function shardBuckets(int $shardBuckets): static + public function shardBuckets(int $value): static { - return $this->addProperty('shard_buckets', $shardBuckets); + return $this->addProperty('shard_buckets', $value); } } diff --git a/src/DSL/Aggs/Metric.php b/src/DSL/Aggs/Metric.php index f7af4f0..e86c25f 100644 --- a/src/DSL/Aggs/Metric.php +++ b/src/DSL/Aggs/Metric.php @@ -21,7 +21,7 @@ trait Metric * @param mixed $params * @return static */ - public function avg($params) + public function avg($params): static { return $this->node(Avg::create(is_string($params) ? ['field' => $params] : $params)); } @@ -32,7 +32,7 @@ public function avg($params) * @param mixed $params * @return static */ - public function sum($params) + public function sum($params): static { return $this->node(Sum::create(is_string($params) ? ['field' => $params] : $params)); } @@ -43,7 +43,7 @@ public function sum($params) * @param mixed $params * @return static */ - public function min($params) + public function min($params): static { return $this->node(Min::create(is_string($params) ? ['field' => $params] : $params)); } @@ -54,7 +54,7 @@ public function min($params) * @param mixed $params * @return static */ - public function max($params) + public function max($params): static { return $this->node(Max::create(is_string($params) ? ['field' => $params] : $params)); } @@ -65,7 +65,7 @@ public function max($params) * @param mixed $params * @return static */ - public function cardinality($params) + public function cardinality($params): static { return $this->node(Cardinality::create(is_string($params) ? ['field' => $params] : $params)); } @@ -76,7 +76,7 @@ public function cardinality($params) * @param mixed $params * @return static */ - public function valueCount($params) + public function valueCount($params): static { return $this->node(ValueCount::create(is_string($params) ? ['field' => $params] : $params)); } @@ -87,7 +87,7 @@ public function valueCount($params) * @param mixed $params * @return static */ - public function stats($params) + public function stats($params): static { return $this->node(Stats::create(is_string($params) ? ['field' => $params] : $params)); } @@ -98,7 +98,7 @@ public function stats($params) * @param mixed $params * @return static */ - public function extendedStats($params) + public function extendedStats($params): static { return $this->node(ExtendedStats::create(is_string($params) ? ['field' => $params] : $params)); } diff --git a/src/DSL/Aggs/Metric/Avg.php b/src/DSL/Aggs/Metric/Avg.php index 485c956..9e1ae08 100644 --- a/src/DSL/Aggs/Metric/Avg.php +++ b/src/DSL/Aggs/Metric/Avg.php @@ -16,22 +16,22 @@ class Avg extends Node /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Metric/Cardinality.php b/src/DSL/Aggs/Metric/Cardinality.php index dacea20..46d5337 100644 --- a/src/DSL/Aggs/Metric/Cardinality.php +++ b/src/DSL/Aggs/Metric/Cardinality.php @@ -16,33 +16,33 @@ class Cardinality extends Node /** * Controls the precision of the count. * - * @param int $threshold + * @param int $value * @return static */ - public function precisionThreshold(int $threshold): static + public function precisionThreshold(int $value): static { - return $this->addProperty('precision_threshold', $threshold); + return $this->addProperty('precision_threshold', $value); } /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Metric/ExtendedStats.php b/src/DSL/Aggs/Metric/ExtendedStats.php index 4a01725..57fb326 100644 --- a/src/DSL/Aggs/Metric/ExtendedStats.php +++ b/src/DSL/Aggs/Metric/ExtendedStats.php @@ -16,33 +16,33 @@ class ExtendedStats extends Node /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } /** * Number of standard deviations above/below the mean to display. * - * @param int $sigma + * @param int $value * @return static */ - public function sigma(int $sigma): static + public function sigma(int $value): static { - return $this->addProperty('sigma', $sigma); + return $this->addProperty('sigma', $value); } } diff --git a/src/DSL/Aggs/Metric/Max.php b/src/DSL/Aggs/Metric/Max.php index 11775a9..4393603 100644 --- a/src/DSL/Aggs/Metric/Max.php +++ b/src/DSL/Aggs/Metric/Max.php @@ -16,22 +16,22 @@ class Max extends Node /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Metric/Min.php b/src/DSL/Aggs/Metric/Min.php index 94bf2d6..5f3121d 100644 --- a/src/DSL/Aggs/Metric/Min.php +++ b/src/DSL/Aggs/Metric/Min.php @@ -16,22 +16,22 @@ class Min extends Node /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Metric/Stats.php b/src/DSL/Aggs/Metric/Stats.php index 1903766..3467257 100644 --- a/src/DSL/Aggs/Metric/Stats.php +++ b/src/DSL/Aggs/Metric/Stats.php @@ -16,22 +16,22 @@ class Stats extends Node /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Metric/Sum.php b/src/DSL/Aggs/Metric/Sum.php index c59dd63..063c905 100644 --- a/src/DSL/Aggs/Metric/Sum.php +++ b/src/DSL/Aggs/Metric/Sum.php @@ -16,22 +16,22 @@ class Sum extends Node /** * The value to use when the field is missing. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Metric/ValueCount.php b/src/DSL/Aggs/Metric/ValueCount.php index 684e837..055fa7e 100644 --- a/src/DSL/Aggs/Metric/ValueCount.php +++ b/src/DSL/Aggs/Metric/ValueCount.php @@ -16,11 +16,11 @@ class ValueCount extends Node /** * The script to use for the aggregation. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } } diff --git a/src/DSL/Aggs/Pipeline.php b/src/DSL/Aggs/Pipeline.php index 3be32cf..d3ea21c 100644 --- a/src/DSL/Aggs/Pipeline.php +++ b/src/DSL/Aggs/Pipeline.php @@ -21,7 +21,7 @@ trait Pipeline * @param mixed $params * @return static */ - public function avgBucket($params) + public function avgBucket($params): static { return $this->node(AvgBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -32,7 +32,7 @@ public function avgBucket($params) * @param mixed $params * @return static */ - public function sumBucket($params) + public function sumBucket($params): static { return $this->node(SumBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -43,7 +43,7 @@ public function sumBucket($params) * @param mixed $params * @return static */ - public function maxBucket($params) + public function maxBucket($params): static { return $this->node(MaxBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -54,7 +54,7 @@ public function maxBucket($params) * @param mixed $params * @return static */ - public function minBucket($params) + public function minBucket($params): static { return $this->node(MinBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -65,7 +65,7 @@ public function minBucket($params) * @param mixed $params * @return static */ - public function statsBucket($params) + public function statsBucket($params): static { return $this->node(StatsBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -76,7 +76,7 @@ public function statsBucket($params) * @param mixed $params * @return static */ - public function cumulativeSum($params) + public function cumulativeSum($params): static { return $this->node(CumulativeSum::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -87,7 +87,7 @@ public function cumulativeSum($params) * @param mixed $params * @return static */ - public function derivative($params) + public function derivative($params): static { return $this->node(Derivative::create(is_string($params) ? ['buckets_path' => $params] : $params)); } @@ -98,7 +98,7 @@ public function derivative($params) * @param mixed $params * @return static */ - public function bucketScript($params) + public function bucketScript($params): static { return $this->node(BucketScript::create(is_string($params) ? ['buckets_path' => $params] : $params)); } diff --git a/src/DSL/Aggs/Pipeline/AvgBucket.php b/src/DSL/Aggs/Pipeline/AvgBucket.php index 8e626eb..dabce8a 100644 --- a/src/DSL/Aggs/Pipeline/AvgBucket.php +++ b/src/DSL/Aggs/Pipeline/AvgBucket.php @@ -16,44 +16,44 @@ class AvgBucket extends Node /** * Path to the buckets to average. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * The value to use when the aggregation is missing a value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Pipeline/BucketScript.php b/src/DSL/Aggs/Pipeline/BucketScript.php index 7da6e36..98eef0b 100644 --- a/src/DSL/Aggs/Pipeline/BucketScript.php +++ b/src/DSL/Aggs/Pipeline/BucketScript.php @@ -16,44 +16,44 @@ class BucketScript extends Node /** * Path to the buckets to use in the script. * - * @param mixed $path + * @param mixed $value * @return static */ - public function bucketsPath($path): static + public function bucketsPath($value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * The script to execute for each bucket. * - * @param string|callable $script + * @param string|callable $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', $script); + return $this->addProperty('script', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } } diff --git a/src/DSL/Aggs/Pipeline/CumulativeSum.php b/src/DSL/Aggs/Pipeline/CumulativeSum.php index 0da75e1..3287ab2 100644 --- a/src/DSL/Aggs/Pipeline/CumulativeSum.php +++ b/src/DSL/Aggs/Pipeline/CumulativeSum.php @@ -16,22 +16,22 @@ class CumulativeSum extends Node /** * Path to the buckets to cumulatively sum. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } } diff --git a/src/DSL/Aggs/Pipeline/Derivative.php b/src/DSL/Aggs/Pipeline/Derivative.php index d8305a3..1f32506 100644 --- a/src/DSL/Aggs/Pipeline/Derivative.php +++ b/src/DSL/Aggs/Pipeline/Derivative.php @@ -16,44 +16,44 @@ class Derivative extends Node /** * Path to the buckets to differentiate. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * The unit for the derivative when the histogram uses time units. * - * @param string $unit + * @param string $value * @return static */ - public function unit(string $unit): static + public function unit(string $value): static { - return $this->addProperty('unit', $unit); + return $this->addProperty('unit', $value); } } diff --git a/src/DSL/Aggs/Pipeline/MaxBucket.php b/src/DSL/Aggs/Pipeline/MaxBucket.php index faa7ff5..e762188 100644 --- a/src/DSL/Aggs/Pipeline/MaxBucket.php +++ b/src/DSL/Aggs/Pipeline/MaxBucket.php @@ -16,44 +16,44 @@ class MaxBucket extends Node /** * Path to the buckets to find the maximum. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * The value to use when the aggregation is missing a value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Pipeline/MinBucket.php b/src/DSL/Aggs/Pipeline/MinBucket.php index 12b0810..dcb4634 100644 --- a/src/DSL/Aggs/Pipeline/MinBucket.php +++ b/src/DSL/Aggs/Pipeline/MinBucket.php @@ -16,44 +16,44 @@ class MinBucket extends Node /** * Path to the buckets to find the minimum. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * The value to use when the aggregation is missing a value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Pipeline/StatsBucket.php b/src/DSL/Aggs/Pipeline/StatsBucket.php index 45af167..93649b1 100644 --- a/src/DSL/Aggs/Pipeline/StatsBucket.php +++ b/src/DSL/Aggs/Pipeline/StatsBucket.php @@ -16,44 +16,44 @@ class StatsBucket extends Node /** * Path to the buckets to compute stats on. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * The value to use when the aggregation is missing a value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Aggs/Pipeline/SumBucket.php b/src/DSL/Aggs/Pipeline/SumBucket.php index dcd5d8d..74dc3c2 100644 --- a/src/DSL/Aggs/Pipeline/SumBucket.php +++ b/src/DSL/Aggs/Pipeline/SumBucket.php @@ -16,44 +16,44 @@ class SumBucket extends Node /** * Path to the buckets to sum. * - * @param string $path + * @param string $value * @return static */ - public function bucketsPath(string $path): static + public function bucketsPath(string $value): static { - return $this->addProperty('buckets_path', $path); + return $this->addProperty('buckets_path', $value); } /** * Policy to apply when gaps are found in the data. * - * @param string $policy + * @param string $value * @return static */ - public function gapPolicy(string $policy): static + public function gapPolicy(string $value): static { - return $this->addProperty('gap_policy', $policy); + return $this->addProperty('gap_policy', $value); } /** * Format for the output value. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** * The value to use when the aggregation is missing a value. * - * @param mixed $missing + * @param mixed $value * @return static */ - public function missing($missing): static + public function missing($value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Node.php b/src/DSL/Node.php index 5aa823f..13db4cb 100644 --- a/src/DSL/Node.php +++ b/src/DSL/Node.php @@ -182,16 +182,6 @@ protected function multi(bool $multi): static return $this; } - /** - * Whether the node supports multiple clauses. - * - * @return bool - */ - protected function isMulti(): bool - { - return $this->_multi; - } - /** * Get the Elasticsearch type identifier. * @@ -334,11 +324,11 @@ public function __toString(): string * Floating point number used to decrease or increase * the relevance scores of a query. Defaults to 1.0. * - * @param float $boost + * @param float $value * @return static */ - public function boost($boost): static + public function boost($value): static { - return $this->addProperty('boost', $boost); + return $this->addProperty('boost', $value); } } diff --git a/src/DSL/Param.php b/src/DSL/Param.php index ba982e3..f5efce6 100644 --- a/src/DSL/Param.php +++ b/src/DSL/Param.php @@ -14,7 +14,7 @@ trait Param * * @var array */ - protected $_params = []; + protected array $_params = []; /** * Check if a search request parameter has been set. @@ -22,7 +22,7 @@ trait Param * @param string $key * @return bool */ - public function hasParam($key) + public function hasParam($key): bool { return array_key_exists($key, $this->_params); } @@ -34,7 +34,7 @@ public function hasParam($key) * @param int $size * @return $this */ - public function size($size) + public function size($size): static { $this->_params['size'] = $size; return $this; @@ -47,7 +47,7 @@ public function size($size) * @param int $from * @return $this */ - public function from($from) + public function from($from): static { $this->_params['from'] = $from; return $this; @@ -60,7 +60,7 @@ public function from($from) * @param string $timeout * @return $this */ - public function timeout($timeout) + public function timeout($timeout): static { $this->_params['timeout'] = $timeout; return $this; @@ -73,7 +73,7 @@ public function timeout($timeout) * @param float $minScore * @return $this */ - public function minScore($minScore) + public function minScore($minScore): static { $this->_params['min_score'] = $minScore; return $this; @@ -86,7 +86,7 @@ public function minScore($minScore) * @param int $terminateAfter * @return $this */ - public function terminateAfter($terminateAfter) + public function terminateAfter($terminateAfter): static { $this->_params['terminate_after'] = $terminateAfter; return $this; @@ -99,7 +99,7 @@ public function terminateAfter($terminateAfter) * @param bool $explain * @return $this */ - public function explain($explain) + public function explain($explain): static { $this->_params['explain'] = $explain; return $this; @@ -112,7 +112,7 @@ public function explain($explain) * @param bool $version * @return $this */ - public function version($version) + public function version($version): static { $this->_params['version'] = $version; return $this; @@ -124,7 +124,7 @@ public function version($version) * @param bool $profile * @return $this */ - public function profile($profile) + public function profile($profile): static { $this->_params['profile'] = $profile; return $this; @@ -137,7 +137,7 @@ public function profile($profile) * @param bool|int $trackTotalHits * @return $this */ - public function trackTotalHits($trackTotalHits) + public function trackTotalHits($trackTotalHits): static { $this->_params['track_total_hits'] = $trackTotalHits; return $this; @@ -150,7 +150,7 @@ public function trackTotalHits($trackTotalHits) * @param bool $seqNoPrimaryTerm * @return $this */ - public function seqNoPrimaryTerm($seqNoPrimaryTerm) + public function seqNoPrimaryTerm($seqNoPrimaryTerm): static { $this->_params['seq_no_primary_term'] = $seqNoPrimaryTerm; return $this; @@ -167,7 +167,7 @@ public function seqNoPrimaryTerm($seqNoPrimaryTerm) * @param string|null $order * @return $this */ - public function sort($field, $order = null) + public function sort($field, $order = null): static { if ($order !== null) { $this->_params['sort'][] = [$field => $order]; @@ -186,7 +186,7 @@ public function sort($field, $order = null) * @param array|string $source * @return $this */ - public function source($source) + public function source($source): static { $this->_params['_source'] = $source; return $this; @@ -198,7 +198,7 @@ public function source($source) * @param array $searchAfter * @return $this */ - public function searchAfter($searchAfter) + public function searchAfter($searchAfter): static { $this->_params['search_after'] = $searchAfter; return $this; @@ -211,7 +211,7 @@ public function searchAfter($searchAfter) * @param array $storedFields * @return $this */ - public function storedFields($storedFields) + public function storedFields($storedFields): static { $this->_params['stored_fields'] = $storedFields; return $this; @@ -223,7 +223,7 @@ public function storedFields($storedFields) * @param array $docvalueFields * @return $this */ - public function docvalueFields($docvalueFields) + public function docvalueFields($docvalueFields): static { $this->_params['docvalue_fields'] = $docvalueFields; return $this; @@ -236,7 +236,7 @@ public function docvalueFields($docvalueFields) * @param array $indicesBoost * @return $this */ - public function indicesBoost($indicesBoost) + public function indicesBoost($indicesBoost): static { $this->_params['indices_boost'] = [$indicesBoost]; return $this; @@ -249,7 +249,7 @@ public function indicesBoost($indicesBoost) * @param bool $trackScores * @return $this */ - public function trackScores($trackScores) + public function trackScores($trackScores): static { $this->_params['track_scores'] = $trackScores; return $this; @@ -262,7 +262,7 @@ public function trackScores($trackScores) * @param array $fields * @return $this */ - public function fields($fields) + public function fields($fields): static { $this->_params['fields'] = $fields; return $this; @@ -274,7 +274,7 @@ public function fields($fields) * @param array $pit * @return $this */ - public function pit($pit) + public function pit($pit): static { $this->_params['pit'] = $pit; return $this; @@ -287,7 +287,7 @@ public function pit($pit) * @param mixed $filter * @return $this */ - public function postFilter($filter) + public function postFilter($filter): static { $this->_params['post_filter'] = Query::create($filter); return $this; @@ -299,7 +299,7 @@ public function postFilter($filter) * @param mixed $collapse * @return $this */ - public function collapse($collapse) + public function collapse($collapse): static { $this->_params['collapse'] = Params\Collapse::create($collapse); return $this; @@ -311,7 +311,7 @@ public function collapse($collapse) * @param mixed $rescore * @return $this */ - public function rescore($rescore) + public function rescore($rescore): static { $this->_params['rescore'] = Params\Rescore::create($rescore); return $this; @@ -324,7 +324,7 @@ public function rescore($rescore) * @param mixed $highlight * @return $this */ - public function highlight($highlight) + public function highlight($highlight): static { $new = Params\Highlight::create($highlight); @@ -357,7 +357,7 @@ public function highlight($highlight) * @param mixed $suggest * @return $this */ - public function suggest($suggest) + public function suggest($suggest): static { $this->_params['suggest'] = Params\Suggest::create($suggest); return $this; @@ -369,7 +369,7 @@ public function suggest($suggest) * @param array $scriptFields * @return $this */ - public function scriptFields($scriptFields) + public function scriptFields($scriptFields): static { $this->_params['script_fields'] = $scriptFields; return $this; @@ -381,7 +381,7 @@ public function scriptFields($scriptFields) * @param array $runtimeMappings * @return $this */ - public function runtimeMappings($runtimeMappings) + public function runtimeMappings($runtimeMappings): static { $this->_params['runtime_mappings'] = $runtimeMappings; return $this; @@ -399,7 +399,7 @@ public function runtimeMappings($runtimeMappings) * @param array|null $queryVector * @return $this */ - public function knn($knn, $queryVector = null) + public function knn($knn, $queryVector = null): static { if (is_string($knn) && $queryVector !== null) { $node = (new Params\Knn())->field($knn)->queryVector($queryVector); diff --git a/src/DSL/Params/Collapse.php b/src/DSL/Params/Collapse.php index a2fd335..8f242da 100644 --- a/src/DSL/Params/Collapse.php +++ b/src/DSL/Params/Collapse.php @@ -48,11 +48,11 @@ public function innerHits(string $name, $hits = null): static /** * Maximum number of concurrent group searches. * - * @param int $max + * @param int $value * @return static */ - public function maxConcurrentGroupSearches(int $max): static + public function maxConcurrentGroupSearches(int $value): static { - return $this->addProperty('max_concurrent_group_searches', $max); + return $this->addProperty('max_concurrent_group_searches', $value); } } diff --git a/src/DSL/Params/Highlight.php b/src/DSL/Params/Highlight.php index 460f116..57e8180 100644 --- a/src/DSL/Params/Highlight.php +++ b/src/DSL/Params/Highlight.php @@ -52,144 +52,144 @@ public function field($field, array $settings = []): static /** * Opening HTML tags for highlighted snippets. * - * @param array $tags + * @param array $value * @return static */ - public function preTags(array $tags): static + public function preTags(array $value): static { - return $this->addProperty('pre_tags', $tags); + return $this->addProperty('pre_tags', $value); } /** * Closing HTML tags for highlighted snippets. * - * @param array $tags + * @param array $value * @return static */ - public function postTags(array $tags): static + public function postTags(array $value): static { - return $this->addProperty('post_tags', $tags); + return $this->addProperty('post_tags', $value); } /** * Size of a highlighted fragment. Defaults to 100. * - * @param int $size + * @param int $value * @return static */ - public function fragmentSize(int $size): static + public function fragmentSize(int $value): static { - return $this->addProperty('fragment_size', $size); + return $this->addProperty('fragment_size', $value); } /** * Maximum number of fragments to return. * - * @param int $num + * @param int $value * @return static */ - public function numberOfFragments(int $num): static + public function numberOfFragments(int $value): static { - return $this->addProperty('number_of_fragments', $num); + return $this->addProperty('number_of_fragments', $value); } /** * Highlighter encoder: html or default. * - * @param string $encoder + * @param string $value * @return static */ - public function encoder(string $encoder): static + public function encoder(string $value): static { - return $this->addProperty('encoder', $encoder); + return $this->addProperty('encoder', $value); } /** * Sort order for highlighted fragments: score or none. * - * @param string $order + * @param string $value * @return static */ - public function order(string $order): static + public function order(string $value): static { - return $this->addProperty('order', $order); + return $this->addProperty('order', $value); } /** * Highlight against a query other than the search query. * - * @param mixed $query + * @param mixed $value * @return static */ - public function highlightQuery($query): static + public function highlightQuery($value): static { - return $this->addProperty('highlight_query', Query::create($query)); + return $this->addProperty('highlight_query', Query::create($value)); } /** * Highlighter type: unified, plain, or fvh. * - * @param string $type + * @param string $value * @return static */ - public function type(string $type): static + public function type(string $value): static { - return $this->addProperty('type', $type); + return $this->addProperty('type', $value); } /** * Boundary scanner: chars, sentence, or word. * - * @param string $scanner + * @param string $value * @return static */ - public function boundaryScanner(string $scanner): static + public function boundaryScanner(string $value): static { - return $this->addProperty('boundary_scanner', $scanner); + return $this->addProperty('boundary_scanner', $value); } /** * Locale for the boundary scanner. * - * @param string $locale + * @param string $value * @return static */ - public function boundaryScannerLocale(string $locale): static + public function boundaryScannerLocale(string $value): static { - return $this->addProperty('boundary_scanner_locale', $locale); + return $this->addProperty('boundary_scanner_locale', $value); } /** * Maximum distance for the boundary scanner. * - * @param int $max + * @param int $value * @return static */ - public function boundaryMaxScan(int $max): static + public function boundaryMaxScan(int $value): static { - return $this->addProperty('boundary_max_scan', $max); + return $this->addProperty('boundary_max_scan', $value); } /** * Size of snippet when no matching fragment is found. * - * @param int $size + * @param int $value * @return static */ - public function noMatchSize(int $size): static + public function noMatchSize(int $value): static { - return $this->addProperty('no_match_size', $size); + return $this->addProperty('no_match_size', $value); } /** * Fragmenter: simple or span (plain highlighter only). * - * @param string $fragmenter + * @param string $value * @return static */ - public function fragmenter(string $fragmenter): static + public function fragmenter(string $value): static { - return $this->addProperty('fragmenter', $fragmenter); + return $this->addProperty('fragmenter', $value); } public function toArray() diff --git a/src/DSL/Params/Knn.php b/src/DSL/Params/Knn.php index 358a382..c033394 100644 --- a/src/DSL/Params/Knn.php +++ b/src/DSL/Params/Knn.php @@ -20,93 +20,82 @@ class Knn extends Node /** * The query vector to search for. * - * @param array $vector + * @param array $value * @return static */ - public function queryVector(array $vector): static + public function queryVector(array $value): static { - return $this->addProperty('query_vector', $vector); + return $this->addProperty('query_vector', $value); } /** * Number of nearest neighbors to return as top hits. * Defaults to the search request's size. * - * @param int $k + * @param int $value * @return static */ - public function k(int $k): static + public function k(int $value): static { - return $this->addProperty('k', $k); + return $this->addProperty('k', $value); } /** * Number of candidates to evaluate per shard. * Defaults to max(k * 4, 50). * - * @param int $num + * @param int $value * @return static */ - public function numCandidates(int $num): static + public function numCandidates(int $value): static { - return $this->addProperty('num_candidates', $num); + return $this->addProperty('num_candidates', $value); } /** * Minimum similarity threshold for a vector to be * considered a match. * - * @param float $similarity + * @param float $value * @return static */ - public function similarity(float $similarity): static + public function similarity(float $value): static { - return $this->addProperty('similarity', $similarity); - } - - /** - * Boost value for the kNN score. - * - * @param float $boost - * @return static - */ - public function boost($boost): static - { - return $this->addProperty('boost', $boost); + return $this->addProperty('similarity', $value); } /** * Pre-filter applied during kNN search. Accepts a closure, * array, or Query object. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addProperty('filter', Query::create($filter)); + return $this->addProperty('filter', Query::create($value)); } /** * Inner hits configuration for nested kNN search. * - * @param mixed $innerHits + * @param mixed $value * @return static */ - public function innerHits($innerHits): static + public function innerHits($value): static { - return $this->addProperty('inner_hits', $innerHits); + return $this->addProperty('inner_hits', $value); } /** * Rescore vector configuration for quantized vector rescoring. * - * @param array $rescoreVector + * @param array $value * @return static */ - public function rescoreVector(array $rescoreVector): static + public function rescoreVector(array $value): static { - return $this->addProperty('rescore_vector', $rescoreVector); + return $this->addProperty('rescore_vector', $value); } public function toArray() diff --git a/src/DSL/Params/Rescore.php b/src/DSL/Params/Rescore.php index 733229c..632ea45 100644 --- a/src/DSL/Params/Rescore.php +++ b/src/DSL/Params/Rescore.php @@ -20,47 +20,47 @@ class Rescore extends Node /** * Number of documents to rescore per shard. * - * @param int $size + * @param int $value * @return static */ - public function windowSize(int $size): static + public function windowSize(int $value): static { - return $this->addProperty('window_size', $size); + return $this->addProperty('window_size', $value); } /** * The query to use for rescoring. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - $this->_properties['query']['rescore_query'] = Query::create($query); + $this->_properties['query']['rescore_query'] = Query::create($value); return $this; } /** * Weight of the rescore query. Defaults to 1.0. * - * @param float $weight + * @param float $value * @return static */ - public function rescoreQueryWeight(float $weight): static + public function rescoreQueryWeight(float $value): static { - $this->_properties['query']['rescore_query_weight'] = $weight; + $this->_properties['query']['rescore_query_weight'] = $value; return $this; } /** * Weight of the original query. Defaults to 1.0. * - * @param float $weight + * @param float $value * @return static */ - public function queryWeight(float $weight): static + public function queryWeight(float $value): static { - $this->_properties['query']['query_weight'] = $weight; + $this->_properties['query']['query_weight'] = $value; return $this; } @@ -68,12 +68,12 @@ public function queryWeight(float $weight): static * How scores are combined. Valid values: total, * multiply, max, avg. Defaults to total. * - * @param string $mode + * @param string $value * @return static */ - public function scoreMode(string $mode): static + public function scoreMode(string $value): static { - $this->_properties['query']['score_mode'] = $mode; + $this->_properties['query']['score_mode'] = $value; return $this; } diff --git a/src/DSL/Params/Suggest.php b/src/DSL/Params/Suggest.php index 0d53ef2..1b10c6e 100644 --- a/src/DSL/Params/Suggest.php +++ b/src/DSL/Params/Suggest.php @@ -20,7 +20,7 @@ class Suggest extends Node * * @param string $alias * @param string $field - * @param string|null $text + * @param ?string $text * @return static */ public function term(string $alias, string $field, ?string $text = null): static @@ -37,7 +37,7 @@ public function term(string $alias, string $field, ?string $text = null): static * * @param string $alias * @param string $field - * @param string|null $prefix + * @param ?string $prefix * @return static */ public function completion(string $alias, string $field, ?string $prefix = null): static @@ -54,7 +54,7 @@ public function completion(string $alias, string $field, ?string $prefix = null) * * @param string $alias * @param string $field - * @param string|null $text + * @param ?string $text * @return static */ public function phrase(string $alias, string $field, ?string $text = null): static diff --git a/src/DSL/Queries/Compound.php b/src/DSL/Queries/Compound.php index 79ad381..1b804ea 100644 --- a/src/DSL/Queries/Compound.php +++ b/src/DSL/Queries/Compound.php @@ -28,7 +28,7 @@ trait Compound * @param callable|Boolean|array $bool * @return $this */ - public function bool($bool) + public function bool($bool): static { if (is_array($bool)) { $boolean = new Boolean(); @@ -51,7 +51,7 @@ public function bool($bool) * @param callable|Boosting|array $boosting * @return $this */ - public function boosting($boosting) + public function boosting($boosting): static { if (is_array($boosting)) { $b = new Boosting(); @@ -74,7 +74,7 @@ public function boosting($boosting) * @param callable|ConstantScore|array $constantScore * @return $this */ - public function constantScore($constantScore) + public function constantScore($constantScore): static { if (is_array($constantScore)) { $cs = new ConstantScore(); @@ -96,7 +96,7 @@ public function constantScore($constantScore) * @param callable|DisjunctionMax|array $disMax * @return $this */ - public function disMax($disMax) + public function disMax($disMax): static { if (is_array($disMax)) { $dm = new DisjunctionMax(); @@ -118,7 +118,7 @@ public function disMax($disMax) * @param mixed $functionScore * @return $this */ - public function functionScore($functionScore) + public function functionScore($functionScore): static { return $this->addQuery(FunctionScore::create($functionScore)); } diff --git a/src/DSL/Queries/Compound/Boolean.php b/src/DSL/Queries/Compound/Boolean.php index aa8a71f..a1bae57 100644 --- a/src/DSL/Queries/Compound/Boolean.php +++ b/src/DSL/Queries/Compound/Boolean.php @@ -20,48 +20,48 @@ class Boolean extends Node * The clause (query) must appear in matching documents and will contribute to the score. * Supports multiple calls to incrementally build the bool query. * - * @param mixed $must + * @param mixed $value * @return static */ - public function must($must): static + public function must($value): static { - return $this->addClause('must', $must); + return $this->addClause('must', $value); } /** * The clause (query) should appear in the matching document. * Supports multiple calls to incrementally build the bool query. * - * @param mixed $should + * @param mixed $value * @return static */ - public function should($should): static + public function should($value): static { - return $this->addClause('should', $should); + return $this->addClause('should', $value); } /** * The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching. * Supports multiple calls to incrementally build the bool query. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addClause('filter', $filter); + return $this->addClause('filter', $value); } /** * The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned. * Supports multiple calls to incrementally build the bool query. * - * @param mixed $mustNot + * @param mixed $value * @return static */ - public function mustNot($mustNot): static + public function mustNot($value): static { - return $this->addClause('must_not', $mustNot); + return $this->addClause('must_not', $value); } /** @@ -71,11 +71,11 @@ public function mustNot($mustNot): static * * For other valid values, see the minimum_should_match parameter. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } } diff --git a/src/DSL/Queries/Compound/Boosting.php b/src/DSL/Queries/Compound/Boosting.php index c668cc5..679c041 100644 --- a/src/DSL/Queries/Compound/Boosting.php +++ b/src/DSL/Queries/Compound/Boosting.php @@ -17,33 +17,33 @@ class Boosting extends Node /** * Query you wish to run. Any returned documents must match this query. * - * @param mixed $positive + * @param mixed $value * @return static */ - public function positive($positive): static + public function positive($value): static { - return $this->addProperty('positive', Query::create($positive)); + return $this->addProperty('positive', Query::create($value)); } /** * Query used to decrease the relevance score of matching documents. * - * @param mixed $negative + * @param mixed $value * @return static */ - public function negative($negative): static + public function negative($value): static { - return $this->addProperty('negative', Query::create($negative)); + return $this->addProperty('negative', Query::create($value)); } /** * Floating point number between 0 and 1.0 used to decrease the relevance scores of documents matching the negative query. * - * @param float $negativeBoost + * @param float $value * @return static */ - public function negativeBoost(float $negativeBoost): static + public function negativeBoost(float $value): static { - return $this->addProperty('negative_boost', $negativeBoost); + return $this->addProperty('negative_boost', $value); } } diff --git a/src/DSL/Queries/Compound/ConstantScore.php b/src/DSL/Queries/Compound/ConstantScore.php index 80ba278..1a80442 100644 --- a/src/DSL/Queries/Compound/ConstantScore.php +++ b/src/DSL/Queries/Compound/ConstantScore.php @@ -17,11 +17,11 @@ class ConstantScore extends Node /** * Filter query you wish to run. Any returned documents must match this query. * - * @param mixed $query + * @param mixed $value * @return static */ - public function filter($query): static + public function filter($value): static { - return $this->addProperty('filter', Query::create($query)); + return $this->addProperty('filter', Query::create($value)); } } diff --git a/src/DSL/Queries/Compound/DisjunctionMax.php b/src/DSL/Queries/Compound/DisjunctionMax.php index 5b63895..ce6a5a7 100644 --- a/src/DSL/Queries/Compound/DisjunctionMax.php +++ b/src/DSL/Queries/Compound/DisjunctionMax.php @@ -20,22 +20,22 @@ class DisjunctionMax extends Node * Contains one or more query clauses. Returned documents must match one or more of these queries. If a document matches multiple queries, Elasticsearch uses the highest relevance score. * Supports multiple calls to incrementally build. * - * @param mixed $queries + * @param mixed $value * @return static */ - public function queries($queries): static + public function queries($value): static { - return $this->addClause('queries', $queries); + return $this->addClause('queries', $value); } /** * Floating point number between 0 and 1.0 used to increase the relevance scores of documents matching multiple query clauses. Defaults to 0.0. * - * @param float $tieBreaker + * @param float $value * @return static */ - public function tieBreaker(float $tieBreaker): static + public function tieBreaker(float $value): static { - return $this->addProperty('tie_breaker', $tieBreaker); + return $this->addProperty('tie_breaker', $value); } } diff --git a/src/DSL/Queries/Compound/FunctionScore.php b/src/DSL/Queries/Compound/FunctionScore.php index ca16b3d..52338e6 100644 --- a/src/DSL/Queries/Compound/FunctionScore.php +++ b/src/DSL/Queries/Compound/FunctionScore.php @@ -19,79 +19,79 @@ class FunctionScore extends Node * Controls how the computed scores from multiple functions are combined. * Options: multiply (default), sum, avg, first, max, min. * - * @param string $scoreMode + * @param string $value * @return static */ - public function scoreMode(string $scoreMode): static + public function scoreMode(string $value): static { - return $this->addProperty('score_mode', $scoreMode); + return $this->addProperty('score_mode', $value); } /** * Defines how the newly computed function score is combined with the query score. * Options: multiply (default), replace, sum, avg, max, min. * - * @param string $boostMode + * @param string $value * @return static */ - public function boostMode(string $boostMode): static + public function boostMode(string $value): static { - return $this->addProperty('boost_mode', $boostMode); + return $this->addProperty('boost_mode', $value); } /** * Excludes documents that do not meet the specified score threshold. * - * @param float $minScore + * @param float $value * @return static */ - public function minScore(float $minScore): static + public function minScore(float $value): static { - return $this->addProperty('min_score', $minScore); + return $this->addProperty('min_score', $value); } /** * Restricts the new score to not exceed the specified limit. Defaults to FLT_MAX. * - * @param float $maxBoost + * @param float $value * @return static */ - public function maxBoost(float $maxBoost): static + public function maxBoost(float $value): static { - return $this->addProperty('max_boost', $maxBoost); + return $this->addProperty('max_boost', $value); } /** * The query to be scored. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - return $this->addProperty('query', Query::create($query)); + return $this->addProperty('query', Query::create($value)); } /** * Array of score functions to apply. * - * @param array $functions + * @param array $value * @return static */ - public function functions(array $functions): static + public function functions(array $value): static { - return $this->addProperty('functions', $functions); + return $this->addProperty('functions', $value); } /** * Appends a score function to the functions array. * - * @param mixed $function + * @param mixed $value * @return static */ - public function addFunction($function): static + public function addFunction($value): static { - return $this->addProperty('functions', Function_::create($function), true); + return $this->addProperty('functions', Function_::create($value), true); } /** diff --git a/src/DSL/Queries/Compound/Functions/Exp.php b/src/DSL/Queries/Compound/Functions/Exp.php index 2516317..adf6cc2 100644 --- a/src/DSL/Queries/Compound/Functions/Exp.php +++ b/src/DSL/Queries/Compound/Functions/Exp.php @@ -18,44 +18,44 @@ class Exp extends Node /** * The point of origin used for calculating distance. Must be a number for numeric fields, date for date fields, and geo point for geo fields. * - * @param mixed $origin + * @param mixed $value * @return static */ - public function origin($origin): static + public function origin($value): static { - return $this->addProperty('origin', $origin); + return $this->addProperty('origin', $value); } /** * Defines the distance from origin + offset at which the computed score will equal the decay parameter. * - * @param mixed $scale + * @param mixed $value * @return static */ - public function scale($scale): static + public function scale($value): static { - return $this->addProperty('scale', $scale); + return $this->addProperty('scale', $value); } /** * If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. * - * @param mixed $offset + * @param mixed $value * @return static */ - public function offset($offset): static + public function offset($value): static { - return $this->addProperty('offset', $offset); + return $this->addProperty('offset', $value); } /** * Defines how documents are scored at the distance given at scale. Defaults to 0.5. * - * @param float $decay + * @param float $value * @return static */ - public function decay(float $decay): static + public function decay(float $value): static { - return $this->addProperty('decay', $decay); + return $this->addProperty('decay', $value); } } diff --git a/src/DSL/Queries/Compound/Functions/FieldValueFactor.php b/src/DSL/Queries/Compound/Functions/FieldValueFactor.php index 667455e..8e3b945 100644 --- a/src/DSL/Queries/Compound/Functions/FieldValueFactor.php +++ b/src/DSL/Queries/Compound/Functions/FieldValueFactor.php @@ -13,33 +13,33 @@ class FieldValueFactor extends Node /** * Optional factor to multiply the field value with, defaults to 1. * - * @param float $factor + * @param float $value * @return static */ - public function factor(float $factor): static + public function factor(float $value): static { - return $this->addProperty('factor', $factor); + return $this->addProperty('factor', $value); } /** * Modifier to apply to the field value, can be one of: none, log, log1p, log2p, ln, ln1p, ln2p, square, sqrt, or reciprocal. Defaults to none. * - * @param string $modifier + * @param string $value * @return static */ - public function modifier(string $modifier): static + public function modifier(string $value): static { - return $this->addProperty('modifier', $modifier); + return $this->addProperty('modifier', $value); } /** * Value used if the document doesn’t have that field. The modifier and factor are still applied to it as though it were read from the document. * - * @param string|int|float|bool $missing + * @param string|int|float|bool $value * @return static */ - public function missing(string|int|float|bool $missing): static + public function missing(string|int|float|bool $value): static { - return $this->addProperty('missing', $missing); + return $this->addProperty('missing', $value); } } diff --git a/src/DSL/Queries/Compound/Functions/Function_.php b/src/DSL/Queries/Compound/Functions/Function_.php index 186e1d1..bb203fa 100644 --- a/src/DSL/Queries/Compound/Functions/Function_.php +++ b/src/DSL/Queries/Compound/Functions/Function_.php @@ -18,57 +18,57 @@ class Function_ extends Node /** * A filtering query that restricts the score function to matching documents only. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addProperty('filter', Query::create($filter)); + return $this->addProperty('filter', Query::create($value)); } /** * Multiplies the score by the provided weight value. * - * @param float $weight + * @param float $value * @return static */ - public function weight(float $weight): static + public function weight(float $value): static { - return $this->addProperty('weight', $weight); + return $this->addProperty('weight', $value); } /** * Generates uniformly distributed random scores from 0 up to but not including 1. * - * @param mixed $randomScore + * @param mixed $value * @return static */ - public function randomScore($randomScore = null): static + public function randomScore($value = null): static { - return $this->addProperty('random_score', RandomScore::create($randomScore)); + return $this->addProperty('random_score', RandomScore::create($value)); } /** * Wraps another query and customizes the scoring using a script. * - * @param mixed $scriptScore + * @param mixed $value * @return static */ - public function scriptScore($scriptScore): static + public function scriptScore($value): static { - return $this->addProperty('script_score', ScriptScore::create($scriptScore)); + return $this->addProperty('script_score', ScriptScore::create($value)); } /** * Sets the script for script_score using a Script object or closure. * - * @param mixed $script + * @param mixed $value * @return static */ - public function script($script): static + public function script($value): static { - $scriptScore = (new ScriptScore())->script($script); - return $this->addProperty('script_score', $scriptScore); + $valueScore = (new ScriptScore())->script($value); + return $this->addProperty('script_score', $valueScore); } /** diff --git a/src/DSL/Queries/Compound/Functions/Gauss.php b/src/DSL/Queries/Compound/Functions/Gauss.php index 4bdaa3b..d88dae3 100644 --- a/src/DSL/Queries/Compound/Functions/Gauss.php +++ b/src/DSL/Queries/Compound/Functions/Gauss.php @@ -18,44 +18,44 @@ class Gauss extends Node /** * The point of origin used for calculating distance. Must be a number for numeric fields, date for date fields, and geo point for geo fields. * - * @param mixed $origin + * @param mixed $value * @return static */ - public function origin($origin): static + public function origin($value): static { - return $this->addProperty('origin', $origin); + return $this->addProperty('origin', $value); } /** * Defines the distance from origin + offset at which the computed score will equal the decay parameter. * - * @param mixed $scale + * @param mixed $value * @return static */ - public function scale($scale): static + public function scale($value): static { - return $this->addProperty('scale', $scale); + return $this->addProperty('scale', $value); } /** * If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. * - * @param mixed $offset + * @param mixed $value * @return static */ - public function offset($offset): static + public function offset($value): static { - return $this->addProperty('offset', $offset); + return $this->addProperty('offset', $value); } /** * Defines how documents are scored at the distance given at scale. Defaults to 0.5. * - * @param float $decay + * @param float $value * @return static */ - public function decay(float $decay): static + public function decay(float $value): static { - return $this->addProperty('decay', $decay); + return $this->addProperty('decay', $value); } } diff --git a/src/DSL/Queries/Compound/Functions/Linear.php b/src/DSL/Queries/Compound/Functions/Linear.php index 65a6896..8d64265 100644 --- a/src/DSL/Queries/Compound/Functions/Linear.php +++ b/src/DSL/Queries/Compound/Functions/Linear.php @@ -18,44 +18,44 @@ class Linear extends Node /** * The point of origin used for calculating distance. Must be a number for numeric fields, date for date fields, and geo point for geo fields. * - * @param mixed $origin + * @param mixed $value * @return static */ - public function origin($origin): static + public function origin($value): static { - return $this->addProperty('origin', $origin); + return $this->addProperty('origin', $value); } /** * Defines the distance from origin + offset at which the computed score will equal the decay parameter. * - * @param mixed $scale + * @param mixed $value * @return static */ - public function scale($scale): static + public function scale($value): static { - return $this->addProperty('scale', $scale); + return $this->addProperty('scale', $value); } /** * If defined, the decay function will only compute for documents with a distance greater than this offset. Defaults to 0. * - * @param mixed $offset + * @param mixed $value * @return static */ - public function offset($offset): static + public function offset($value): static { - return $this->addProperty('offset', $offset); + return $this->addProperty('offset', $value); } /** * Defines how documents are scored at the distance given at scale. Defaults to 0.5. * - * @param float $decay + * @param float $value * @return static */ - public function decay(float $decay): static + public function decay(float $value): static { - return $this->addProperty('decay', $decay); + return $this->addProperty('decay', $value); } } diff --git a/src/DSL/Queries/Compound/Functions/RandomScore.php b/src/DSL/Queries/Compound/Functions/RandomScore.php index 25a6979..a7ae078 100644 --- a/src/DSL/Queries/Compound/Functions/RandomScore.php +++ b/src/DSL/Queries/Compound/Functions/RandomScore.php @@ -16,12 +16,12 @@ class RandomScore extends Node /** * Seed value for reproducible random scores. * - * @param mixed $seed + * @param mixed $value * @return static */ - public function seed($seed): static + public function seed($value): static { - return $this->addProperty('seed', $seed); + return $this->addProperty('seed', $value); } /** diff --git a/src/DSL/Queries/Compound/Functions/ScriptScore.php b/src/DSL/Queries/Compound/Functions/ScriptScore.php index fbeea46..e2c9f7f 100644 --- a/src/DSL/Queries/Compound/Functions/ScriptScore.php +++ b/src/DSL/Queries/Compound/Functions/ScriptScore.php @@ -17,11 +17,11 @@ class ScriptScore extends Node /** * The script used to compute the custom score. * - * @param mixed $script + * @param mixed $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', Script::create($script)); + return $this->addProperty('script', Script::create($value)); } } diff --git a/src/DSL/Queries/FullText.php b/src/DSL/Queries/FullText.php index 21b6808..298d46a 100644 --- a/src/DSL/Queries/FullText.php +++ b/src/DSL/Queries/FullText.php @@ -26,7 +26,7 @@ trait FullText * @param mixed $value * @return $this */ - public function intervals($field, $value = null) + public function intervals($field, $value = null): static { return $this->addQuery(Intervals::create($field, $value)); } @@ -40,7 +40,7 @@ public function intervals($field, $value = null) * @param callable|string|array $value * @return $this */ - public function match($field, $value = null) + public function match($field, $value = null): static { return $this->addQuery(Match_::create($field, $value)); } @@ -52,7 +52,7 @@ public function match($field, $value = null) * @param mixed $value * @return $this */ - public function matchPhrase($field, $value = null) + public function matchPhrase($field, $value = null): static { return $this->addQuery(MatchPhrase::create($field, $value)); } @@ -64,7 +64,7 @@ public function matchPhrase($field, $value = null) * @param mixed $value * @return $this */ - public function matchPhrasePrefix($field, $value = null) + public function matchPhrasePrefix($field, $value = null): static { return $this->addQuery(MatchPhrasePrefix::create($field, $value)); } @@ -76,7 +76,7 @@ public function matchPhrasePrefix($field, $value = null) * @param mixed $value * @return $this */ - public function matchBoolPrefix($field, $value = null) + public function matchBoolPrefix($field, $value = null): static { return $this->addQuery(MatchBoolPrefix::create($field, $value)); } @@ -89,7 +89,7 @@ public function matchBoolPrefix($field, $value = null) * @param callable|MultiMatch|array $value * @return $this */ - public function multiMatch($value) + public function multiMatch($value): static { return $this->addQuery(MultiMatch::create($value)); } @@ -100,7 +100,7 @@ public function multiMatch($value) * @param mixed $value * @return $this */ - public function combinedFields($value) + public function combinedFields($value): static { return $this->addQuery(CombinedFields::create($value)); } @@ -111,7 +111,7 @@ public function combinedFields($value) * @param mixed $queryString * @return $this */ - public function queryString($queryString) + public function queryString($queryString): static { return $this->addQuery(QueryString::create($queryString)); } @@ -122,7 +122,7 @@ public function queryString($queryString) * @param mixed $simpleQueryString * @return $this */ - public function simpleQueryString($simpleQueryString) + public function simpleQueryString($simpleQueryString): static { return $this->addQuery(SimpleQueryString::create($simpleQueryString)); } diff --git a/src/DSL/Queries/FullText/CombinedFields.php b/src/DSL/Queries/FullText/CombinedFields.php index d63c934..5b29314 100644 --- a/src/DSL/Queries/FullText/CombinedFields.php +++ b/src/DSL/Queries/FullText/CombinedFields.php @@ -21,12 +21,12 @@ class CombinedFields extends Node * The combined_fields query analyzes the provided text before performing * a search. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** @@ -34,48 +34,48 @@ public function query(string $query): static * patterns are allowed. Only text fields are supported, and they must all * have the same search analyzer. * - * @param array $fields + * @param array $value * @return static */ - public function fields(array $fields): static + public function fields(array $value): static { - return $this->addProperty('fields', $fields); + return $this->addProperty('fields', $value); } /** * If true, match phrase queries are automatically * created for multi-term synonyms. Defaults to true. * - * @param bool $autoGenerateSynonymsPhraseQuery + * @param bool $value * @return static */ - public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static + public function autoGenerateSynonymsPhraseQuery(bool $value): static { - return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); + return $this->addProperty('auto_generate_synonyms_phrase_query', $value); } /** * Boolean logic used to interpret text in the query * value. Valid values are: or (Default), and. * - * @param string $operator + * @param string $value * @return static */ - public function operator(string $operator): static + public function operator(string $value): static { - return $this->addProperty('operator', $operator); + return $this->addProperty('operator', $value); } /** * Minimum number of clauses that must match for a * document to be returned. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** @@ -83,11 +83,11 @@ public function minimumShouldMatch(int|string $minimumShouldMatch): static * analyzer removes all tokens, such as when using a stop filter. * Valid values are: none (Default), all. * - * @param string $zeroTermsQuery + * @param string $value * @return static */ - public function zeroTermsQuery(string $zeroTermsQuery): static + public function zeroTermsQuery(string $value): static { - return $this->addProperty('zero_terms_query', $zeroTermsQuery); + return $this->addProperty('zero_terms_query', $value); } } diff --git a/src/DSL/Queries/FullText/Intervals.php b/src/DSL/Queries/FullText/Intervals.php index 9b1b01d..af4edf0 100644 --- a/src/DSL/Queries/FullText/Intervals.php +++ b/src/DSL/Queries/FullText/Intervals.php @@ -18,7 +18,7 @@ class Intervals extends Node protected bool $_fieldKeyed = true; /** @var array */ - protected $_intervals = []; + protected array $_intervals = []; /** * Add a match rule that matches analyzed text. @@ -36,24 +36,24 @@ public function match($match): static * Add a prefix rule that matches terms that start with a specified set * of characters. * - * @param mixed $prefix + * @param mixed $value * @return static */ - public function prefix($prefix): static + public function prefix($value): static { - $this->_intervals[] = Intervals\Prefix::create($prefix); + $this->_intervals[] = Intervals\Prefix::create($value); return $this; } /** * Add a wildcard rule that matches terms using a wildcard pattern. * - * @param mixed $wildcard + * @param mixed $value * @return static */ - public function wildcard($wildcard): static + public function wildcard($value): static { - $this->_intervals[] = Intervals\Wildcard::create($wildcard); + $this->_intervals[] = Intervals\Wildcard::create($value); return $this; } @@ -61,24 +61,24 @@ public function wildcard($wildcard): static * Add a fuzzy rule that matches terms that are similar to the provided * term, within a defined edit distance. * - * @param mixed $fuzzy + * @param mixed $value * @return static */ - public function fuzzy($fuzzy): static + public function fuzzy($value): static { - $this->_intervals[] = Intervals\Fuzzy::create($fuzzy); + $this->_intervals[] = Intervals\Fuzzy::create($value); return $this; } /** * Add a range rule that matches terms that fall within a specified range. * - * @param mixed $range + * @param mixed $value * @return static */ - public function range($range): static + public function range($value): static { - $this->_intervals[] = Intervals\Range::create($range); + $this->_intervals[] = Intervals\Range::create($value); return $this; } @@ -86,12 +86,12 @@ public function range($range): static * Add an all_of rule that returns matches that span a combination of * other rules. * - * @param mixed $allOf + * @param mixed $value * @return static */ - public function allOf($allOf): static + public function allOf($value): static { - $this->_intervals[] = Intervals\AllOf::create($allOf); + $this->_intervals[] = Intervals\AllOf::create($value); return $this; } @@ -99,12 +99,12 @@ public function allOf($allOf): static * Add an any_of rule that returns intervals produced by any of its * sub-rules. * - * @param mixed $anyOf + * @param mixed $value * @return static */ - public function anyOf($anyOf): static + public function anyOf($value): static { - $this->_intervals[] = Intervals\AnyOf::create($anyOf); + $this->_intervals[] = Intervals\AnyOf::create($value); return $this; } diff --git a/src/DSL/Queries/FullText/Intervals/AllOf.php b/src/DSL/Queries/FullText/Intervals/AllOf.php index 777cf1b..030d0c9 100644 --- a/src/DSL/Queries/FullText/Intervals/AllOf.php +++ b/src/DSL/Queries/FullText/Intervals/AllOf.php @@ -18,33 +18,33 @@ class AllOf extends Node * An array of rules to combine. All rules * must produce a match in a document for the overall source to match. * - * @param mixed $intervals + * @param mixed $value * @return static */ - public function intervals($intervals): static + public function intervals($value): static { - $intervals = Intervals::create($intervals) + $value = Intervals::create($value) ->fieldKeyed(false) ->multi(true); - return $this->addProperty('intervals', $intervals); + return $this->addProperty('intervals', $value); } /** * Append an interval rule. Supports multiple calls to incrementally build. * - * @param mixed $interval + * @param mixed $value * @return static */ - public function addInterval($interval): static + public function addInterval($value): static { if (!isset($this->_properties['intervals'])) { $this->_properties['intervals'] = (new Intervals())->fieldKeyed(false)->multi(true); } $target = $this->_properties['intervals']; - if ($interval instanceof \Closure) { - $interval($target); - } elseif ($interval instanceof Node) { - $target->addQuery($interval); + if ($value instanceof \Closure) { + $value($target); + } elseif ($value instanceof Node) { + $target->addQuery($value); } return $this; } @@ -54,35 +54,35 @@ public function addInterval($interval): static * terms. Intervals produced by the rules further apart than this are not * considered matches. Defaults to -1 (no restriction). * - * @param int $maxGaps + * @param int $value * @return static */ - public function maxGaps(int $maxGaps): static + public function maxGaps(int $value): static { - return $this->addProperty('max_gaps', $maxGaps); + return $this->addProperty('max_gaps', $value); } /** * If true, intervals produced by the rules should * appear in the order in which they are specified. Defaults to false. * - * @param bool $ordered + * @param bool $value * @return static */ - public function ordered(bool $ordered): static + public function ordered(bool $value): static { - return $this->addProperty('ordered', $ordered); + return $this->addProperty('ordered', $value); } /** * Rule used to filter returned * intervals. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addProperty('filter', $filter); + return $this->addProperty('filter', $value); } } diff --git a/src/DSL/Queries/FullText/Intervals/AnyOf.php b/src/DSL/Queries/FullText/Intervals/AnyOf.php index 44bc2eb..77408ee 100644 --- a/src/DSL/Queries/FullText/Intervals/AnyOf.php +++ b/src/DSL/Queries/FullText/Intervals/AnyOf.php @@ -17,33 +17,33 @@ class AnyOf extends Node /** * An array of rules to match. * - * @param mixed $intervals + * @param mixed $value * @return static */ - public function intervals($intervals): static + public function intervals($value): static { - $intervals = Intervals::create($intervals) + $value = Intervals::create($value) ->fieldKeyed(false) ->multi(true); - return $this->addProperty('intervals', $intervals); + return $this->addProperty('intervals', $value); } /** * Append an interval rule. Supports multiple calls to incrementally build. * - * @param mixed $interval + * @param mixed $value * @return static */ - public function addInterval($interval): static + public function addInterval($value): static { if (!isset($this->_properties['intervals'])) { $this->_properties['intervals'] = (new Intervals())->fieldKeyed(false)->multi(true); } $target = $this->_properties['intervals']; - if ($interval instanceof \Closure) { - $interval($target); - } elseif ($interval instanceof Node) { - $target->addQuery($interval); + if ($value instanceof \Closure) { + $value($target); + } elseif ($value instanceof Node) { + $target->addQuery($value); } return $this; } @@ -52,11 +52,11 @@ public function addInterval($interval): static * Rule used to filter returned * intervals. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addProperty('filter', Filter::create($filter)); + return $this->addProperty('filter', Filter::create($value)); } } diff --git a/src/DSL/Queries/FullText/Intervals/Filter.php b/src/DSL/Queries/FullText/Intervals/Filter.php index a2ae9a0..5957a91 100644 --- a/src/DSL/Queries/FullText/Intervals/Filter.php +++ b/src/DSL/Queries/FullText/Intervals/Filter.php @@ -20,72 +20,72 @@ class Filter extends Node * Query used to return intervals that follow an * interval from the filter rule. * - * @param mixed $after + * @param mixed $value * @return static */ - public function after($after): static + public function after($value): static { - return $this->addProperty('after', Query::create($after)); + return $this->addProperty('after', Query::create($value)); } /** * Query used to return intervals that occur before * an interval from the filter rule. * - * @param mixed $before + * @param mixed $value * @return static */ - public function before($before): static + public function before($value): static { - return $this->addProperty('before', Query::create($before)); + return $this->addProperty('before', Query::create($value)); } /** * Query used to return intervals contained by an * interval from the filter rule. * - * @param mixed $containedBy + * @param mixed $value * @return static */ - public function containedBy($containedBy): static + public function containedBy($value): static { - return $this->addProperty('contained_by', Query::create($containedBy)); + return $this->addProperty('contained_by', Query::create($value)); } /** * Query used to return intervals that contain an * interval from the filter rule. * - * @param mixed $containing + * @param mixed $value * @return static */ - public function containing($containing): static + public function containing($value): static { - return $this->addProperty('containing', Query::create($containing)); + return $this->addProperty('containing', Query::create($value)); } /** * Query used to return intervals that do not * contain an interval from the filter rule. * - * @param mixed $notContaining + * @param mixed $value * @return static */ - public function notContaining($notContaining): static + public function notContaining($value): static { - return $this->addProperty('not_containing', Query::create($notContaining)); + return $this->addProperty('not_containing', Query::create($value)); } /** * Query used to return intervals that overlap * with an interval from the filter rule. * - * @param mixed $overlapping + * @param mixed $value * @return static */ - public function overlapping($overlapping): static + public function overlapping($value): static { - return $this->addProperty('overlapping', Query::create($overlapping)); + return $this->addProperty('overlapping', Query::create($value)); } /** @@ -93,35 +93,35 @@ public function overlapping($overlapping): static * This script must return a boolean value, true or false. The script can * use the interval variable with start, end, and gaps methods. * - * @param mixed $script + * @param mixed $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', Script::create($script)); + return $this->addProperty('script', Script::create($value)); } /** * Query used to return intervals that are not * contained by an interval from the filter rule. * - * @param mixed $notContainedBy + * @param mixed $value * @return static */ - public function notContainedBy($notContainedBy): static + public function notContainedBy($value): static { - return $this->addProperty('not_contained_by', Query::create($notContainedBy)); + return $this->addProperty('not_contained_by', Query::create($value)); } /** * Query used to return intervals that do not * overlap with an interval from the filter rule. * - * @param mixed $notOverlapping + * @param mixed $value * @return static */ - public function notOverlapping($notOverlapping): static + public function notOverlapping($value): static { - return $this->addProperty('not_overlapping', Query::create($notOverlapping)); + return $this->addProperty('not_overlapping', Query::create($value)); } } diff --git a/src/DSL/Queries/FullText/Intervals/Fuzzy.php b/src/DSL/Queries/FullText/Intervals/Fuzzy.php index 9638bf8..419849b 100644 --- a/src/DSL/Queries/FullText/Intervals/Fuzzy.php +++ b/src/DSL/Queries/FullText/Intervals/Fuzzy.php @@ -18,60 +18,60 @@ class Fuzzy extends Node /** * The term to match. * - * @param string $term + * @param string $value * @return static */ - public function term(string $term): static + public function term(string $value): static { - return $this->addProperty('term', $term); + return $this->addProperty('term', $value); } /** * Number of beginning characters left unchanged when * creating expansions. Defaults to 0. * - * @param int $prefixLength + * @param int $value * @return static */ - public function prefixLength(int $prefixLength): static + public function prefixLength(int $value): static { - return $this->addProperty('prefix_length', $prefixLength); + return $this->addProperty('prefix_length', $value); } /** * Indicates whether edits include transpositions of * two adjacent characters (ab -> ba). Defaults to true. * - * @param bool $transpositions + * @param bool $value * @return static */ - public function transpositions(bool $transpositions): static + public function transpositions(bool $value): static { - return $this->addProperty('transpositions', $transpositions); + return $this->addProperty('transpositions', $value); } /** * Maximum edit distance allowed for matching. * Defaults to auto. * - * @param int|string $fuzziness + * @param int|string $value * @return static */ - public function fuzziness(int|string $fuzziness): static + public function fuzziness(int|string $value): static { - return $this->addProperty('fuzziness', $fuzziness); + return $this->addProperty('fuzziness', $value); } /** * Analyzer used to normalize the term. Defaults to the * top-level field's analyzer. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** @@ -79,11 +79,11 @@ public function analyzer(string $analyzer): static * than the top-level field. The term is normalized using the search * analyzer from this field. * - * @param string $useField + * @param string $value * @return static */ - public function useField(string $useField): static + public function useField(string $value): static { - return $this->addProperty('use_field', $useField); + return $this->addProperty('use_field', $value); } } diff --git a/src/DSL/Queries/FullText/Intervals/Match_.php b/src/DSL/Queries/FullText/Intervals/Match_.php index 1cadd4a..89657c4 100644 --- a/src/DSL/Queries/FullText/Intervals/Match_.php +++ b/src/DSL/Queries/FullText/Intervals/Match_.php @@ -18,12 +18,12 @@ class Match_ extends Node /** * Text you wish to find in the provided field. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** @@ -32,47 +32,47 @@ public function query(string $query): static * Defaults to -1 (no restriction). If set to 0, the terms must appear * next to each other. * - * @param int $maxGaps + * @param int $value * @return static */ - public function maxGaps(int $maxGaps): static + public function maxGaps(int $value): static { - return $this->addProperty('max_gaps', $maxGaps); + return $this->addProperty('max_gaps', $value); } /** * If true, matching terms must appear in their * specified order. Defaults to false. * - * @param bool $ordered + * @param bool $value * @return static */ - public function ordered(bool $ordered = false): static + public function ordered(bool $value = false): static { - return $this->addProperty('ordered', $ordered); + return $this->addProperty('ordered', $value); } /** * Analyzer used to analyze terms in the query. * Defaults to the top-level field's analyzer. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * An optional interval filter. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { - return $this->addProperty('filter', Filter::create($filter)); + return $this->addProperty('filter', Filter::create($value)); } /** @@ -80,11 +80,11 @@ public function filter($filter): static * than the top-level field. Terms are analyzed using the search analyzer * from this field. * - * @param string $useField + * @param string $value * @return static */ - public function useField(string $useField): static + public function useField(string $value): static { - return $this->addProperty('use_field', $useField); + return $this->addProperty('use_field', $value); } } diff --git a/src/DSL/Queries/FullText/Intervals/Prefix.php b/src/DSL/Queries/FullText/Intervals/Prefix.php index 13eaef4..38e7d60 100644 --- a/src/DSL/Queries/FullText/Intervals/Prefix.php +++ b/src/DSL/Queries/FullText/Intervals/Prefix.php @@ -19,24 +19,24 @@ class Prefix extends Node * Beginning characters of terms you wish to find in * the top-level field. * - * @param string $prefix + * @param string $value * @return static */ - public function prefix(string $prefix): static + public function prefix(string $value): static { - return $this->addProperty('prefix', $prefix); + return $this->addProperty('prefix', $value); } /** * Analyzer used to normalize the prefix. Defaults to * the top-level field's analyzer. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** @@ -44,11 +44,11 @@ public function analyzer(string $analyzer): static * than the top-level field. The prefix is normalized using the search * analyzer from this field. * - * @param string $userField + * @param string $value * @return static */ - public function useField(string $userField): static + public function useField(string $value): static { - return $this->addProperty('use_field', $userField); + return $this->addProperty('use_field', $value); } } diff --git a/src/DSL/Queries/FullText/Intervals/Range.php b/src/DSL/Queries/FullText/Intervals/Range.php index bfb7a6e..b931ef9 100644 --- a/src/DSL/Queries/FullText/Intervals/Range.php +++ b/src/DSL/Queries/FullText/Intervals/Range.php @@ -20,68 +20,68 @@ class Range extends Node /** * Greater than or equal to the specified value. * - * @param string|int|float|bool $gte + * @param string|int|float|bool $value * @return static */ - public function gte(string|int|float|bool $gte): static + public function gte(string|int|float|bool $value): static { - return $this->addProperty('gte', $gte); + return $this->addProperty('gte', $value); } /** * Greater than the specified value. * - * @param string|int|float|bool $gt + * @param string|int|float|bool $value * @return static */ - public function gt(string|int|float|bool $gt): static + public function gt(string|int|float|bool $value): static { - return $this->addProperty('gt', $gt); + return $this->addProperty('gt', $value); } /** * Less than or equal to the specified value. * - * @param string|int|float|bool $lte + * @param string|int|float|bool $value * @return static */ - public function lte(string|int|float|bool $lte): static + public function lte(string|int|float|bool $value): static { - return $this->addProperty('lte', $lte); + return $this->addProperty('lte', $value); } /** * Less than the specified value. * - * @param string|int|float|bool $lt + * @param string|int|float|bool $value * @return static */ - public function lt(string|int|float|bool $lt): static + public function lt(string|int|float|bool $value): static { - return $this->addProperty('lt', $lt); + return $this->addProperty('lt', $value); } /** * Analyzer used to normalize the range values. * Defaults to the top-level field's analyzer. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * If specified, match intervals from this field rather * than the top-level field. * - * @param string $useField + * @param string $value * @return static */ - public function useField(string $useField): static + public function useField(string $value): static { - return $this->addProperty('use_field', $useField); + return $this->addProperty('use_field', $value); } } diff --git a/src/DSL/Queries/FullText/Intervals/Wildcard.php b/src/DSL/Queries/FullText/Intervals/Wildcard.php index 43fe8e3..92892ab 100644 --- a/src/DSL/Queries/FullText/Intervals/Wildcard.php +++ b/src/DSL/Queries/FullText/Intervals/Wildcard.php @@ -19,24 +19,24 @@ class Wildcard extends Node * Wildcard pattern used to find matching terms. * Supports ? (any single character) and * (zero or more characters). * - * @param string $pattern + * @param string $value * @return static */ - public function pattern(string $pattern): static + public function pattern(string $value): static { - return $this->addProperty('pattern', $pattern); + return $this->addProperty('pattern', $value); } /** * Analyzer used to normalize the pattern. Defaults to * the top-level field's analyzer. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** @@ -44,11 +44,11 @@ public function analyzer(string $analyzer): static * than the top-level field. The pattern is normalized using the search * analyzer from this field. * - * @param string $useField + * @param string $value * @return static */ - public function useField(string $useField): static + public function useField(string $value): static { - return $this->addProperty('use_field', $useField); + return $this->addProperty('use_field', $value); } } diff --git a/src/DSL/Queries/FullText/MatchBoolPrefix.php b/src/DSL/Queries/FullText/MatchBoolPrefix.php index 50ee452..1c4e311 100644 --- a/src/DSL/Queries/FullText/MatchBoolPrefix.php +++ b/src/DSL/Queries/FullText/MatchBoolPrefix.php @@ -24,117 +24,117 @@ class MatchBoolPrefix extends Node * The match_bool_prefix query analyzes any provided text into tokens * before performing a search. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** * Maximum number of terms to which the last provided * term of the query value will expand. Defaults to 50. * - * @param int $maxExpansions + * @param int $value * @return static */ - public function maxExpansions(int $maxExpansions): static + public function maxExpansions(int $value): static { - return $this->addProperty('max_expansions', $maxExpansions); + return $this->addProperty('max_expansions', $value); } /** * If true, format-based errors, such as providing a * text query value for a numeric field, are ignored. Defaults to false. * - * @param bool $lenient + * @param bool $value * @return static */ - public function lenient(bool $lenient): static + public function lenient(bool $value): static { - return $this->addProperty('lenient', $lenient); + return $this->addProperty('lenient', $value); } /** * Analyzer used to convert text in the query value * into tokens. Defaults to the index-time analyzer mapped for the field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * Minimum number of clauses that must match for a * document to be returned. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** * Maximum edit distance allowed for fuzzy matching. * - * @param int|string $fuzziness + * @param int|string $value * @return static */ - public function fuzziness(int|string $fuzziness): static + public function fuzziness(int|string $value): static { - return $this->addProperty('fuzziness', $fuzziness); + return $this->addProperty('fuzziness', $value); } /** * Number of beginning characters left unchanged for * fuzzy matching. Defaults to 0. * - * @param int $prefixLength + * @param int $value * @return static */ - public function prefixLength(int $prefixLength): static + public function prefixLength(int $value): static { - return $this->addProperty('prefix_length', $prefixLength); + return $this->addProperty('prefix_length', $value); } /** * If true, edits for fuzzy matching include * transpositions of two adjacent characters (ab -> ba). Defaults to true. * - * @param bool $fuzzyTranspositions + * @param bool $value * @return static */ - public function fuzzyTranspositions(bool $fuzzyTranspositions): static + public function fuzzyTranspositions(bool $value): static { - return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); + return $this->addProperty('fuzzy_transpositions', $value); } /** * Method used to rewrite the query for fuzzy matching. * - * @param string $fuzzyRewrite + * @param string $value * @return static */ - public function fuzzyRewrite(string $fuzzyRewrite): static + public function fuzzyRewrite(string $value): static { - return $this->addProperty('fuzzy_rewrite', $fuzzyRewrite); + return $this->addProperty('fuzzy_rewrite', $value); } /** * Boolean logic used to interpret text in the query * value. Valid values are: OR (Default), AND. * - * @param string $operator + * @param string $value * @return static */ - public function operator(string $operator): static + public function operator(string $value): static { - return $this->addProperty('operator', $operator); + return $this->addProperty('operator', $value); } } diff --git a/src/DSL/Queries/FullText/MatchPhrase.php b/src/DSL/Queries/FullText/MatchPhrase.php index 83df915..921ab50 100644 --- a/src/DSL/Queries/FullText/MatchPhrase.php +++ b/src/DSL/Queries/FullText/MatchPhrase.php @@ -24,36 +24,36 @@ class MatchPhrase extends Node * The match_phrase query analyzes any provided text into tokens before * performing a search. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** * Analyzer used to convert text in the query value * into tokens. Defaults to the index-time analyzer mapped for the field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * Maximum number of positions allowed between matching * tokens. Defaults to 0. Transposed terms have a slop of 2. * - * @param int $slop + * @param int $value * @return static */ - public function slop(int $slop): static + public function slop(int $value): static { - return $this->addProperty('slop', $slop); + return $this->addProperty('slop', $value); } /** @@ -61,11 +61,11 @@ public function slop(int $slop): static * analyzer removes all tokens, such as when using a stop filter. * Valid values are: none (Default), all. * - * @param string $zeroTermsQuery + * @param string $value * @return static */ - public function zeroTermsQuery(string $zeroTermsQuery): static + public function zeroTermsQuery(string $value): static { - return $this->addProperty('zero_terms_query', $zeroTermsQuery); + return $this->addProperty('zero_terms_query', $value); } } diff --git a/src/DSL/Queries/FullText/MatchPhrasePrefix.php b/src/DSL/Queries/FullText/MatchPhrasePrefix.php index c907d57..9b2fcc6 100644 --- a/src/DSL/Queries/FullText/MatchPhrasePrefix.php +++ b/src/DSL/Queries/FullText/MatchPhrasePrefix.php @@ -25,48 +25,48 @@ class MatchPhrasePrefix extends Node * before performing a search. The last term of this text is treated as a * prefix, matching any words that begin with that term. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** * Analyzer used to convert text in the query value * into tokens. Defaults to the index-time analyzer mapped for the field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * Maximum number of terms to which the last provided * term of the query value will expand. Defaults to 50. * - * @param int $maxExpansions + * @param int $value * @return static */ - public function maxExpansions(int $maxExpansions): static + public function maxExpansions(int $value): static { - return $this->addProperty('max_expansions', $maxExpansions); + return $this->addProperty('max_expansions', $value); } /** * Maximum number of positions allowed between matching * tokens. Defaults to 0. Transposed terms have a slop of 2. * - * @param int $slop + * @param int $value * @return static */ - public function slop(int $slop): static + public function slop(int $value): static { - return $this->addProperty('slop', $slop); + return $this->addProperty('slop', $value); } /** @@ -74,11 +74,11 @@ public function slop(int $slop): static * analyzer removes all tokens, such as when using a stop filter. * Valid values are: none (Default), all. * - * @param string $zeroTermsQuery + * @param string $value * @return static */ - public function zeroTermsQuery(string $zeroTermsQuery): static + public function zeroTermsQuery(string $value): static { - return $this->addProperty('zero_terms_query', $zeroTermsQuery); + return $this->addProperty('zero_terms_query', $value); } } diff --git a/src/DSL/Queries/FullText/Match_.php b/src/DSL/Queries/FullText/Match_.php index 45c8947..70a0466 100644 --- a/src/DSL/Queries/FullText/Match_.php +++ b/src/DSL/Queries/FullText/Match_.php @@ -26,84 +26,84 @@ class Match_ extends Node * in the provided field. The match query analyzes any provided text before * performing a search. * - * @param string|int|float|bool $query + * @param string|int|float|bool $value * @return static */ - public function query(string|int|float|bool $query): static + public function query(string|int|float|bool $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** * Analyzer used to convert the text in the query value * into tokens. Defaults to the index-time analyzer mapped for the field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * If true, match phrase queries are automatically * created for multi-term synonyms. Defaults to true. * - * @param bool $autoGenerateSynonymsPhraseQuery + * @param bool $value * @return static */ - public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static + public function autoGenerateSynonymsPhraseQuery(bool $value): static { - return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); + return $this->addProperty('auto_generate_synonyms_phrase_query', $value); } /** * Maximum edit distance allowed for matching. * See Fuzziness for valid values and more information. * - * @param int|string $fuzziness + * @param int|string $value * @return static */ - public function fuzziness(int|string $fuzziness): static + public function fuzziness(int|string $value): static { - return $this->addProperty('fuzziness', $fuzziness); + return $this->addProperty('fuzziness', $value); } /** * Maximum number of terms to which the query will * expand. Defaults to 50. * - * @param int $maxExpansions + * @param int $value * @return static */ - public function maxExpansions(int $maxExpansions): static + public function maxExpansions(int $value): static { - return $this->addProperty('max_expansions', $maxExpansions); + return $this->addProperty('max_expansions', $value); } /** * Number of beginning characters left unchanged for * fuzzy matching. Defaults to 0. * - * @param int $prefixLength + * @param int $value * @return static */ - public function prefixLength(int $prefixLength): static + public function prefixLength(int $value): static { - return $this->addProperty('prefix_length', $prefixLength); + return $this->addProperty('prefix_length', $value); } /** * If true, edits for fuzzy matching include * transpositions of two adjacent characters (ab -> ba). Defaults to true. * - * @param bool $fuzzyTranspositions + * @param bool $value * @return static */ - public function fuzzyTranspositions(bool $fuzzyTranspositions): static + public function fuzzyTranspositions(bool $value): static { - return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); + return $this->addProperty('fuzzy_transpositions', $value); } /** @@ -111,48 +111,48 @@ public function fuzzyTranspositions(bool $fuzzyTranspositions): static * parameter is not 0, the match query uses a fuzzy_rewrite method of * top_terms_blended_freqs_${max_expansions} by default. * - * @param string $fuzzyRewrite + * @param string $value * @return static */ - public function fuzzyRewrite(string $fuzzyRewrite): static + public function fuzzyRewrite(string $value): static { - return $this->addProperty('fuzzy_rewrite', $fuzzyRewrite); + return $this->addProperty('fuzzy_rewrite', $value); } /** * If true, format-based errors, such as providing a * text query value for a numeric field, are ignored. Defaults to false. * - * @param bool $lenient + * @param bool $value * @return static */ - public function lenient(bool $lenient): static + public function lenient(bool $value): static { - return $this->addProperty('lenient', $lenient); + return $this->addProperty('lenient', $value); } /** * Boolean logic used to interpret text in the query * value. Valid values are: OR (Default), AND. * - * @param string $operator + * @param string $value * @return static */ - public function operator(string $operator): static + public function operator(string $value): static { - return $this->addProperty('operator', $operator); + return $this->addProperty('operator', $value); } /** * Minimum number of clauses that must match for a * document to be returned. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** @@ -160,11 +160,11 @@ public function minimumShouldMatch(int|string $minimumShouldMatch): static * analyzer removes all tokens, such as when using a stop filter. * Valid values are: none (Default), all. * - * @param string $zeroTermsQuery + * @param string $value * @return static */ - public function zeroTermsQuery(string $zeroTermsQuery): static + public function zeroTermsQuery(string $value): static { - return $this->addProperty('zero_terms_query', $zeroTermsQuery); + return $this->addProperty('zero_terms_query', $value); } } diff --git a/src/DSL/Queries/FullText/MultiMatch.php b/src/DSL/Queries/FullText/MultiMatch.php index 048c222..38f35e3 100644 --- a/src/DSL/Queries/FullText/MultiMatch.php +++ b/src/DSL/Queries/FullText/MultiMatch.php @@ -19,12 +19,12 @@ class MultiMatch extends Node * Text, number, boolean value or date you wish to find * in the provided fields. * - * @param string|int|float|bool $query + * @param string|int|float|bool $value * @return static */ - public function query(string|int|float|bool $query): static + public function query(string|int|float|bool $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** @@ -32,12 +32,12 @@ public function query(string|int|float|bool $query): static * wildcards (*). Individual fields can be boosted with the caret (^) * notation. * - * @param array $fields + * @param array $value * @return static */ - public function fields(array $fields): static + public function fields(array $value): static { - return $this->addProperty('fields', $fields); + return $this->addProperty('fields', $value); } /** @@ -45,130 +45,130 @@ public function fields(array $fields): static * Valid values are: best_fields (Default), most_fields, cross_fields, * phrase, phrase_prefix, bool_prefix. * - * @param string $type + * @param string $value * @return static */ - public function type(string $type): static + public function type(string $value): static { - return $this->addProperty('type', $type); + return $this->addProperty('type', $value); } /** * Boolean logic used to interpret text in the query * value. Valid values are: OR (Default), AND. * - * @param string $operator + * @param string $value * @return static */ - public function operator(string $operator): static + public function operator(string $value): static { - return $this->addProperty('operator', $operator); + return $this->addProperty('operator', $value); } /** * Analyzer used to convert the text in the query value * into tokens. Defaults to the index-time analyzer mapped for the field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * Minimum number of clauses that must match for a * document to be returned. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** * Floating point number used to decrease or increase * the relevance scores of a query. Defaults to 1.0. * - * @param float $tieBreaker + * @param float $value * @return static */ - public function tieBreaker(float $tieBreaker): static + public function tieBreaker(float $value): static { - return $this->addProperty('tie_breaker', $tieBreaker); + return $this->addProperty('tie_breaker', $value); } /** * Maximum edit distance allowed for fuzzy matching. * - * @param int|string $fuzziness + * @param int|string $value * @return static */ - public function fuzziness(int|string $fuzziness): static + public function fuzziness(int|string $value): static { - return $this->addProperty('fuzziness', $fuzziness); + return $this->addProperty('fuzziness', $value); } /** * Number of beginning characters left unchanged for * fuzzy matching. Defaults to 0. * - * @param int $prefixLength + * @param int $value * @return static */ - public function prefixLength(int $prefixLength): static + public function prefixLength(int $value): static { - return $this->addProperty('prefix_length', $prefixLength); + return $this->addProperty('prefix_length', $value); } /** * Maximum number of terms to which the query will * expand. Defaults to 50. * - * @param int $maxExpansions + * @param int $value * @return static */ - public function maxExpansions(int $maxExpansions): static + public function maxExpansions(int $value): static { - return $this->addProperty('max_expansions', $maxExpansions); + return $this->addProperty('max_expansions', $value); } /** * If true, edits for fuzzy matching include * transpositions of two adjacent characters (ab -> ba). Defaults to true. * - * @param bool $fuzzyTranspositions + * @param bool $value * @return static */ - public function fuzzyTranspositions(bool $fuzzyTranspositions): static + public function fuzzyTranspositions(bool $value): static { - return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); + return $this->addProperty('fuzzy_transpositions', $value); } /** * Method used to rewrite the query for fuzzy matching. * - * @param string $fuzzyRewrite + * @param string $value * @return static */ - public function fuzzyRewrite(string $fuzzyRewrite): static + public function fuzzyRewrite(string $value): static { - return $this->addProperty('fuzzy_rewrite', $fuzzyRewrite); + return $this->addProperty('fuzzy_rewrite', $value); } /** * If true, format-based errors, such as providing a * text query value for a numeric field, are ignored. Defaults to false. * - * @param bool $lenient + * @param bool $value * @return static */ - public function lenient(bool $lenient): static + public function lenient(bool $value): static { - return $this->addProperty('lenient', $lenient); + return $this->addProperty('lenient', $value); } /** @@ -176,35 +176,35 @@ public function lenient(bool $lenient): static * analyzer removes all tokens, such as when using a stop filter. * Valid values are: none (Default), all. * - * @param string $zeroTermsQuery + * @param string $value * @return static */ - public function zeroTermsQuery(string $zeroTermsQuery): static + public function zeroTermsQuery(string $value): static { - return $this->addProperty('zero_terms_query', $zeroTermsQuery); + return $this->addProperty('zero_terms_query', $value); } /** * Maximum number of positions allowed between matching * tokens. Defaults to 0. Transposed terms have a slop of 2. * - * @param int $slop + * @param int $value * @return static */ - public function slop(int $slop): static + public function slop(int $value): static { - return $this->addProperty('slop', $slop); + return $this->addProperty('slop', $value); } /** * If true, match phrase queries are automatically * created for multi-term synonyms. Defaults to true. * - * @param bool $autoGenerateSynonymsPhraseQuery + * @param bool $value * @return static */ - public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static + public function autoGenerateSynonymsPhraseQuery(bool $value): static { - return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); + return $this->addProperty('auto_generate_synonyms_phrase_query', $value); } } diff --git a/src/DSL/Queries/FullText/QueryString.php b/src/DSL/Queries/FullText/QueryString.php index 1d4b757..b4145fb 100644 --- a/src/DSL/Queries/FullText/QueryString.php +++ b/src/DSL/Queries/FullText/QueryString.php @@ -19,36 +19,36 @@ class QueryString extends Node /** * Query string you wish to parse and use for search. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** * Default field to search if no field is provided in * the query string. Supports wildcards (*). Defaults to *. * - * @param string $defaultField + * @param string $value * @return static */ - public function defaultField(string $defaultField): static + public function defaultField(string $value): static { - return $this->addProperty('default_field', $defaultField); + return $this->addProperty('default_field', $value); } /** * If true, the wildcard characters * and ? are allowed * as the first character of the query string. Defaults to true. * - * @param bool $allowLeadingWildcard + * @param bool $value * @return static */ - public function allowLeadingWildcard(bool $allowLeadingWildcard): static + public function allowLeadingWildcard(bool $value): static { - return $this->addProperty('allow_leading_wildcard', $allowLeadingWildcard); + return $this->addProperty('allow_leading_wildcard', $value); } /** @@ -56,24 +56,24 @@ public function allowLeadingWildcard(bool $allowLeadingWildcard): static * into tokens. Defaults to the index-time analyzer mapped for the * default_field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * If true, match phrase queries are automatically * created for multi-term synonyms. Defaults to true. * - * @param bool $autoGenerateSynonymsPhraseQuery + * @param bool $value * @return static */ - public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static + public function autoGenerateSynonymsPhraseQuery(bool $value): static { - return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); + return $this->addProperty('auto_generate_synonyms_phrase_query', $value); } /** @@ -81,119 +81,119 @@ public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhrase * query string if no operators are specified. Valid values are: * OR (Default), AND. * - * @param string $defaultOperator + * @param string $value * @return static */ - public function defaultOperator(string $defaultOperator): static + public function defaultOperator(string $value): static { - return $this->addProperty('default_operator', $defaultOperator); + return $this->addProperty('default_operator', $value); } /** * If true, enable position increments in queries * constructed from a query_string search. Defaults to true. * - * @param bool $enablePositionIncrements + * @param bool $value * @return static */ - public function enablePositionIncrements(bool $enablePositionIncrements): static + public function enablePositionIncrements(bool $value): static { - return $this->addProperty('enable_position_increments', $enablePositionIncrements); + return $this->addProperty('enable_position_increments', $value); } /** * Array of fields to search. Supports * wildcards (*). * - * @param array $fields + * @param array $value * @return static */ - public function fields(array $fields): static + public function fields(array $value): static { - return $this->addProperty('fields', $fields); + return $this->addProperty('fields', $value); } /** * Maximum edit distance allowed for fuzzy matching. * - * @param int|string $fuzziness + * @param int|string $value * @return static */ - public function fuzziness(int|string $fuzziness): static + public function fuzziness(int|string $value): static { - return $this->addProperty('fuzziness', $fuzziness); + return $this->addProperty('fuzziness', $value); } /** * Maximum number of terms to which the query expands * for fuzzy matching. Defaults to 50. * - * @param int $fuzzyMaxExpansions + * @param int $value * @return static */ - public function fuzzyMaxExpansions(int $fuzzyMaxExpansions): static + public function fuzzyMaxExpansions(int $value): static { - return $this->addProperty('fuzzy_max_expansions', $fuzzyMaxExpansions); + return $this->addProperty('fuzzy_max_expansions', $value); } /** * Number of beginning characters left unchanged for * fuzzy matching. Defaults to 0. * - * @param int $fuzzyPrefixLength + * @param int $value * @return static */ - public function fuzzyPrefixLength(int $fuzzyPrefixLength): static + public function fuzzyPrefixLength(int $value): static { - return $this->addProperty('fuzzy_prefix_length', $fuzzyPrefixLength); + return $this->addProperty('fuzzy_prefix_length', $value); } /** * If true, edits for fuzzy matching include * transpositions of two adjacent characters (ab -> ba). Defaults to true. * - * @param bool $fuzzyTranspositions + * @param bool $value * @return static */ - public function fuzzyTranspositions(bool $fuzzyTranspositions): static + public function fuzzyTranspositions(bool $value): static { - return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); + return $this->addProperty('fuzzy_transpositions', $value); } /** * If true, format-based errors, such as providing a * text value for a numeric field, are ignored. Defaults to false. * - * @param bool $lenient + * @param bool $value * @return static */ - public function lenient(bool $lenient): static + public function lenient(bool $value): static { - return $this->addProperty('lenient', $lenient); + return $this->addProperty('lenient', $value); } /** * Maximum number of automaton states required for * the query. Default is 10000. * - * @param int $maxDeterminizedStates + * @param int $value * @return static */ - public function maxDeterminizedStates(int $maxDeterminizedStates): static + public function maxDeterminizedStates(int $value): static { - return $this->addProperty('max_determinized_states', $maxDeterminizedStates); + return $this->addProperty('max_determinized_states', $value); } /** * Minimum number of clauses that must match for a * document to be returned. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** @@ -201,12 +201,12 @@ public function minimumShouldMatch(int|string $minimumShouldMatch): static * string into tokens. Defaults to the search_quote_analyzer mapped for * the default_field. * - * @param string $quoteAnalyzer + * @param string $value * @return static */ - public function quoteAnalyzer(string $quoteAnalyzer): static + public function quoteAnalyzer(string $value): static { - return $this->addProperty('quote_analyzer', $quoteAnalyzer); + return $this->addProperty('quote_analyzer', $value); } /** @@ -214,12 +214,12 @@ public function quoteAnalyzer(string $quoteAnalyzer): static * tokens for phrases. Defaults to 0. If 0, exact phrase matches are * required. Transposed terms have a slop of 2. * - * @param int $phraseSlop + * @param int $value * @return static */ - public function phraseSlop(int $phraseSlop): static + public function phraseSlop(int $value): static { - return $this->addProperty('phrase_slop', $phraseSlop); + return $this->addProperty('phrase_slop', $value); } /** @@ -227,35 +227,35 @@ public function phraseSlop(int $phraseSlop): static * You can use this suffix to use a different analysis method for exact * matches. * - * @param string $quoteFieldSuffix + * @param string $value * @return static */ - public function quoteFieldSuffix(string $quoteFieldSuffix): static + public function quoteFieldSuffix(string $value): static { - return $this->addProperty('quote_field_suffix', $quoteFieldSuffix); + return $this->addProperty('quote_field_suffix', $value); } /** * Method used to rewrite the query. * - * @param string $rewrite + * @param string $value * @return static */ - public function rewrite(string $rewrite): static + public function rewrite(string $value): static { - return $this->addProperty('rewrite', $rewrite); + return $this->addProperty('rewrite', $value); } /** * Coordinated Universal Time (UTC) offset or IANA time * zone used to convert date values in the query string to UTC. * - * @param string $timeZone + * @param string $value * @return static */ - public function timeZone(string $timeZone): static + public function timeZone(string $value): static { - return $this->addProperty('time_zone', $timeZone); + return $this->addProperty('time_zone', $value); } /** @@ -263,35 +263,35 @@ public function timeZone(string $timeZone): static * when searching multiple fields. Valid values are: best_fields (Default), * most_fields, cross_fields, phrase, phrase_prefix, bool_prefix. * - * @param string $type + * @param string $value * @return static */ - public function type(string $type): static + public function type(string $value): static { - return $this->addProperty('type', $type); + return $this->addProperty('type', $value); } /** * If true, the query attempts to analyze wildcard terms * in the query string. Defaults to false. * - * @param bool $analyzeWildcard + * @param bool $value * @return static */ - public function analyzeWildcard(bool $analyzeWildcard): static + public function analyzeWildcard(bool $value): static { - return $this->addProperty('analyze_wildcard', $analyzeWildcard); + return $this->addProperty('analyze_wildcard', $value); } /** * Floating point number used to control the scoring of * results when searching multiple fields. Defaults to 0. * - * @param float $tieBreaker + * @param float $value * @return static */ - public function tieBreaker(float $tieBreaker): static + public function tieBreaker(float $value): static { - return $this->addProperty('tie_breaker', $tieBreaker); + return $this->addProperty('tie_breaker', $value); } } diff --git a/src/DSL/Queries/FullText/SimpleQueryString.php b/src/DSL/Queries/FullText/SimpleQueryString.php index 84666d3..700a93e 100644 --- a/src/DSL/Queries/FullText/SimpleQueryString.php +++ b/src/DSL/Queries/FullText/SimpleQueryString.php @@ -19,12 +19,12 @@ class SimpleQueryString extends Node /** * Query string you wish to parse and use for search. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } /** @@ -32,12 +32,12 @@ public function query(string $query): static * Supports wildcard expressions and per-field boosting with caret (^) * notation. * - * @param array $fields + * @param array $value * @return static */ - public function fields(array $fields): static + public function fields(array $value): static { - return $this->addProperty('fields', $fields); + return $this->addProperty('fields', $value); } /** @@ -45,24 +45,24 @@ public function fields(array $fields): static * query string if no operators are specified. Valid values are: * OR (Default), AND. * - * @param string $defaultOperator + * @param string $value * @return static */ - public function defaultOperator(string $defaultOperator): static + public function defaultOperator(string $value): static { - return $this->addProperty('default_operator', $defaultOperator); + return $this->addProperty('default_operator', $value); } /** * If true, the query attempts to analyze wildcard terms * in the query string. Defaults to false. * - * @param bool $analyzeWildcard + * @param bool $value * @return static */ - public function analyzeWildcard(bool $analyzeWildcard): static + public function analyzeWildcard(bool $value): static { - return $this->addProperty('analyze_wildcard', $analyzeWildcard); + return $this->addProperty('analyze_wildcard', $value); } /** @@ -70,96 +70,96 @@ public function analyzeWildcard(bool $analyzeWildcard): static * into tokens. Defaults to the index-time analyzer mapped for the * default_field. * - * @param string $analyzer + * @param string $value * @return static */ - public function analyzer(string $analyzer): static + public function analyzer(string $value): static { - return $this->addProperty('analyzer', $analyzer); + return $this->addProperty('analyzer', $value); } /** * If true, the parser creates a match_phrase query * for each multi-position token. Defaults to true. * - * @param bool $autoGenerateSynonymsPhraseQuery + * @param bool $value * @return static */ - public function autoGenerateSynonymsPhraseQuery(bool $autoGenerateSynonymsPhraseQuery): static + public function autoGenerateSynonymsPhraseQuery(bool $value): static { - return $this->addProperty('auto_generate_synonyms_phrase_query', $autoGenerateSynonymsPhraseQuery); + return $this->addProperty('auto_generate_synonyms_phrase_query', $value); } /** * List of enabled operators for the simple query string * syntax. Defaults to ALL (all operators). * - * @param string $flags + * @param string $value * @return static */ - public function flags(string $flags): static + public function flags(string $value): static { - return $this->addProperty('flags', $flags); + return $this->addProperty('flags', $value); } /** * Maximum number of terms to which the query expands * for fuzzy matching. Defaults to 50. * - * @param int $fuzzyMaxExpansions + * @param int $value * @return static */ - public function fuzzyMaxExpansions(int $fuzzyMaxExpansions): static + public function fuzzyMaxExpansions(int $value): static { - return $this->addProperty('fuzzy_max_expansions', $fuzzyMaxExpansions); + return $this->addProperty('fuzzy_max_expansions', $value); } /** * Number of beginning characters left unchanged for * fuzzy matching. Defaults to 0. * - * @param int $fuzzyPrefixLength + * @param int $value * @return static */ - public function fuzzyPrefixLength(int $fuzzyPrefixLength): static + public function fuzzyPrefixLength(int $value): static { - return $this->addProperty('fuzzy_prefix_length', $fuzzyPrefixLength); + return $this->addProperty('fuzzy_prefix_length', $value); } /** * If true, edits for fuzzy matching include * transpositions of two adjacent characters (ab -> ba). Defaults to true. * - * @param bool $fuzzyTranspositions + * @param bool $value * @return static */ - public function fuzzyTranspositions(bool $fuzzyTranspositions): static + public function fuzzyTranspositions(bool $value): static { - return $this->addProperty('fuzzy_transpositions', $fuzzyTranspositions); + return $this->addProperty('fuzzy_transpositions', $value); } /** * If true, format-based errors, such as providing a * text value for a numeric field, are ignored. Defaults to false. * - * @param bool $lenient + * @param bool $value * @return static */ - public function lenient(bool $lenient): static + public function lenient(bool $value): static { - return $this->addProperty('lenient', $lenient); + return $this->addProperty('lenient', $value); } /** * Minimum number of clauses that must match for a * document to be returned. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** @@ -167,11 +167,11 @@ public function minimumShouldMatch(int|string $minimumShouldMatch): static * You can use this suffix to use a different analysis method for exact * matches. * - * @param string $quoteFieldSuffix + * @param string $value * @return static */ - public function quoteFieldSuffix(string $quoteFieldSuffix): static + public function quoteFieldSuffix(string $value): static { - return $this->addProperty('quote_field_suffix', $quoteFieldSuffix); + return $this->addProperty('quote_field_suffix', $value); } } diff --git a/src/DSL/Queries/Geo.php b/src/DSL/Queries/Geo.php index 631bbb3..51f567d 100644 --- a/src/DSL/Queries/Geo.php +++ b/src/DSL/Queries/Geo.php @@ -22,7 +22,7 @@ trait Geo * @param mixed $value * @return $this */ - public function geoBoundingBox($field, $value = null) + public function geoBoundingBox($field, $value = null): static { return $this->addQuery(GeoBoundingBox::create($field, $value)); } @@ -35,7 +35,7 @@ public function geoBoundingBox($field, $value = null) * @param callable|GeoDistance|array $value * @return $this */ - public function geoDistance($value = null) + public function geoDistance($value = null): static { return $this->addQuery(GeoDistance::create($value)); } @@ -47,7 +47,7 @@ public function geoDistance($value = null) * @param mixed $value * @return $this */ - public function geoGrid($field, $value = null) + public function geoGrid($field, $value = null): static { return $this->addQuery(GeoGrid::create($field, $value)); } @@ -59,7 +59,7 @@ public function geoGrid($field, $value = null) * @param mixed $value * @return $this */ - public function geoPolygon($field, $value = null) + public function geoPolygon($field, $value = null): static { return $this->addQuery(GeoPolygon::create($field, $value)); } @@ -71,7 +71,7 @@ public function geoPolygon($field, $value = null) * @param mixed $value * @return $this */ - public function geoShape($field, $value = null) + public function geoShape($field, $value = null): static { return $this->addQuery(GeoShape::create($field, $value)); } diff --git a/src/DSL/Queries/Geo/GeoBoundingBox.php b/src/DSL/Queries/Geo/GeoBoundingBox.php index a5b5367..2502bda 100644 --- a/src/DSL/Queries/Geo/GeoBoundingBox.php +++ b/src/DSL/Queries/Geo/GeoBoundingBox.php @@ -20,123 +20,123 @@ class GeoBoundingBox extends Node /** * Top-left corner of the bounding box. * - * @param mixed $topLeft + * @param mixed $value * @return static */ - public function topLeft($topLeft): static + public function topLeft($value): static { - return $this->addProperty('top_left', $topLeft); + return $this->addProperty('top_left', $value); } /** * Bottom-right corner of the bounding box. * - * @param mixed $bottomRight + * @param mixed $value * @return static */ - public function bottomRight($bottomRight): static + public function bottomRight($value): static { - return $this->addProperty('bottom_right', $bottomRight); + return $this->addProperty('bottom_right', $value); } /** * Top latitude of the bounding box. Can be used instead of topLeft/bottomRight pairs to set values separately. * - * @param float $top + * @param float $value * @return static */ - public function top(float $top): static + public function top(float $value): static { - return $this->addProperty('top', $top); + return $this->addProperty('top', $value); } /** * Left longitude of the bounding box. Can be used instead of topLeft/bottomRight pairs to set values separately. * - * @param float $left + * @param float $value * @return static */ - public function left(float $left): static + public function left(float $value): static { - return $this->addProperty('left', $left); + return $this->addProperty('left', $value); } /** * Bottom latitude of the bounding box. Can be used instead of topLeft/bottomRight pairs to set values separately. * - * @param float $bottom + * @param float $value * @return static */ - public function bottom(float $bottom): static + public function bottom(float $value): static { - return $this->addProperty('bottom', $bottom); + return $this->addProperty('bottom', $value); } /** * Right longitude of the bounding box. Can be used instead of topLeft/bottomRight pairs to set values separately. * - * @param float $right + * @param float $value * @return static */ - public function right(float $right): static + public function right(float $value): static { - return $this->addProperty('right', $right); + return $this->addProperty('right', $value); } /** * Bounding box defined as Well-Known Text (WKT) BBOX format. * - * @param string $wkt + * @param string $value * @return static */ - public function wkt(string $wkt): static + public function wkt(string $value): static { - return $this->addProperty('wkt', $wkt); + return $this->addProperty('wkt', $value); } /** * Top-right corner of the bounding box. Can be used with bottomLeft instead of topLeft/bottomRight. * - * @param mixed $topRight + * @param mixed $value * @return static */ - public function topRight($topRight): static + public function topRight($value): static { - return $this->addProperty('top_right', $topRight); + return $this->addProperty('top_right', $value); } /** * Bottom-left corner of the bounding box. Can be used with topRight instead of topLeft/bottomRight. * - * @param mixed $bottomLeft + * @param mixed $value * @return static */ - public function bottomLeft($bottomLeft): static + public function bottomLeft($value): static { - return $this->addProperty('bottom_left', $bottomLeft); + return $this->addProperty('bottom_left', $value); } /** * Set to IGNORE_MALFORMED to accept geo points with invalid latitude or longitude, * set to COERCE to also try to infer correct latitude or longitude. Defaults to STRICT. * - * @param string $validationMethod + * @param string $value * @return static */ - public function validationMethod(string $validationMethod): static + public function validationMethod(string $value): static { - return $this->addProperty('validation_method', $validationMethod); + return $this->addProperty('validation_method', $value); } /** * When set to true, the ignore_unmapped option will ignore an unmapped field * and will not match any documents for this query. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Queries/Geo/GeoDistance.php b/src/DSL/Queries/Geo/GeoDistance.php index 6f5b892..e0ea3f4 100644 --- a/src/DSL/Queries/Geo/GeoDistance.php +++ b/src/DSL/Queries/Geo/GeoDistance.php @@ -25,12 +25,12 @@ class GeoDistance extends Node * Points which fall into this circle are considered to be matches. * The distance can be specified in various units. * - * @param string $distance + * @param string $value * @return static */ - public function distance(string $distance): static + public function distance(string $value): static { - return $this->addProperty('distance', $distance); + return $this->addProperty('distance', $value); } /** @@ -50,36 +50,34 @@ public function location(string $field, $location): static * How to compute the distance. Can either be arc (default) or * plane (faster, but inaccurate on long distances and close to the poles). * - * @param string $distanceType + * @param string $value * @return static */ - public function distanceType(string $distanceType): static + public function distanceType(string $value): static { - return $this->addProperty('distance_type', $distanceType); + return $this->addProperty('distance_type', $value); } /** * Optional name field to identify the query. * - * @param string $_name + * @param string $value * @return static - * @SuppressWarnings(PHPMD.CamelCaseParameterName) - * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ - public function _name(string $_name): static + public function _name(string $value): static { - return $this->addProperty('_name', $_name); + return $this->addProperty('_name', $value); } /** * Set to IGNORE_MALFORMED to accept geo points with invalid latitude or longitude, * set to COERCE to additionally try and infer correct coordinates. Defaults to STRICT. * - * @param string $validationMethod + * @param string $value * @return static */ - public function validationMethod(string $validationMethod): static + public function validationMethod(string $value): static { - return $this->addProperty('validation_method', $validationMethod); + return $this->addProperty('validation_method', $value); } } diff --git a/src/DSL/Queries/Geo/GeoGrid.php b/src/DSL/Queries/Geo/GeoGrid.php index 64bea1d..66337a8 100644 --- a/src/DSL/Queries/Geo/GeoGrid.php +++ b/src/DSL/Queries/Geo/GeoGrid.php @@ -22,35 +22,35 @@ class GeoGrid extends Node /** * The geohex grid key to match. Only usable with geo_point fields. * - * @param string $geohex + * @param string $value * @return static */ - public function geohex(string $geohex): static + public function geohex(string $value): static { - return $this->addProperty('geohex', $geohex); + return $this->addProperty('geohex', $value); } /** * The geotile grid key to match (e.g. "6/32/21"). * Usable with geo_point and geo_shape fields. * - * @param string $geotile + * @param string $value * @return static */ - public function geotile(string $geotile): static + public function geotile(string $value): static { - return $this->addProperty('geotile', $geotile); + return $this->addProperty('geotile', $value); } /** * The geohash grid key to match (e.g. "u1"). * Usable with geo_point and geo_shape fields. * - * @param string $geohash + * @param string $value * @return static */ - public function geohash(string $geohash): static + public function geohash(string $value): static { - return $this->addProperty('geohash', $geohash); + return $this->addProperty('geohash', $value); } } diff --git a/src/DSL/Queries/Geo/GeoPolygon.php b/src/DSL/Queries/Geo/GeoPolygon.php index 9e3fbbf..bc5b05d 100644 --- a/src/DSL/Queries/Geo/GeoPolygon.php +++ b/src/DSL/Queries/Geo/GeoPolygon.php @@ -21,35 +21,35 @@ class GeoPolygon extends Node * Array of geo points that define the polygon. * At least three points are required to form a polygon. * - * @param array> $points + * @param array> $value * @return static */ - public function points(array $points): static + public function points(array $value): static { - return $this->addProperty('points', $points); + return $this->addProperty('points', $value); } /** * Set to IGNORE_MALFORMED to accept geo points with invalid latitude or longitude, * set to COERCE to try and infer correct latitude or longitude, or STRICT (default). * - * @param string $validationMethod + * @param string $value * @return static */ - public function validationMethod(string $validationMethod): static + public function validationMethod(string $value): static { - return $this->addProperty('validation_method', $validationMethod); + return $this->addProperty('validation_method', $value); } /** * When set to true, the ignore_unmapped option will ignore an unmapped field * and will not match any documents for this query. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Queries/Geo/GeoShape.php b/src/DSL/Queries/Geo/GeoShape.php index 2dfb933..e600074 100644 --- a/src/DSL/Queries/Geo/GeoShape.php +++ b/src/DSL/Queries/Geo/GeoShape.php @@ -24,47 +24,47 @@ class GeoShape extends Node * Inline shape definition using GeoJSON or Well-Known Text (WKT). * Contains the shape type and coordinates. * - * @param mixed $shape + * @param mixed $value * @return static */ - public function shape($shape): static + public function shape($value): static { - return $this->addProperty('shape', $shape); + return $this->addProperty('shape', $value); } /** * Spatial relation operator to use at search time. * Valid values: INTERSECTS (default), DISJOINT, WITHIN, CONTAINS. * - * @param string $relation + * @param string $value * @return static */ - public function relation(string $relation): static + public function relation(string $value): static { - return $this->addProperty('relation', $relation); + return $this->addProperty('relation', $value); } /** * Reference to a pre-indexed shape. Contains id, index, path, and routing fields * to identify the shape document in another index. * - * @param mixed $indexedShape + * @param mixed $value * @return static */ - public function indexedShape($indexedShape): static + public function indexedShape($value): static { - return $this->addProperty('indexed_shape', $indexedShape); + return $this->addProperty('indexed_shape', $value); } /** * When set to true, the ignore_unmapped option will ignore an unmapped field * and will not match any documents for this query. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Queries/Joining.php b/src/DSL/Queries/Joining.php index bb35ae9..98e3446 100644 --- a/src/DSL/Queries/Joining.php +++ b/src/DSL/Queries/Joining.php @@ -24,7 +24,7 @@ trait Joining * @param callable|Query|array|null $query optional query when first arg is a path string * @return $this */ - public function nested($path, $query = null) + public function nested($path, $query = null): static { if (is_string($path) && $query !== null) { $nested = Nested::create($path); @@ -41,7 +41,7 @@ public function nested($path, $query = null) * @param callable|Query|array|null $query optional query when first arg is a type string * @return $this */ - public function hasChild($type, $query = null) + public function hasChild($type, $query = null): static { if (is_string($type) && $query !== null) { $hasChild = HasChild::create(); @@ -59,7 +59,7 @@ public function hasChild($type, $query = null) * @param callable|Query|array|null $query optional query when first arg is a parent_type string * @return $this */ - public function hasParent($type, $query = null) + public function hasParent($type, $query = null): static { if (is_string($type) && $query !== null) { $hasParent = HasParent::create(); @@ -76,7 +76,7 @@ public function hasParent($type, $query = null) * @param mixed $parentId * @return $this */ - public function parentId($parentId) + public function parentId($parentId): static { return $this->addQuery(ParentId::create($parentId)); } diff --git a/src/DSL/Queries/Joining/HasChild.php b/src/DSL/Queries/Joining/HasChild.php index 267aa62..5f6ac72 100644 --- a/src/DSL/Queries/Joining/HasChild.php +++ b/src/DSL/Queries/Joining/HasChild.php @@ -19,48 +19,48 @@ class HasChild extends Node /** * Name of the child relationship mapped for the join field. * - * @param string $type + * @param string $value * @return static */ - public function type(string $type): static + public function type(string $value): static { - return $this->addProperty('type', $type); + return $this->addProperty('type', $value); } /** * Query you wish to run on child documents of the type field. * If a child document matches the search, the query returns the parent document. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - return $this->addProperty('query', Query::create($query)); + return $this->addProperty('query', Query::create($value)); } /** * Indicates whether to ignore an unmapped type and not return any * documents instead of an error. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } /** * Maximum number of child documents that match the query allowed for a * returned parent document. If the parent document exceeds this limit, it is excluded from the search results. * - * @param int $maxChildren + * @param int $value * @return static */ - public function maxChildren(int $maxChildren): static + public function maxChildren(int $value): static { - return $this->addProperty('max_children', $maxChildren); + return $this->addProperty('max_children', $value); } /** @@ -68,23 +68,23 @@ public function maxChildren(int $maxChildren): static * the query for a returned parent document. If the parent document does not meet this limit, * it is excluded from the search results. * - * @param int $minChildren + * @param int $value * @return static */ - public function minChildren(int $minChildren): static + public function minChildren(int $value): static { - return $this->addProperty('min_children', $minChildren); + return $this->addProperty('min_children', $value); } /** * Indicates how scores for matching child documents affect the root parent * document's relevance score. Valid values: none (default), avg, max, min, sum. * - * @param string $scoreMode + * @param string $value * @return static */ - public function scoreMode(string $scoreMode): static + public function scoreMode(string $value): static { - return $this->addProperty('score_mode', $scoreMode); + return $this->addProperty('score_mode', $value); } } diff --git a/src/DSL/Queries/Joining/HasParent.php b/src/DSL/Queries/Joining/HasParent.php index f13d68c..c01178b 100644 --- a/src/DSL/Queries/Joining/HasParent.php +++ b/src/DSL/Queries/Joining/HasParent.php @@ -19,47 +19,47 @@ class HasParent extends Node /** * Name of the parent relationship mapped for the join field. * - * @param string $parentType + * @param string $value * @return static */ - public function parentType(string $parentType): static + public function parentType(string $value): static { - return $this->addProperty('parent_type', $parentType); + return $this->addProperty('parent_type', $value); } /** * Query you wish to run on parent documents of the parent_type field. * If a parent document matches the search, the query returns its child documents. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - return $this->addProperty('query', Query::create($query)); + return $this->addProperty('query', Query::create($value)); } /** * Indicates whether the relevance score of a matching parent document is * aggregated into its child documents. Defaults to false. * - * @param bool $score + * @param bool $value * @return static */ - public function score(bool $score): static + public function score(bool $value): static { - return $this->addProperty('score', $score); + return $this->addProperty('score', $value); } /** * Indicates whether to ignore an unmapped parent_type and not return any * documents instead of an error. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Queries/Joining/Nested.php b/src/DSL/Queries/Joining/Nested.php index 97c762f..5493c0d 100644 --- a/src/DSL/Queries/Joining/Nested.php +++ b/src/DSL/Queries/Joining/Nested.php @@ -37,47 +37,47 @@ public static function create($field = null, $value = null): static /** * Path to the nested object you wish to search. * - * @param string $path + * @param string $value * @return static */ - public function path(string $path): static + public function path(string $value): static { - return $this->addProperty('path', $path); + return $this->addProperty('path', $value); } /** * Query you wish to run on nested objects in the path. * If an object matches the search, the nested query returns the root parent document. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - return $this->addProperty('query', Query::create($query)); + return $this->addProperty('query', Query::create($value)); } /** * Indicates how scores for matching child objects affect the root parent * document's relevance score. Valid values: avg (default), max, min, none, sum. * - * @param string $scoreMode + * @param string $value * @return static */ - public function scoreMode(string $scoreMode): static + public function scoreMode(string $value): static { - return $this->addProperty('score_mode', $scoreMode); + return $this->addProperty('score_mode', $value); } /** * Indicates whether to ignore an unmapped path and not return any * documents instead of an error. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Queries/Joining/ParentId.php b/src/DSL/Queries/Joining/ParentId.php index 040b300..9914e16 100644 --- a/src/DSL/Queries/Joining/ParentId.php +++ b/src/DSL/Queries/Joining/ParentId.php @@ -18,34 +18,34 @@ class ParentId extends Node /** * Name of the child relationship mapped for the join field. * - * @param string $type + * @param string $value * @return static */ - public function type(string $type): static + public function type(string $value): static { - return $this->addProperty('type', $type); + return $this->addProperty('type', $value); } /** * ID of the parent document. The query will return child documents of this parent document. * - * @param string $id + * @param string $value * @return static */ - public function id(string $id): static + public function id(string $value): static { - return $this->addProperty('id', $id); + return $this->addProperty('id', $value); } /** * Indicates whether to ignore an unmapped type and not return any * documents instead of an error. Defaults to false. * - * @param bool $ignoreUnmapped + * @param bool $value * @return static */ - public function ignoreUnmapped(bool $ignoreUnmapped): static + public function ignoreUnmapped(bool $value): static { - return $this->addProperty('ignore_unmapped', $ignoreUnmapped); + return $this->addProperty('ignore_unmapped', $value); } } diff --git a/src/DSL/Queries/MatchAll.php b/src/DSL/Queries/MatchAll.php index 337b63f..74e4605 100644 --- a/src/DSL/Queries/MatchAll.php +++ b/src/DSL/Queries/MatchAll.php @@ -18,7 +18,7 @@ trait MatchAll * @param mixed $matchAll * @return $this */ - public function matchAll($matchAll = null) + public function matchAll($matchAll = null): static { return $this->addQuery(QMatchAll::create($matchAll)); } @@ -28,7 +28,7 @@ public function matchAll($matchAll = null) * * @return $this */ - public function matchNone() + public function matchNone(): static { return $this->addQuery(MatchNone::create()); } diff --git a/src/DSL/Queries/Script.php b/src/DSL/Queries/Script.php index 132637e..8a41289 100644 --- a/src/DSL/Queries/Script.php +++ b/src/DSL/Queries/Script.php @@ -16,44 +16,44 @@ class Script extends Node /** * The ID of a stored script. * - * @param string $id + * @param string $value * @return static */ - public function id(string $id): static + public function id(string $value): static { - return $this->addProperty('id', $id); + return $this->addProperty('id', $value); } /** * The script language. Defaults to painless. * - * @param string $lang + * @param string $value * @return static */ - public function lang(string $lang): static + public function lang(string $value): static { - return $this->addProperty('lang', $lang); + return $this->addProperty('lang', $value); } /** * The inline script source to execute. * - * @param string $source + * @param string $value * @return static */ - public function source(string $source): static + public function source(string $value): static { - return $this->addProperty('source', $source); + return $this->addProperty('source', $value); } /** * Named parameters passed into the script. * - * @param array $params + * @param array $value * @return static */ - public function params(array $params): static + public function params(array $value): static { - return $this->addProperty('params', $params); + return $this->addProperty('params', $value); } } diff --git a/src/DSL/Queries/Shape.php b/src/DSL/Queries/Shape.php index 1c2710a..ee708b8 100644 --- a/src/DSL/Queries/Shape.php +++ b/src/DSL/Queries/Shape.php @@ -18,7 +18,7 @@ trait Shape * @param mixed $value * @return $this */ - public function shape($field, $value = null) + public function shape($field, $value = null): static { return $this->addQuery(QShape::create($field, $value)); } diff --git a/src/DSL/Queries/Shape/Shape.php b/src/DSL/Queries/Shape/Shape.php index c0cc763..b1de24e 100644 --- a/src/DSL/Queries/Shape/Shape.php +++ b/src/DSL/Queries/Shape/Shape.php @@ -22,35 +22,35 @@ class Shape extends Node /** * Inline shape definition. Contains the shape type and coordinates. * - * @param mixed $shape + * @param mixed $value * @return static */ - public function shape($shape): static + public function shape($value): static { - return $this->addProperty('shape', $shape); + return $this->addProperty('shape', $value); } /** * Spatial relation operator to use at search time. * Valid values: INTERSECTS (default), DISJOINT, WITHIN, CONTAINS. * - * @param string $relation + * @param string $value * @return static */ - public function relation(string $relation): static + public function relation(string $value): static { - return $this->addProperty('relation', $relation); + return $this->addProperty('relation', $value); } /** * Reference to a pre-indexed shape. Contains id, index, path, and routing fields * to identify the shape document in another index. * - * @param mixed $indexedShape + * @param mixed $value * @return static */ - public function indexedShape($indexedShape): static + public function indexedShape($value): static { - return $this->addProperty('indexed_shape', $indexedShape); + return $this->addProperty('indexed_shape', $value); } } diff --git a/src/DSL/Queries/Span.php b/src/DSL/Queries/Span.php index c083640..111ef5c 100644 --- a/src/DSL/Queries/Span.php +++ b/src/DSL/Queries/Span.php @@ -26,7 +26,7 @@ trait Span * @param mixed $spanContaining * @return $this */ - public function spanContaining($spanContaining) + public function spanContaining($spanContaining): static { return $this->addQuery(SpanContaining::create($spanContaining)); } @@ -37,7 +37,7 @@ public function spanContaining($spanContaining) * @param mixed $spanFieldMasking * @return $this */ - public function spanFieldMasking($spanFieldMasking) + public function spanFieldMasking($spanFieldMasking): static { return $this->addQuery(SpanFieldMasking::create($spanFieldMasking)); } @@ -48,7 +48,7 @@ public function spanFieldMasking($spanFieldMasking) * @param mixed $spanFirst * @return $this */ - public function spanFirst($spanFirst) + public function spanFirst($spanFirst): static { return $this->addQuery(SpanFirst::create($spanFirst)); } @@ -59,7 +59,7 @@ public function spanFirst($spanFirst) * @param mixed $spanMulti * @return $this */ - public function spanMulti($spanMulti) + public function spanMulti($spanMulti): static { return $this->addQuery(SpanMulti::create($spanMulti)); } @@ -70,7 +70,7 @@ public function spanMulti($spanMulti) * @param mixed $spanNear * @return $this */ - public function spanNear($spanNear) + public function spanNear($spanNear): static { return $this->addQuery(SpanNear::create($spanNear)); } @@ -81,7 +81,7 @@ public function spanNear($spanNear) * @param mixed $spanNot * @return $this */ - public function spanNot($spanNot) + public function spanNot($spanNot): static { return $this->addQuery(SpanNot::create($spanNot)); } @@ -92,7 +92,7 @@ public function spanNot($spanNot) * @param mixed $spanOr * @return $this */ - public function spanOr($spanOr) + public function spanOr($spanOr): static { return $this->addQuery(SpanOr::create($spanOr)); } @@ -104,7 +104,7 @@ public function spanOr($spanOr) * @param mixed $value * @return $this */ - public function spanTerm($field, $value = null) + public function spanTerm($field, $value = null): static { return $this->addQuery(SpanTerm::create($field, $value)); } @@ -115,7 +115,7 @@ public function spanTerm($field, $value = null) * @param mixed $spanWithin * @return $this */ - public function spanWithin($spanWithin) + public function spanWithin($spanWithin): static { return $this->addQuery(SpanWithin::create($spanWithin)); } diff --git a/src/DSL/Queries/Span/SpanContaining.php b/src/DSL/Queries/Span/SpanContaining.php index 7f5e397..d2593fa 100644 --- a/src/DSL/Queries/Span/SpanContaining.php +++ b/src/DSL/Queries/Span/SpanContaining.php @@ -17,22 +17,22 @@ class SpanContaining extends Node /** * The little span query whose matches must be contained within the big span. * - * @param mixed $little + * @param mixed $value * @return static */ - public function little($little): static + public function little($value): static { - return $this->addProperty('little', Query::create($little)); + return $this->addProperty('little', Query::create($value)); } /** * The big span query that must contain matches from the little span. * - * @param mixed $big + * @param mixed $value * @return static */ - public function big($big): static + public function big($value): static { - return $this->addProperty('big', Query::create($big)); + return $this->addProperty('big', Query::create($value)); } } diff --git a/src/DSL/Queries/Span/SpanFieldMasking.php b/src/DSL/Queries/Span/SpanFieldMasking.php index 5be991e..458344d 100644 --- a/src/DSL/Queries/Span/SpanFieldMasking.php +++ b/src/DSL/Queries/Span/SpanFieldMasking.php @@ -17,11 +17,11 @@ class SpanFieldMasking extends Node /** * The inner span query to execute. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - return $this->addProperty('query', Query::create($query)); + return $this->addProperty('query', Query::create($value)); } } diff --git a/src/DSL/Queries/Span/SpanFirst.php b/src/DSL/Queries/Span/SpanFirst.php index fc21193..660b048 100644 --- a/src/DSL/Queries/Span/SpanFirst.php +++ b/src/DSL/Queries/Span/SpanFirst.php @@ -17,22 +17,22 @@ class SpanFirst extends Node /** * The inner span query whose matches are restricted. * - * @param mixed $match + * @param mixed $value * @return static */ - public function match($match): static + public function match($value): static { - return $this->addProperty('match', Query::create($match)); + return $this->addProperty('match', Query::create($value)); } /** * The maximum end position permitted for the span match. * - * @param int $end + * @param int $value * @return static */ - public function end(int $end): static + public function end(int $value): static { - return $this->addProperty('end', $end); + return $this->addProperty('end', $value); } } diff --git a/src/DSL/Queries/Span/SpanMulti.php b/src/DSL/Queries/Span/SpanMulti.php index ebe0ffe..61094f9 100644 --- a/src/DSL/Queries/Span/SpanMulti.php +++ b/src/DSL/Queries/Span/SpanMulti.php @@ -17,11 +17,11 @@ class SpanMulti extends Node /** * The non-span query to wrap as a span query. * - * @param mixed $match + * @param mixed $value * @return static */ - public function match($match): static + public function match($value): static { - return $this->addProperty('match', Query::create($match)); + return $this->addProperty('match', Query::create($value)); } } diff --git a/src/DSL/Queries/Span/SpanNear.php b/src/DSL/Queries/Span/SpanNear.php index c7b49a5..3cf7404 100644 --- a/src/DSL/Queries/Span/SpanNear.php +++ b/src/DSL/Queries/Span/SpanNear.php @@ -20,33 +20,33 @@ class SpanNear extends Node * The list of span query clauses that must appear near each other. * Supports multiple calls to incrementally build. * - * @param mixed $clauses + * @param mixed $value * @return static */ - public function clauses($clauses): static + public function clauses($value): static { - return $this->addClause('clauses', $clauses); + return $this->addClause('clauses', $value); } /** * The maximum number of positions allowed between matching spans. * - * @param int $slop + * @param int $value * @return static */ - public function slop(int $slop): static + public function slop(int $value): static { - return $this->addProperty('slop', $slop); + return $this->addProperty('slop', $value); } /** * Whether the span clauses must appear in their specified order. * - * @param bool $inOrder + * @param bool $value * @return static */ - public function inOrder(bool $inOrder): static + public function inOrder(bool $value): static { - return $this->addProperty('in_order', $inOrder); + return $this->addProperty('in_order', $value); } } diff --git a/src/DSL/Queries/Span/SpanNot.php b/src/DSL/Queries/Span/SpanNot.php index 785f810..9a7d34f 100644 --- a/src/DSL/Queries/Span/SpanNot.php +++ b/src/DSL/Queries/Span/SpanNot.php @@ -17,55 +17,55 @@ class SpanNot extends Node /** * The span query whose matches are included. * - * @param mixed $include + * @param mixed $value * @return static */ - public function include($include): static + public function include($value): static { - return $this->addProperty('include', Query::create($include)); + return $this->addProperty('include', Query::create($value)); } /** * The span query whose overlapping matches are excluded. * - * @param mixed $exclude + * @param mixed $value * @return static */ - public function exclude($exclude): static + public function exclude($value): static { - return $this->addProperty('exclude', Query::create($exclude)); + return $this->addProperty('exclude', Query::create($value)); } /** * The number of positions before the include span that must not overlap with the exclude span. * - * @param int $pre + * @param int $value * @return static */ - public function pre(int $pre): static + public function pre(int $value): static { - return $this->addProperty('pre', $pre); + return $this->addProperty('pre', $value); } /** * The number of positions after the include span that must not overlap with the exclude span. * - * @param int $post + * @param int $value * @return static */ - public function post(int $post): static + public function post(int $value): static { - return $this->addProperty('post', $post); + return $this->addProperty('post', $value); } /** * The number of positions both before and after the include span that must not overlap with the exclude span. * - * @param int $dist + * @param int $value * @return static */ - public function dist(int $dist): static + public function dist(int $value): static { - return $this->addProperty('dist', $dist); + return $this->addProperty('dist', $value); } } diff --git a/src/DSL/Queries/Span/SpanOr.php b/src/DSL/Queries/Span/SpanOr.php index 2da6c7d..1b7152d 100644 --- a/src/DSL/Queries/Span/SpanOr.php +++ b/src/DSL/Queries/Span/SpanOr.php @@ -20,11 +20,11 @@ class SpanOr extends Node * The list of span query clauses to combine. * Supports multiple calls to incrementally build. * - * @param mixed $clauses + * @param mixed $value * @return static */ - public function clauses($clauses): static + public function clauses($value): static { - return $this->addClause('clauses', $clauses); + return $this->addClause('clauses', $value); } } diff --git a/src/DSL/Queries/Span/SpanTerm.php b/src/DSL/Queries/Span/SpanTerm.php index 972f096..1a468e8 100644 --- a/src/DSL/Queries/Span/SpanTerm.php +++ b/src/DSL/Queries/Span/SpanTerm.php @@ -19,12 +19,12 @@ class SpanTerm extends Node /** * The value of the term to match. * - * @param string|int|float|bool $term + * @param string|int|float|bool $value * @return static */ - public function term(string|int|float|bool $term): static + public function term(string|int|float|bool $value): static { - return $this->addProperty('term', $term); + return $this->addProperty('term', $value); } /** diff --git a/src/DSL/Queries/Span/SpanWithin.php b/src/DSL/Queries/Span/SpanWithin.php index 08edb3e..2e63664 100644 --- a/src/DSL/Queries/Span/SpanWithin.php +++ b/src/DSL/Queries/Span/SpanWithin.php @@ -17,22 +17,22 @@ class SpanWithin extends Node /** * The little span query whose matches must fall within the big span. * - * @param mixed $little + * @param mixed $value * @return static */ - public function little($little): static + public function little($value): static { - return $this->addProperty('little', Query::create($little)); + return $this->addProperty('little', Query::create($value)); } /** * The big span query that must contain matches from the little span. * - * @param mixed $big + * @param mixed $value * @return static */ - public function big($big): static + public function big($value): static { - return $this->addProperty('big', Query::create($big)); + return $this->addProperty('big', Query::create($value)); } } diff --git a/src/DSL/Queries/Specialized.php b/src/DSL/Queries/Specialized.php index 1667af0..ea94d56 100644 --- a/src/DSL/Queries/Specialized.php +++ b/src/DSL/Queries/Specialized.php @@ -24,7 +24,7 @@ trait Specialized * @param mixed $distanceFeature * @return $this */ - public function distanceFeature($distanceFeature) + public function distanceFeature($distanceFeature): static { return $this->addQuery(DistanceFeature::create($distanceFeature)); } @@ -35,7 +35,7 @@ public function distanceFeature($distanceFeature) * @param mixed $moreLikeThis * @return $this */ - public function moreLikeThis($moreLikeThis) + public function moreLikeThis($moreLikeThis): static { return $this->addQuery(MoreLikeThis::create($moreLikeThis)); } @@ -46,7 +46,7 @@ public function moreLikeThis($moreLikeThis) * @param mixed $percolate * @return $this */ - public function percolate($percolate) + public function percolate($percolate): static { return $this->addQuery(Percolate::create($percolate)); } @@ -57,7 +57,7 @@ public function percolate($percolate) * @param mixed $rankFeature * @return $this */ - public function rankFeature($rankFeature) + public function rankFeature($rankFeature): static { return $this->addQuery(RankFeature::create($rankFeature)); } @@ -68,7 +68,7 @@ public function rankFeature($rankFeature) * @param mixed $script * @return $this */ - public function script($script) + public function script($script): static { return $this->addQuery(Script::create($script)); } @@ -79,7 +79,7 @@ public function script($script) * @param mixed $scriptScore * @return $this */ - public function scriptScore($scriptScore) + public function scriptScore($scriptScore): static { return $this->addQuery(ScriptScore::create($scriptScore)); } @@ -90,7 +90,7 @@ public function scriptScore($scriptScore) * @param mixed $wrapper * @return $this */ - public function wrapper($wrapper) + public function wrapper($wrapper): static { return $this->addQuery(Wrapper::create($wrapper)); } @@ -101,7 +101,7 @@ public function wrapper($wrapper) * @param mixed $pinned * @return $this */ - public function pinned($pinned) + public function pinned($pinned): static { return $this->addQuery(Pinned::create($pinned)); } diff --git a/src/DSL/Queries/Specialized/DistanceFeature.php b/src/DSL/Queries/Specialized/DistanceFeature.php index be85c11..7bd8715 100644 --- a/src/DSL/Queries/Specialized/DistanceFeature.php +++ b/src/DSL/Queries/Specialized/DistanceFeature.php @@ -16,22 +16,22 @@ class DistanceFeature extends Node /** * Location or date to use as the origin from which to calculate distance. * - * @param mixed $origin + * @param mixed $value * @return static */ - public function origin($origin): static + public function origin($value): static { - return $this->addProperty('origin', $origin); + return $this->addProperty('origin', $value); } /** * Distance from the origin at which relevance scores receive half of the boost value. * - * @param string $pivot + * @param string $value * @return static */ - public function pivot(string $pivot): static + public function pivot(string $value): static { - return $this->addProperty('pivot', $pivot); + return $this->addProperty('pivot', $value); } } diff --git a/src/DSL/Queries/Specialized/MoreLikeThis.php b/src/DSL/Queries/Specialized/MoreLikeThis.php index 4c7c6b1..f12b310 100644 --- a/src/DSL/Queries/Specialized/MoreLikeThis.php +++ b/src/DSL/Queries/Specialized/MoreLikeThis.php @@ -16,44 +16,44 @@ class MoreLikeThis extends Node /** * List of fields to use for similarity comparison. * - * @param array $array + * @param array $value * @return static */ - public function fields(array $array): static + public function fields(array $value): static { - return $this->addProperty('fields', $array); + return $this->addProperty('fields', $value); } /** * Text or documents to find similar documents for. * - * @param mixed $string + * @param mixed $value * @return static */ - public function like($string): static + public function like($value): static { - return $this->addProperty('like', $string); + return $this->addProperty('like', $value); } /** * Minimum term frequency below which terms are ignored. Defaults to 2. * - * @param int $int + * @param int $value * @return static */ - public function minTermFreq(int $int): static + public function minTermFreq(int $value): static { - return $this->addProperty('min_term_freq', $int); + return $this->addProperty('min_term_freq', $value); } /** * Maximum number of query terms to be selected per result document. Defaults to 25. * - * @param int $int + * @param int $value * @return static */ - public function maxQueryTerms(int $int): static + public function maxQueryTerms(int $value): static { - return $this->addProperty('max_query_terms', $int); + return $this->addProperty('max_query_terms', $value); } } diff --git a/src/DSL/Queries/Specialized/Percolate.php b/src/DSL/Queries/Specialized/Percolate.php index 61bf1a3..635d058 100644 --- a/src/DSL/Queries/Specialized/Percolate.php +++ b/src/DSL/Queries/Specialized/Percolate.php @@ -16,11 +16,11 @@ class Percolate extends Node /** * The source document to percolate against registered queries. * - * @param mixed $document + * @param mixed $value * @return static */ - public function document($document): static + public function document($value): static { - return $this->addProperty('document', $document); + return $this->addProperty('document', $value); } } diff --git a/src/DSL/Queries/Specialized/Pinned.php b/src/DSL/Queries/Specialized/Pinned.php index 361bebc..81c11a9 100644 --- a/src/DSL/Queries/Specialized/Pinned.php +++ b/src/DSL/Queries/Specialized/Pinned.php @@ -17,33 +17,33 @@ class Pinned extends Node /** * List of document IDs to pin to the top of the results. * - * @param array $ids + * @param array $value * @return static */ - public function ids(array $ids): static + public function ids(array $value): static { - return $this->addProperty('ids', $ids); + return $this->addProperty('ids', $value); } /** * The organic query used to rank non-pinned documents. * - * @param mixed $organic + * @param mixed $value * @return static */ - public function organic($organic): static + public function organic($value): static { - return $this->addProperty('organic', Query::create($organic)); + return $this->addProperty('organic', Query::create($value)); } /** * A document to pin instead of using an ID. * - * @param mixed $doc + * @param mixed $value * @return static */ - public function doc($doc): static + public function doc($value): static { - return $this->addProperty('doc', $doc); + return $this->addProperty('doc', $value); } } diff --git a/src/DSL/Queries/Specialized/RankFeature.php b/src/DSL/Queries/Specialized/RankFeature.php index 011b217..ed77d5b 100644 --- a/src/DSL/Queries/Specialized/RankFeature.php +++ b/src/DSL/Queries/Specialized/RankFeature.php @@ -16,44 +16,44 @@ class RankFeature extends Node /** * Saturation function to compute the score. Uses point: 2 by default. * - * @param mixed $saturation + * @param mixed $value * @return static */ - public function saturation($saturation): static + public function saturation($value): static { - return $this->addProperty('saturation', $saturation); + return $this->addProperty('saturation', $value); } /** * Logarithmic function to compute the score. Supports a scaling_factor parameter. * - * @param mixed $log + * @param mixed $value * @return static */ - public function log($log): static + public function log($value): static { - return $this->addProperty('log', $log); + return $this->addProperty('log', $value); } /** * Sigmoid function to compute the score. Requires exponent and pivot parameters. * - * @param mixed $sigmoid + * @param mixed $value * @return static */ - public function sigmoid($sigmoid): static + public function sigmoid($value): static { - return $this->addProperty('sigmoid', $sigmoid); + return $this->addProperty('sigmoid', $value); } /** * Linear function to compute the score, producing a linear relation between the feature value and the score. * - * @param mixed $linear + * @param mixed $value * @return static */ - public function linear($linear): static + public function linear($value): static { - return $this->addProperty('linear', $linear); + return $this->addProperty('linear', $value); } } diff --git a/src/DSL/Queries/Specialized/Script.php b/src/DSL/Queries/Specialized/Script.php index e670d0b..2c5cb2e 100644 --- a/src/DSL/Queries/Specialized/Script.php +++ b/src/DSL/Queries/Specialized/Script.php @@ -16,11 +16,11 @@ class Script extends Node /** * The script to use as the query filter. * - * @param mixed $script + * @param mixed $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', \ElasticKit\DSL\Queries\Script::create($script)); + return $this->addProperty('script', \ElasticKit\DSL\Queries\Script::create($value)); } } diff --git a/src/DSL/Queries/Specialized/ScriptScore.php b/src/DSL/Queries/Specialized/ScriptScore.php index aa9a94e..bcee851 100644 --- a/src/DSL/Queries/Specialized/ScriptScore.php +++ b/src/DSL/Queries/Specialized/ScriptScore.php @@ -17,33 +17,33 @@ class ScriptScore extends Node /** * The base query whose scores will be modified by the script. * - * @param mixed $query + * @param mixed $value * @return static */ - public function query($query): static + public function query($value): static { - return $this->addProperty('query', Query::create($query)); + return $this->addProperty('query', Query::create($value)); } /** * The script used to compute the new relevance score. * - * @param mixed $script + * @param mixed $value * @return static */ - public function script($script): static + public function script($value): static { - return $this->addProperty('script', \ElasticKit\DSL\Queries\Script::create($script)); + return $this->addProperty('script', \ElasticKit\DSL\Queries\Script::create($value)); } /** * Minimum relevance score threshold. Documents with a lower score are excluded. * - * @param float $minScore + * @param float $value * @return static */ - public function minScore(float $minScore): static + public function minScore(float $value): static { - return $this->addProperty('min_score', Query::create($minScore)); + return $this->addProperty('min_score', Query::create($value)); } } diff --git a/src/DSL/Queries/Specialized/Wrapper.php b/src/DSL/Queries/Specialized/Wrapper.php index 84335df..48c83c7 100644 --- a/src/DSL/Queries/Specialized/Wrapper.php +++ b/src/DSL/Queries/Specialized/Wrapper.php @@ -34,11 +34,11 @@ public static function create($field = null, $value = null): static /** * A query in base64 encoded format. * - * @param string $query + * @param string $value * @return static */ - public function query(string $query): static + public function query(string $value): static { - return $this->addProperty('query', $query); + return $this->addProperty('query', $value); } } diff --git a/src/DSL/Queries/TermLevel.php b/src/DSL/Queries/TermLevel.php index 946130d..2b1583a 100644 --- a/src/DSL/Queries/TermLevel.php +++ b/src/DSL/Queries/TermLevel.php @@ -34,7 +34,7 @@ trait TermLevel * @param mixed $value * @return $this */ - public function fuzzy($field, $value = null) + public function fuzzy($field, $value = null): static { return $this->addQuery(Fuzzy::create($field, $value)); } @@ -52,7 +52,7 @@ public function fuzzy($field, $value = null) * @param mixed $field * @return $this */ - public function exists($field) + public function exists($field): static { return $this->addQuery(Exists::create($field)); } @@ -63,7 +63,7 @@ public function exists($field) * @param mixed $ids * @return $this */ - public function ids($ids) + public function ids($ids): static { if (is_array($ids) && !isset($ids['values'])) { $ids = ['values' => $ids]; @@ -78,7 +78,7 @@ public function ids($ids) * @param mixed $value * @return $this */ - public function prefix($field, $value = null) + public function prefix($field, $value = null): static { return $this->addQuery(Prefix::create($field, $value)); } @@ -93,7 +93,7 @@ public function prefix($field, $value = null) * @param callable|array $value * @return $this */ - public function range($field, $value = null) + public function range($field, $value = null): static { return $this->addQuery(Range::create($field, $value)); } @@ -105,7 +105,7 @@ public function range($field, $value = null) * @param mixed $value * @return $this */ - public function regexp($field, $value = null) + public function regexp($field, $value = null): static { return $this->addQuery(Regexp::create($field, $value)); } @@ -119,7 +119,7 @@ public function regexp($field, $value = null) * @param callable|string|array $value * @return $this */ - public function term($field, $value = null) + public function term($field, $value = null): static { return $this->addQuery(Term::create($field, $value)); } @@ -134,7 +134,7 @@ public function term($field, $value = null) * @param mixed $value * @return $this */ - public function terms($field, $value = null) + public function terms($field, $value = null): static { return $this->addQuery(Terms::create($field, $value)); } @@ -151,7 +151,7 @@ public function terms($field, $value = null) * @param mixed $value * @return $this */ - public function termsSet($field, $value = null) + public function termsSet($field, $value = null): static { return $this->addQuery(TermsSet::create($field, $value)); } @@ -165,7 +165,7 @@ public function termsSet($field, $value = null) * @param mixed $value * @return $this */ - public function wildcard($field, $value = null) + public function wildcard($field, $value = null): static { return $this->addQuery(Wildcard::create($field, $value)); } diff --git a/src/DSL/Queries/TermLevel/Fuzzy.php b/src/DSL/Queries/TermLevel/Fuzzy.php index 47301da..33a5fd0 100644 --- a/src/DSL/Queries/TermLevel/Fuzzy.php +++ b/src/DSL/Queries/TermLevel/Fuzzy.php @@ -26,55 +26,55 @@ public function value(string $value): static /** * Maximum edit distance allowed for matching. See Fuzziness for valid values and more information. * - * @param int|string $fuzziness + * @param int|string $value * @return static */ - public function fuzziness(int|string $fuzziness): static + public function fuzziness(int|string $value): static { - return $this->addProperty('fuzziness', $fuzziness); + return $this->addProperty('fuzziness', $value); } /** * Maximum number of variations created. Defaults to 50. * - * @param int $maxExpansions + * @param int $value * @return static */ - public function maxExpansions(int $maxExpansions): static + public function maxExpansions(int $value): static { - return $this->addProperty('max_expansions', $maxExpansions); + return $this->addProperty('max_expansions', $value); } /** * Number of beginning characters left unchanged when creating expansions. Defaults to 0. * - * @param int $prefixLength + * @param int $value * @return static */ - public function prefixLength(int $prefixLength): static + public function prefixLength(int $value): static { - return $this->addProperty('prefix_length', $prefixLength); + return $this->addProperty('prefix_length', $value); } /** * Indicates whether edits include transpositions of two adjacent characters (ab → ba). Defaults to true. * - * @param bool $transpositions + * @param bool $value * @return static */ - public function transpositions(bool $transpositions): static + public function transpositions(bool $value): static { - return $this->addProperty('transpositions', $transpositions); + return $this->addProperty('transpositions', $value); } /** * Method used to rewrite the query. For valid values and more information, see the rewrite parameter. * - * @param string $rewrite + * @param string $value * @return static */ - public function rewrite(string $rewrite): static + public function rewrite(string $value): static { - return $this->addProperty('rewrite', $rewrite); + return $this->addProperty('rewrite', $value); } } diff --git a/src/DSL/Queries/TermLevel/IDs.php b/src/DSL/Queries/TermLevel/IDs.php index 73efe22..fcab3a4 100644 --- a/src/DSL/Queries/TermLevel/IDs.php +++ b/src/DSL/Queries/TermLevel/IDs.php @@ -16,11 +16,11 @@ class IDs extends Node /** * An array of document IDs. * - * @param array $values + * @param array $value * @return static */ - public function values(array $values): static + public function values(array $value): static { - return $this->addProperty('values', $values); + return $this->addProperty('values', $value); } } diff --git a/src/DSL/Queries/TermLevel/Prefix.php b/src/DSL/Queries/TermLevel/Prefix.php index 6f6305a..eec7485 100644 --- a/src/DSL/Queries/TermLevel/Prefix.php +++ b/src/DSL/Queries/TermLevel/Prefix.php @@ -26,22 +26,22 @@ public function value(string $value): static /** * Method used to rewrite the query. For valid values and more information, see the rewrite parameter. * - * @param string $rewrite + * @param string $value * @return static */ - public function rewrite(string $rewrite): static + public function rewrite(string $value): static { - return $this->addProperty('rewrite', $rewrite); + return $this->addProperty('rewrite', $value); } /** * Allows ASCII case insensitive matching of the value with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping. * - * @param bool $caseInsensitive + * @param bool $value * @return static */ - public function caseInsensitive(bool $caseInsensitive): static + public function caseInsensitive(bool $value): static { - return $this->addProperty('case_insensitive', $caseInsensitive); + return $this->addProperty('case_insensitive', $value); } } diff --git a/src/DSL/Queries/TermLevel/Range.php b/src/DSL/Queries/TermLevel/Range.php index 9686872..dc2192f 100644 --- a/src/DSL/Queries/TermLevel/Range.php +++ b/src/DSL/Queries/TermLevel/Range.php @@ -18,45 +18,45 @@ class Range extends Node /** * Greater than or equal to. * - * @param string|int|float|bool $gte + * @param string|int|float|bool $value * @return static */ - public function gte(string|int|float|bool $gte): static + public function gte(string|int|float|bool $value): static { - return $this->addProperty('gte', $gte); + return $this->addProperty('gte', $value); } /** * Greater than. * - * @param string|int|float|bool $gt + * @param string|int|float|bool $value * @return static */ - public function gt(string|int|float|bool $gt): static + public function gt(string|int|float|bool $value): static { - return $this->addProperty('gt', $gt); + return $this->addProperty('gt', $value); } /** * Less than or equal to. * - * @param string|int|float|bool $lte + * @param string|int|float|bool $value * @return static */ - public function lte(string|int|float|bool $lte): static + public function lte(string|int|float|bool $value): static { - return $this->addProperty('lte', $lte); + return $this->addProperty('lte', $value); } /** * Less than. * - * @param string|int|float|bool $lt + * @param string|int|float|bool $value * @return static */ - public function lt(string|int|float|bool $lt): static + public function lt(string|int|float|bool $value): static { - return $this->addProperty('lt', $lt); + return $this->addProperty('lt', $value); } /** @@ -68,12 +68,12 @@ public function lt(string|int|float|bool $lt): static * * If a format or date value is incomplete, the range query replaces any missing components with default values. See Missing date components. * - * @param string $format + * @param string $value * @return static */ - public function format(string $format): static + public function format(string $value): static { - return $this->addProperty('format', $format); + return $this->addProperty('format', $value); } /** @@ -86,22 +86,22 @@ public function format(string $format): static * WITHIN * Matches documents with a range field value entirely within the query’s range. * - * @param string $relation + * @param string $value * @return static */ - public function relation(string $relation): static + public function relation(string $value): static { - return $this->addProperty('relation', $relation); + return $this->addProperty('relation', $value); } /** * Coordinated Universal Time (UTC) offset or IANA time zone used to convert date values in the query to UTC. * - * @param string $timeZone + * @param string $value * @return static */ - public function timeZone(string $timeZone): static + public function timeZone(string $value): static { - return $this->addProperty('time_zone', $timeZone); + return $this->addProperty('time_zone', $value); } } diff --git a/src/DSL/Queries/TermLevel/Regexp.php b/src/DSL/Queries/TermLevel/Regexp.php index f8db581..f7d9a83 100644 --- a/src/DSL/Queries/TermLevel/Regexp.php +++ b/src/DSL/Queries/TermLevel/Regexp.php @@ -30,23 +30,23 @@ public function value(string $value): static /** * Enables optional operators for the regular expression. For valid values and more information, see Regular expression syntax. * - * @param string $flags + * @param string $value * @return static */ - public function flags(string $flags): static + public function flags(string $value): static { - return $this->addProperty('flags', $flags); + return $this->addProperty('flags', $value); } /** * Allows case insensitive matching of the regular expression value with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping. * - * @param bool $caseInsensitive + * @param bool $value * @return static */ - public function caseInsensitive(bool $caseInsensitive): static + public function caseInsensitive(bool $value): static { - return $this->addProperty('case_insensitive', $caseInsensitive); + return $this->addProperty('case_insensitive', $value); } /** @@ -56,22 +56,22 @@ public function caseInsensitive(bool $caseInsensitive): static * * You can use this parameter to prevent that conversion from unintentionally consuming too many resources. You may need to increase this limit to run complex regular expressions. * - * @param int $maxDeterminizedStates + * @param int $value * @return static */ - public function maxDeterminizedStates(int $maxDeterminizedStates): static + public function maxDeterminizedStates(int $value): static { - return $this->addProperty('max_determinized_states', $maxDeterminizedStates); + return $this->addProperty('max_determinized_states', $value); } /** * Method used to rewrite the query. For valid values and more information, see the rewrite parameter. * - * @param string $rewrite + * @param string $value * @return static */ - public function rewrite(string $rewrite): static + public function rewrite(string $value): static { - return $this->addProperty('rewrite', $rewrite); + return $this->addProperty('rewrite', $value); } } diff --git a/src/DSL/Queries/TermLevel/Term.php b/src/DSL/Queries/TermLevel/Term.php index 1ab8da5..ad4f0e8 100644 --- a/src/DSL/Queries/TermLevel/Term.php +++ b/src/DSL/Queries/TermLevel/Term.php @@ -38,12 +38,12 @@ public function value(string|int|float|bool $value): static * * Allows ASCII case insensitive matching of the value with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping. * - * @param bool $caseInsensitive + * @param bool $value * @return static * @version 7.10.0 */ - public function caseInsensitive(bool $caseInsensitive): static + public function caseInsensitive(bool $value): static { - return $this->addProperty('case_insensitive', $caseInsensitive); + return $this->addProperty('case_insensitive', $value); } } diff --git a/src/DSL/Queries/TermLevel/TermsSet.php b/src/DSL/Queries/TermLevel/TermsSet.php index 470f82f..1c60488 100644 --- a/src/DSL/Queries/TermLevel/TermsSet.php +++ b/src/DSL/Queries/TermLevel/TermsSet.php @@ -21,12 +21,12 @@ class TermsSet extends Node * * The required number of matching terms is defined in the minimum_should_match, minimum_should_match_field or minimum_should_match_script parameters. Exactly one of these parameters must be provided. * - * @param array $terms + * @param array $value * @return static */ - public function terms(array $terms): static + public function terms(array $value): static { - return $this->addProperty('terms', $terms); + return $this->addProperty('terms', $value); } /** @@ -34,21 +34,21 @@ public function terms(array $terms): static * * For valid values, see minimum_should_match parameter. * - * @param int|string $minimumShouldMatch + * @param int|string $value * @return static */ - public function minimumShouldMatch(int|string $minimumShouldMatch): static + public function minimumShouldMatch(int|string $value): static { - return $this->addProperty('minimum_should_match', $minimumShouldMatch); + return $this->addProperty('minimum_should_match', $value); } /** - * @param string $field + * @param string $value * @return static */ - public function minimumShouldMatchField(string $field): static + public function minimumShouldMatchField(string $value): static { - return $this->addProperty('minimum_should_match_field', $field); + return $this->addProperty('minimum_should_match_field', $value); } /** @@ -58,11 +58,11 @@ public function minimumShouldMatchField(string $field): static * * For an example query using the minimum_should_match_script parameter, see How to use the minimum_should_match_script parameter. * - * @param mixed $minimumShouldMatchScript + * @param mixed $value * @return static */ - public function minimumShouldMatchScript($minimumShouldMatchScript): static + public function minimumShouldMatchScript($value): static { - return $this->addProperty('minimum_should_match_script', Script::create($minimumShouldMatchScript)); + return $this->addProperty('minimum_should_match_script', Script::create($value)); } } diff --git a/src/DSL/Queries/TermLevel/Wildcard.php b/src/DSL/Queries/TermLevel/Wildcard.php index 1efa192..88c6d69 100644 --- a/src/DSL/Queries/TermLevel/Wildcard.php +++ b/src/DSL/Queries/TermLevel/Wildcard.php @@ -15,24 +15,24 @@ class Wildcard extends Node /** * Allows case insensitive matching of the pattern with the indexed field values when set to true. Default is false which means the case sensitivity of matching depends on the underlying field’s mapping. * - * @param bool $caseInsensitive + * @param bool $value * @return static * @version 7.10.0 */ - public function caseInsensitive(bool $caseInsensitive): static + public function caseInsensitive(bool $value): static { - return $this->addProperty('case_insensitive', $caseInsensitive); + return $this->addProperty('case_insensitive', $value); } /** * Method used to rewrite the query. For valid values and more information, see the rewrite parameter. * - * @param string $rewrite + * @param string $value * @return static */ - public function rewrite(string $rewrite): static + public function rewrite(string $value): static { - return $this->addProperty('rewrite', $rewrite); + return $this->addProperty('rewrite', $value); } /** @@ -55,11 +55,11 @@ public function value(string $value): static /** * An alias for the value parameter. If you specify both value and wildcard, the query uses the last one in the request body. * - * @param string $wildcard + * @param string $value * @return static */ - public function wildcard(string $wildcard): static + public function wildcard(string $value): static { - return $this->addProperty('wildcard', $wildcard); + return $this->addProperty('wildcard', $value); } } diff --git a/src/DSL/Query.php b/src/DSL/Query.php index 8ce35cd..c6f0d63 100644 --- a/src/DSL/Query.php +++ b/src/DSL/Query.php @@ -51,24 +51,14 @@ class Query extends Node * * @var array */ - protected $_queries = []; + protected array $_queries = []; /** * Aggregation nodes stored independently from type properties. * * @var array */ - protected $_aggregations = []; - - /** - * Whether the query supports multiple clauses. - * - * @return bool - */ - protected function isMulti(): bool - { - return $this->_multi; - } + protected array $_aggregations = []; /** * Initialize the query container. @@ -128,12 +118,12 @@ public function getQueries(): array /** * Add a query clause to the query container. * - * @param mixed $query + * @param mixed $value * @return $this */ - public function addQuery($query): static + public function addQuery($value): static { - $this->_queries[] = $query; + $this->_queries[] = $value; return $this; } @@ -231,8 +221,8 @@ public function toArray(): array $dsl['query'] = $query; } - $this->buildAggs($dsl); - $this->buildParams($dsl); + $dsl = $this->buildAggs($dsl); + $dsl = $this->buildParams($dsl); return array_filter($dsl, function ($v) { return $v !== []; @@ -242,9 +232,9 @@ public function toArray(): array /** * Build the query clause array from stored query clauses. * - * @return array|object + * @return array|object */ - private function buildQuery() + private function buildQuery(): array|object { if (empty($this->_queries)) { return $this->_multi ? (object)[] : []; @@ -277,7 +267,7 @@ private function buildQuery() } if ($this->_multi) { - return $clauses; // @phpstan-ignore return.type + return $clauses; } if (empty($clauses)) { return []; @@ -289,26 +279,27 @@ private function buildQuery() * Build aggregation entries into the DSL array. * * @param array $dsl - * @return void + * @return array */ - private function buildAggs(array &$dsl): void + private function buildAggs(array $dsl): array { if (empty($this->_aggregations)) { - return; + return $dsl; } $dsl['aggs'] = []; foreach ($this->_aggregations as $agg) { $dsl['aggs'] += $agg->toArray(); } + return $dsl; } /** * Build search request parameters into the DSL array. * * @param array $dsl - * @return void + * @return array */ - private function buildParams(array &$dsl): void + private function buildParams(array $dsl): array { foreach ($this->_params as $key => $value) { if ($value instanceof Query) { @@ -320,5 +311,6 @@ private function buildParams(array &$dsl): void } $dsl[$key] = $value; } + return $dsl; } } diff --git a/src/DSL/Support/ClausesSupport.php b/src/DSL/Support/ClausesSupport.php index 8a45877..7c28048 100644 --- a/src/DSL/Support/ClausesSupport.php +++ b/src/DSL/Support/ClausesSupport.php @@ -22,7 +22,7 @@ trait ClausesSupport * @param mixed $clause * @return static */ - protected function addClause(string $key, $clause) + protected function addClause(string $key, $clause): static { if (!isset($this->_properties[$key])) { $this->_properties[$key] = (new Query())->multi(true); diff --git a/src/DSL/Support/RangeSupport.php b/src/DSL/Support/RangeSupport.php index 723ba39..6a35899 100644 --- a/src/DSL/Support/RangeSupport.php +++ b/src/DSL/Support/RangeSupport.php @@ -29,7 +29,7 @@ public function __construct($field = null, $value = null) * @param array $props * @return array */ - private static function normalizeKeys(array $props) + private static function normalizeKeys(array $props): array { $operators = [ '>=' => 'gte', '>' => 'gt', '<=' => 'lte', '<' => 'lt', From f7cb826d824668ab8f507cd9f7ffae222ed65819 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 19 Jun 2026 01:26:51 +0800 Subject: [PATCH 18/24] =?UTF-8?q?feat(query):=20=E6=96=B0=E5=A2=9E=20inter?= =?UTF-8?q?vals=20regexp=20=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补全 intervals 查询缺失的 regexp 规则,对齐 ES 文档顺序置于 wildcard 与 fuzzy 之间。新增 Regexp leaf(pattern/analyzer/useField)。 Co-Authored-By: Claude --- src/DSL/Queries/FullText/Intervals.php | 19 ++++++- src/DSL/Queries/FullText/Intervals/Regexp.php | 55 +++++++++++++++++++ tests/FullTextQueriesTest.php | 24 ++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/DSL/Queries/FullText/Intervals/Regexp.php diff --git a/src/DSL/Queries/FullText/Intervals.php b/src/DSL/Queries/FullText/Intervals.php index af4edf0..198f6ec 100644 --- a/src/DSL/Queries/FullText/Intervals.php +++ b/src/DSL/Queries/FullText/Intervals.php @@ -23,12 +23,12 @@ class Intervals extends Node /** * Add a match rule that matches analyzed text. * - * @param mixed $match + * @param mixed $value * @return static */ - public function match($match): static + public function match($value): static { - $this->_intervals[] = Intervals\Match_::create($match); + $this->_intervals[] = Intervals\Match_::create($value); return $this; } @@ -57,6 +57,19 @@ public function wildcard($value): static return $this; } + /** + * Add a regexp rule that matches terms using a regular expression + * pattern. + * + * @param mixed $value + * @return static + */ + public function regexp($value): static + { + $this->_intervals[] = Intervals\Regexp::create($value); + return $this; + } + /** * Add a fuzzy rule that matches terms that are similar to the provided * term, within a defined edit distance. diff --git a/src/DSL/Queries/FullText/Intervals/Regexp.php b/src/DSL/Queries/FullText/Intervals/Regexp.php new file mode 100644 index 0000000..306cbbe --- /dev/null +++ b/src/DSL/Queries/FullText/Intervals/Regexp.php @@ -0,0 +1,55 @@ +addProperty('pattern', $value); + } + + /** + * Analyzer used to normalize the pattern. Defaults to + * the top-level field's analyzer. + * + * @param string $value + * @return static + */ + public function analyzer(string $value): static + { + return $this->addProperty('analyzer', $value); + } + + /** + * If specified, match intervals from this field rather + * than the top-level field. The pattern is normalized using the search + * analyzer from this field. + * + * @param string $value + * @return static + */ + public function useField(string $value): static + { + return $this->addProperty('use_field', $value); + } +} diff --git a/tests/FullTextQueriesTest.php b/tests/FullTextQueriesTest.php index 054e72e..5d07a84 100644 --- a/tests/FullTextQueriesTest.php +++ b/tests/FullTextQueriesTest.php @@ -503,6 +503,30 @@ public function testIntervalsWildcard() $this->assertQuery($exampleJson, $query); } + public function testIntervalsRegexp() + { + $exampleJson = <<intervals('my_text', function (Intervals $intervals) { + $intervals->regexp(function (Intervals\Regexp $r) { + $r->pattern('h[ao]t'); + }); + }); + $this->assertQuery($exampleJson, $query); + } + public function testIntervalsRange() { $exampleJson = << Date: Fri, 19 Jun 2026 01:27:09 +0800 Subject: [PATCH 19/24] =?UTF-8?q?refactor(dsl):=20=E7=BB=9F=E4=B8=80=20non?= =?UTF-8?q?-leaf=20=E5=B1=82=E5=8F=82=E6=95=B0=E5=91=BD=E5=90=8D=E4=B8=8E?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 延续 2e18121(leaf setter 统一为 $value),将参数命名推广到 Query/Param/Agg/Function 等 non-leaf 层及全部 builder trait: - Param:26 个单参 setter 改 $value;sort() 改纯追加语义;indices_boost 改追加模式(链式多次调用累加而非覆盖);sort docblock 修正 - Agg:$subAggs → $_subAggs;node/alias/toArray 补类型声明 - trait(Compound/Span/Specialized/FullText/Joining/MatchAll/TermLevel/Aggs):单参 builder 统一 $value;Bucket::filter 同步 - Function_:4 个 decay 方法第二参改 $value Co-Authored-By: Claude --- src/DSL/Agg.php | 24 +-- src/DSL/Aggs/Bucket.php | 180 +++++++++--------- src/DSL/Aggs/Metric.php | 48 ++--- src/DSL/Aggs/Pipeline.php | 48 ++--- src/DSL/Node.php | 4 +- src/DSL/Param.php | 172 +++++++++-------- src/DSL/Queries/Compound.php | 46 ++--- .../Queries/Compound/Functions/Function_.php | 24 +-- src/DSL/Queries/FullText.php | 12 +- src/DSL/Queries/FullText/Intervals/AllOf.php | 2 - src/DSL/Queries/FullText/Intervals/AnyOf.php | 2 - src/DSL/Queries/Joining.php | 6 +- src/DSL/Queries/MatchAll.php | 6 +- src/DSL/Queries/Span.php | 48 ++--- src/DSL/Queries/Specialized.php | 48 ++--- src/DSL/Queries/TermLevel.php | 10 +- src/DSL/Query.php | 8 +- tests/ParamsTest.php | 20 ++ 18 files changed, 365 insertions(+), 343 deletions(-) diff --git a/src/DSL/Agg.php b/src/DSL/Agg.php index 7e41b01..fd27e51 100644 --- a/src/DSL/Agg.php +++ b/src/DSL/Agg.php @@ -35,7 +35,7 @@ class Agg * * @var array */ - protected array $subAggs = []; + protected array $_subAggs = []; /** * Properties for array-based aggregation definitions (raw DSL mode). @@ -81,7 +81,7 @@ public static function create($agg = []): static * @param Node $node * @return $this */ - protected function node($node): static + protected function node(Node $node): static { $this->_node = $node; $this->_properties = null; @@ -97,7 +97,7 @@ protected function node($node): static * @param string $value * @return $this */ - public function alias($value): static + public function alias(string $value): static { $this->_alias = $value; return $this; @@ -137,7 +137,7 @@ public function aggs($alias, $aggs = null): static if ($alias !== null) { $aggs->alias($alias); } - $this->subAggs[$alias ?? $aggs->getAlias()] = $aggs; + $this->_subAggs[$alias ?? $aggs->getAlias()] = $aggs; return $this; } @@ -146,17 +146,17 @@ public function aggs($alias, $aggs = null): static if ($alias !== null) { $childAgg->alias($alias); } - $this->subAggs[$alias] = $childAgg; + $this->_subAggs[$alias] = $childAgg; return $this; } - if ($alias !== null && !isset($this->subAggs[$alias])) { - $this->subAggs[$alias] = new Agg(); - $this->subAggs[$alias]->alias($alias); + if ($alias !== null && !isset($this->_subAggs[$alias])) { + $this->_subAggs[$alias] = new Agg(); + $this->_subAggs[$alias]->alias($alias); } if ($aggs instanceof \Closure) { - $aggs($this->subAggs[$alias]); + $aggs($this->_subAggs[$alias]); return $this; } @@ -197,7 +197,7 @@ protected function resolveProperties(array $properties): array * * @return array */ - public function toArray() + public function toArray(): array { if ($this->_properties !== null) { $resolved = $this->resolveProperties($this->_properties); @@ -213,9 +213,9 @@ public function toArray() $inner[$this->_node->key()] = $this->_node->toArray(); } - if (!empty($this->subAggs)) { + if (!empty($this->_subAggs)) { $inner['aggs'] = []; - foreach ($this->subAggs as $subAgg) { + foreach ($this->_subAggs as $subAgg) { $inner['aggs'] += $subAgg->toArray(); } } diff --git a/src/DSL/Aggs/Bucket.php b/src/DSL/Aggs/Bucket.php index 99fdb00..7519c2a 100644 --- a/src/DSL/Aggs/Bucket.php +++ b/src/DSL/Aggs/Bucket.php @@ -41,168 +41,168 @@ trait Bucket /** * Groups documents by field values into buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function terms($params): static + public function terms($value): static { - return $this->node(Terms::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Terms::create(is_string($value) ? ['field' => $value] : $value)); } /** * Defines a single bucket that limits documents matching a query. * - * @param mixed $filter + * @param mixed $value * @return static */ - public function filter($filter): static + public function filter($value): static { $instance = new Filter(); - $instance->filter($filter); + $instance->filter($value); return $this->node($instance); } /** * Defines multiple buckets from multiple filters, one per filter expression. * - * @param mixed $params + * @param mixed $value * @return static */ - public function filters($params): static + public function filters($value): static { - return $this->node(Filters::create($params)); + return $this->node(Filters::create($value)); } /** * Groups documents into buckets based on combinations of filter expressions. * - * @param mixed $params + * @param mixed $value * @return static */ - public function adjacencyMatrix($params): static + public function adjacencyMatrix($value): static { - return $this->node(AdjacencyMatrix::create($params)); + return $this->node(AdjacencyMatrix::create($value)); } /** * Automatically determines bucket intervals for date fields based on document count. * - * @param mixed $params + * @param mixed $value * @return static */ - public function autoDateHistogram($params): static + public function autoDateHistogram($value): static { - return $this->node(AutoDateHistogram::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(AutoDateHistogram::create(is_string($value) ? ['field' => $value] : $value)); } /** * Extracts categories from text fields by tokenizing and grouping values. * - * @param mixed $params + * @param mixed $value * @return static */ - public function categorizeText($params): static + public function categorizeText($value): static { - return $this->node(CategorizeText::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(CategorizeText::create(is_string($value) ? ['field' => $value] : $value)); } /** * Creates composite buckets from multiple source values, supporting pagination. * - * @param mixed $params + * @param mixed $value * @return static */ - public function composite($params): static + public function composite($value): static { - return $this->node(Composite::create($params)); + return $this->node(Composite::create($value)); } /** * Groups documents into buckets by date interval (e.g. per day, per month). * - * @param mixed $params + * @param mixed $value * @return static */ - public function dateHistogram($params): static + public function dateHistogram($value): static { - return $this->node(DateHistogram::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(DateHistogram::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into buckets by user-defined date ranges. * - * @param mixed $params + * @param mixed $value * @return static */ - public function dateRange($params): static + public function dateRange($value): static { - return $this->node(DateRange::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(DateRange::create(is_string($value) ? ['field' => $value] : $value)); } /** * Limits any child aggregations to a diversified sample of top-scoring documents. * - * @param mixed $params + * @param mixed $value * @return static */ - public function diversifiedSampler($params): static + public function diversifiedSampler($value): static { - return $this->node(DiversifiedSampler::create($params)); + return $this->node(DiversifiedSampler::create($value)); } /** * Finds frequently co-occurring item sets in array fields. * - * @param mixed $params + * @param mixed $value * @return static */ - public function frequentItemSets($params): static + public function frequentItemSets($value): static { - return $this->node(FrequentItemSets::create($params)); + return $this->node(FrequentItemSets::create($value)); } /** * Groups documents into buckets by distance ranges from a geo point. * - * @param mixed $params + * @param mixed $value * @return static */ - public function geoDistance($params): static + public function geoDistance($value): static { - return $this->node(GeoDistance::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(GeoDistance::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into grid cells using geohash prefixes. * - * @param mixed $params + * @param mixed $value * @return static */ - public function geoHashGrid($params): static + public function geoHashGrid($value): static { - return $this->node(GeoHashGrid::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(GeoHashGrid::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into grid cells using H3 hexagon indexes. * - * @param mixed $params + * @param mixed $value * @return static */ - public function geohexGrid($params): static + public function geohexGrid($value): static { - return $this->node(GeohexGrid::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(GeohexGrid::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into grid cells using geotile prefixes. * - * @param mixed $params + * @param mixed $value * @return static */ - public function geotileGrid($params): static + public function geotileGrid($value): static { - return $this->node(GeotileGrid::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(GeotileGrid::create(is_string($value) ? ['field' => $value] : $value)); } /** @@ -218,165 +218,165 @@ public function global(): static /** * Groups documents into buckets by numeric interval. * - * @param mixed $params + * @param mixed $value * @return static */ - public function histogram($params): static + public function histogram($value): static { - return $this->node(Histogram::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Histogram::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into buckets by IP address prefix. * - * @param mixed $params + * @param mixed $value * @return static */ - public function ipPrefix($params): static + public function ipPrefix($value): static { - return $this->node(IpPrefix::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(IpPrefix::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into buckets by user-defined IP address ranges. * - * @param mixed $params + * @param mixed $value * @return static */ - public function ipRange($params): static + public function ipRange($value): static { - return $this->node(IpRange::create($params)); + return $this->node(IpRange::create($value)); } /** * Creates a single bucket for documents missing a field value. * - * @param mixed $params + * @param mixed $value * @return static */ - public function missing($params): static + public function missing($value): static { - return $this->node(Missing::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Missing::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into buckets by multiple field term combinations. * - * @param mixed $params + * @param mixed $value * @return static */ - public function multiTerms($params): static + public function multiTerms($value): static { - return $this->node(MultiTerms::create($params)); + return $this->node(MultiTerms::create($value)); } /** * Aggregates on nested documents within a parent document. * - * @param mixed $params + * @param mixed $value * @return static */ - public function nested($params): static + public function nested($value): static { - return $this->node(Nested::create($params)); + return $this->node(Nested::create($value)); } /** * Aggregates on parent documents from a child document context in a join relation. * - * @param mixed $params + * @param mixed $value * @return static */ - public function parent($params): static + public function parent($value): static { - return $this->node(Parent_::create($params)); + return $this->node(Parent_::create($value)); } /** * Limits any child aggregations to a random sample of documents. * - * @param mixed $params + * @param mixed $value * @return static */ - public function randomSampler($params): static + public function randomSampler($value): static { - return $this->node(RandomSampler::create($params)); + return $this->node(RandomSampler::create($value)); } /** * Groups documents into buckets by user-defined numeric ranges. * - * @param mixed $params + * @param mixed $value * @return static */ - public function range($params): static + public function range($value): static { - return $this->node(Range::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Range::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into buckets by rare field values with low document counts. * - * @param mixed $params + * @param mixed $value * @return static */ - public function rareTerms($params): static + public function rareTerms($value): static { - return $this->node(RareTerms::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(RareTerms::create(is_string($value) ? ['field' => $value] : $value)); } /** * Aggregates on parent documents from within a nested aggregation context. * - * @param mixed $params + * @param mixed $value * @return static */ - public function reverseNested($params = []): static + public function reverseNested($value = []): static { - return $this->node(ReverseNested::create($params)); + return $this->node(ReverseNested::create($value)); } /** * Finds field values that are unusually common in a subset compared to the whole index. * - * @param mixed $params + * @param mixed $value * @return static */ - public function significantTerms($params): static + public function significantTerms($value): static { - return $this->node(SignificantTerms::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(SignificantTerms::create(is_string($value) ? ['field' => $value] : $value)); } /** * Finds significant terms from text field content without needing a sub-field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function significantText($params): static + public function significantText($value): static { - return $this->node(SignificantText::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(SignificantText::create(is_string($value) ? ['field' => $value] : $value)); } /** * Groups documents into time series buckets for time-series data. * - * @param mixed $params + * @param mixed $value * @return static */ - public function timeSeries($params): static + public function timeSeries($value): static { - return $this->node(TimeSeries::create($params)); + return $this->node(TimeSeries::create($value)); } /** * Groups documents into dynamically sized histogram buckets based on data distribution. * - * @param mixed $params + * @param mixed $value * @return static */ - public function variableWidthHistogram($params): static + public function variableWidthHistogram($value): static { - return $this->node(VariableWidthHistogram::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(VariableWidthHistogram::create(is_string($value) ? ['field' => $value] : $value)); } } diff --git a/src/DSL/Aggs/Metric.php b/src/DSL/Aggs/Metric.php index e86c25f..30a91ff 100644 --- a/src/DSL/Aggs/Metric.php +++ b/src/DSL/Aggs/Metric.php @@ -18,88 +18,88 @@ trait Metric /** * Computes the average of numeric values from a field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function avg($params): static + public function avg($value): static { - return $this->node(Avg::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Avg::create(is_string($value) ? ['field' => $value] : $value)); } /** * Computes the sum of numeric values from a field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function sum($params): static + public function sum($value): static { - return $this->node(Sum::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Sum::create(is_string($value) ? ['field' => $value] : $value)); } /** * Computes the minimum value from a field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function min($params): static + public function min($value): static { - return $this->node(Min::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Min::create(is_string($value) ? ['field' => $value] : $value)); } /** * Computes the maximum value from a field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function max($params): static + public function max($value): static { - return $this->node(Max::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Max::create(is_string($value) ? ['field' => $value] : $value)); } /** * Counts the number of distinct values in a field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function cardinality($params): static + public function cardinality($value): static { - return $this->node(Cardinality::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Cardinality::create(is_string($value) ? ['field' => $value] : $value)); } /** * Counts the number of values in a field, including duplicates. * - * @param mixed $params + * @param mixed $value * @return static */ - public function valueCount($params): static + public function valueCount($value): static { - return $this->node(ValueCount::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(ValueCount::create(is_string($value) ? ['field' => $value] : $value)); } /** * Computes count, min, max, avg, and sum stats from a field in one request. * - * @param mixed $params + * @param mixed $value * @return static */ - public function stats($params): static + public function stats($value): static { - return $this->node(Stats::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(Stats::create(is_string($value) ? ['field' => $value] : $value)); } /** * Computes extended statistics (stats plus stddev, variance, std error) from a field. * - * @param mixed $params + * @param mixed $value * @return static */ - public function extendedStats($params): static + public function extendedStats($value): static { - return $this->node(ExtendedStats::create(is_string($params) ? ['field' => $params] : $params)); + return $this->node(ExtendedStats::create(is_string($value) ? ['field' => $value] : $value)); } } diff --git a/src/DSL/Aggs/Pipeline.php b/src/DSL/Aggs/Pipeline.php index d3ea21c..34d7a74 100644 --- a/src/DSL/Aggs/Pipeline.php +++ b/src/DSL/Aggs/Pipeline.php @@ -18,88 +18,88 @@ trait Pipeline /** * Computes the average of a metric across sibling aggregation buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function avgBucket($params): static + public function avgBucket($value): static { - return $this->node(AvgBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(AvgBucket::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Computes the sum of a metric across sibling aggregation buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function sumBucket($params): static + public function sumBucket($value): static { - return $this->node(SumBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(SumBucket::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Finds the bucket with the maximum value of a metric across sibling buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function maxBucket($params): static + public function maxBucket($value): static { - return $this->node(MaxBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(MaxBucket::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Finds the bucket with the minimum value of a metric across sibling buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function minBucket($params): static + public function minBucket($value): static { - return $this->node(MinBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(MinBucket::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Computes count, min, max, avg, and sum stats across sibling aggregation buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function statsBucket($params): static + public function statsBucket($value): static { - return $this->node(StatsBucket::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(StatsBucket::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Computes a cumulative running sum of a metric across parent histogram buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function cumulativeSum($params): static + public function cumulativeSum($value): static { - return $this->node(CumulativeSum::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(CumulativeSum::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Computes the derivative of a metric between consecutive parent histogram buckets. * - * @param mixed $params + * @param mixed $value * @return static */ - public function derivative($params): static + public function derivative($value): static { - return $this->node(Derivative::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(Derivative::create(is_string($value) ? ['buckets_path' => $value] : $value)); } /** * Runs a custom script to compute values from multiple bucket metrics. * - * @param mixed $params + * @param mixed $value * @return static */ - public function bucketScript($params): static + public function bucketScript($value): static { - return $this->node(BucketScript::create(is_string($params) ? ['buckets_path' => $params] : $params)); + return $this->node(BucketScript::create(is_string($value) ? ['buckets_path' => $value] : $value)); } } diff --git a/src/DSL/Node.php b/src/DSL/Node.php index 13db4cb..e47e4af 100644 --- a/src/DSL/Node.php +++ b/src/DSL/Node.php @@ -185,6 +185,8 @@ protected function multi(bool $multi): static /** * Get the Elasticsearch type identifier. * + * @internal + * * @return string */ public function key(): string @@ -216,7 +218,7 @@ public function field($field): static * @param bool $append * @return static */ - public function addProperty($attribute, $value, $append = false): static + protected function addProperty($attribute, $value, $append = false): static { if ($append) { $this->_properties[$attribute][] = $value; diff --git a/src/DSL/Param.php b/src/DSL/Param.php index f5efce6..44eee44 100644 --- a/src/DSL/Param.php +++ b/src/DSL/Param.php @@ -31,12 +31,12 @@ public function hasParam($key): bool * Defines the maximum number of documents to return. * Defaults to 10. * - * @param int $size + * @param int $value * @return $this */ - public function size($size): static + public function size($value): static { - $this->_params['size'] = $size; + $this->_params['size'] = $value; return $this; } @@ -44,12 +44,12 @@ public function size($size): static * The starting document offset. * Defaults to 0. * - * @param int $from + * @param int $value * @return $this */ - public function from($from): static + public function from($value): static { - $this->_params['from'] = $from; + $this->_params['from'] = $value; return $this; } @@ -57,12 +57,12 @@ public function from($from): static * Specifies the period of time to wait for * a response from each shard. * - * @param string $timeout + * @param string $value * @return $this */ - public function timeout($timeout): static + public function timeout($value): static { - $this->_params['timeout'] = $timeout; + $this->_params['timeout'] = $value; return $this; } @@ -70,12 +70,12 @@ public function timeout($timeout): static * Minimum relevance score required for a document * to be included in the result set. * - * @param float $minScore + * @param float $value * @return $this */ - public function minScore($minScore): static + public function minScore($value): static { - $this->_params['min_score'] = $minScore; + $this->_params['min_score'] = $value; return $this; } @@ -83,12 +83,12 @@ public function minScore($minScore): static * Maximum number of documents to collect for * each shard, upon reaching which the query execution will terminate early. * - * @param int $terminateAfter + * @param int $value * @return $this */ - public function terminateAfter($terminateAfter): static + public function terminateAfter($value): static { - $this->_params['terminate_after'] = $terminateAfter; + $this->_params['terminate_after'] = $value; return $this; } @@ -96,12 +96,12 @@ public function terminateAfter($terminateAfter): static * If true, returns detailed information about * score computation as part of a hit. * - * @param bool $explain + * @param bool $value * @return $this */ - public function explain($explain): static + public function explain($value): static { - $this->_params['explain'] = $explain; + $this->_params['explain'] = $value; return $this; } @@ -109,24 +109,24 @@ public function explain($explain): static * If true, returns document version as part * of a hit. * - * @param bool $version + * @param bool $value * @return $this */ - public function version($version): static + public function version($value): static { - $this->_params['version'] = $version; + $this->_params['version'] = $value; return $this; } /** * If true, the query is profiled. * - * @param bool $profile + * @param bool $value * @return $this */ - public function profile($profile): static + public function profile($value): static { - $this->_params['profile'] = $profile; + $this->_params['profile'] = $value; return $this; } @@ -134,12 +134,12 @@ public function profile($profile): static * Number of hits matching the query to count * accurately. Defaults to 10,000. * - * @param bool|int $trackTotalHits + * @param bool|int $value * @return $this */ - public function trackTotalHits($trackTotalHits): static + public function trackTotalHits($value): static { - $this->_params['track_total_hits'] = $trackTotalHits; + $this->_params['track_total_hits'] = $value; return $this; } @@ -147,24 +147,26 @@ public function trackTotalHits($trackTotalHits): static * If true, returns sequence number and primary * term of the last modification of each hit. * - * @param bool $seqNoPrimaryTerm + * @param bool $value * @return $this */ - public function seqNoPrimaryTerm($seqNoPrimaryTerm): static + public function seqNoPrimaryTerm($value): static { - $this->_params['seq_no_primary_term'] = $seqNoPrimaryTerm; + $this->_params['seq_no_primary_term'] = $value; return $this; } /** - * Sorts the response by the given criteria. + * Sorts the response by the given criteria. Appends to the sort list; + * multiple calls chain together. * - * - sort('price', 'asc') — field + order, supports chaining - * - sort([['price' => 'asc']]) — raw ES array format + * - sort('price', 'asc') — field + order + * - sort('price', ['order' => 'asc', 'mode' => 'avg']) — field + options * - sort('_score') — field without direction + * - sort([['price' => 'asc'], ['age' => 'desc']]) — raw ES list, each spec appended * * @param string|array $field - * @param string|null $order + * @param string|array|null $order * @return $this */ public function sort($field, $order = null): static @@ -172,7 +174,9 @@ public function sort($field, $order = null): static if ($order !== null) { $this->_params['sort'][] = [$field => $order]; } elseif (is_array($field)) { - $this->_params['sort'] = $field; + foreach ($field as $spec) { + $this->_params['sort'][] = $spec; + } } else { $this->_params['sort'][] = $field; } @@ -183,24 +187,24 @@ public function sort($field, $order = null): static * Indicates which source fields are returned * for the search hits. * - * @param array|string $source + * @param array|string $value * @return $this */ - public function source($source): static + public function source($value): static { - $this->_params['_source'] = $source; + $this->_params['_source'] = $value; return $this; } /** * Sort values used to paginate results. * - * @param array $searchAfter + * @param array $value * @return $this */ - public function searchAfter($searchAfter): static + public function searchAfter($value): static { - $this->_params['search_after'] = $searchAfter; + $this->_params['search_after'] = $value; return $this; } @@ -208,37 +212,37 @@ public function searchAfter($searchAfter): static * Controls which stored fields are returned * as part of a hit. * - * @param array $storedFields + * @param array $value * @return $this */ - public function storedFields($storedFields): static + public function storedFields($value): static { - $this->_params['stored_fields'] = $storedFields; + $this->_params['stored_fields'] = $value; return $this; } /** * Returns docvalue fields as part of a hit. * - * @param array $docvalueFields + * @param array $value * @return $this */ - public function docvalueFields($docvalueFields): static + public function docvalueFields($value): static { - $this->_params['docvalue_fields'] = $docvalueFields; + $this->_params['docvalue_fields'] = $value; return $this; } /** - * Boosts the _score of documents from - * specified indices. + * Boosts the _score of documents from specified indices. + * Appends to the indices_boost list; multiple calls chain together. * - * @param array $indicesBoost + * @param array $value * @return $this */ - public function indicesBoost($indicesBoost): static + public function indicesBoost($value): static { - $this->_params['indices_boost'] = [$indicesBoost]; + $this->_params['indices_boost'][] = $value; return $this; } @@ -246,12 +250,12 @@ public function indicesBoost($indicesBoost): static * If true, compute and return _score even when * sorting on a field. Defaults to false. * - * @param bool $trackScores + * @param bool $value * @return $this */ - public function trackScores($trackScores): static + public function trackScores($value): static { - $this->_params['track_scores'] = $trackScores; + $this->_params['track_scores'] = $value; return $this; } @@ -259,24 +263,24 @@ public function trackScores($trackScores): static * Returns values from fields in the search response. * Supports field alias fields and array fields. * - * @param array $fields + * @param array $value * @return $this */ - public function fields($fields): static + public function fields($value): static { - $this->_params['fields'] = $fields; + $this->_params['fields'] = $value; return $this; } /** * Limits the search to a point in time (PIT). * - * @param array $pit + * @param array $value * @return $this */ - public function pit($pit): static + public function pit($value): static { - $this->_params['pit'] = $pit; + $this->_params['pit'] = $value; return $this; } @@ -284,36 +288,36 @@ public function pit($pit): static * Filter applied after query and aggregation execution. * Accepts a closure, array, or Query object. * - * @param mixed $filter + * @param mixed $value * @return $this */ - public function postFilter($filter): static + public function postFilter($value): static { - $this->_params['post_filter'] = Query::create($filter); + $this->_params['post_filter'] = Query::create($value); return $this; } /** * Collapse search results by field value. * - * @param mixed $collapse + * @param mixed $value * @return $this */ - public function collapse($collapse): static + public function collapse($value): static { - $this->_params['collapse'] = Params\Collapse::create($collapse); + $this->_params['collapse'] = Params\Collapse::create($value); return $this; } /** * Rescore the top documents with a secondary query. * - * @param mixed $rescore + * @param mixed $value * @return $this */ - public function rescore($rescore): static + public function rescore($value): static { - $this->_params['rescore'] = Params\Rescore::create($rescore); + $this->_params['rescore'] = Params\Rescore::create($value); return $this; } @@ -321,12 +325,12 @@ public function rescore($rescore): static * Highlight search matches in field values. * Supports chaining — fields are merged across calls. * - * @param mixed $highlight + * @param mixed $value * @return $this */ - public function highlight($highlight): static + public function highlight($value): static { - $new = Params\Highlight::create($highlight); + $new = Params\Highlight::create($value); if (isset($this->_params['highlight']) && $this->_params['highlight'] instanceof Params\Highlight) { // Merge new fields into existing highlight @@ -338,9 +342,9 @@ public function highlight($highlight): static } // Merge other properties (pre_tags, post_tags, etc) — last wins if (is_array($new->_properties)) { - foreach ($new->_properties as $key => $value) { + foreach ($new->_properties as $key => $val) { if ($key !== 'fields') { - $existing->addProperty($key, $value); + $existing->addProperty($key, $val); } } } @@ -354,36 +358,36 @@ public function highlight($highlight): static /** * Search suggestions based on term, completion, or phrase. * - * @param mixed $suggest + * @param mixed $value * @return $this */ - public function suggest($suggest): static + public function suggest($value): static { - $this->_params['suggest'] = Params\Suggest::create($suggest); + $this->_params['suggest'] = Params\Suggest::create($value); return $this; } /** * Returns script evaluation values for each hit. * - * @param array $scriptFields + * @param array $value * @return $this */ - public function scriptFields($scriptFields): static + public function scriptFields($value): static { - $this->_params['script_fields'] = $scriptFields; + $this->_params['script_fields'] = $value; return $this; } /** * Runtime field definitions used in the search request. * - * @param array $runtimeMappings + * @param array $value * @return $this */ - public function runtimeMappings($runtimeMappings): static + public function runtimeMappings($value): static { - $this->_params['runtime_mappings'] = $runtimeMappings; + $this->_params['runtime_mappings'] = $value; return $this; } diff --git a/src/DSL/Queries/Compound.php b/src/DSL/Queries/Compound.php index 1b804ea..90e92d8 100644 --- a/src/DSL/Queries/Compound.php +++ b/src/DSL/Queries/Compound.php @@ -25,14 +25,14 @@ trait Compound * * @example $query->bool(function (Boolean $b) { $b->must(function (Query $q) { $q->match('title', 'test') }) }) * - * @param callable|Boolean|array $bool + * @param callable|Boolean|array $value * @return $this */ - public function bool($bool): static + public function bool($value): static { - if (is_array($bool)) { + if (is_array($value)) { $boolean = new Boolean(); - foreach ($bool as $clause => $val) { + foreach ($value as $clause => $val) { $method = $clause === 'must_not' ? 'mustNot' : $clause; if ($val instanceof \Closure || $val instanceof Query) { $boolean->$method($val); @@ -42,20 +42,20 @@ public function bool($bool): static } return $this->addQuery($boolean); } - return $this->addQuery(Boolean::create($bool)); + return $this->addQuery(Boolean::create($value)); } /** * Add a boosting query. * - * @param callable|Boosting|array $boosting + * @param callable|Boosting|array $value * @return $this */ - public function boosting($boosting): static + public function boosting($value): static { - if (is_array($boosting)) { + if (is_array($value)) { $b = new Boosting(); - foreach ($boosting as $key => $val) { + foreach ($value as $key => $val) { if (($key === 'positive' || $key === 'negative') && ($val instanceof \Closure || $val instanceof Query)) { $b->$key($val); @@ -65,20 +65,20 @@ public function boosting($boosting): static } return $this->addQuery($b); } - return $this->addQuery(Boosting::create($boosting)); + return $this->addQuery(Boosting::create($value)); } /** * Add a constant_score query. * - * @param callable|ConstantScore|array $constantScore + * @param callable|ConstantScore|array $value * @return $this */ - public function constantScore($constantScore): static + public function constantScore($value): static { - if (is_array($constantScore)) { + if (is_array($value)) { $cs = new ConstantScore(); - foreach ($constantScore as $key => $val) { + foreach ($value as $key => $val) { if ($key === 'filter' && ($val instanceof \Closure || $val instanceof Query)) { $cs->filter($val); } else { @@ -87,20 +87,20 @@ public function constantScore($constantScore): static } return $this->addQuery($cs); } - return $this->addQuery(ConstantScore::create($constantScore)); + return $this->addQuery(ConstantScore::create($value)); } /** * Add a dis_max query. * - * @param callable|DisjunctionMax|array $disMax + * @param callable|DisjunctionMax|array $value * @return $this */ - public function disMax($disMax): static + public function disMax($value): static { - if (is_array($disMax)) { + if (is_array($value)) { $dm = new DisjunctionMax(); - foreach ($disMax as $key => $val) { + foreach ($value as $key => $val) { if ($key === 'queries' && ($val instanceof \Closure || $val instanceof Query)) { $dm->queries($val); } else { @@ -109,17 +109,17 @@ public function disMax($disMax): static } return $this->addQuery($dm); } - return $this->addQuery(DisjunctionMax::create($disMax)); + return $this->addQuery(DisjunctionMax::create($value)); } /** * Add a function_score query. * - * @param mixed $functionScore + * @param mixed $value * @return $this */ - public function functionScore($functionScore): static + public function functionScore($value): static { - return $this->addQuery(FunctionScore::create($functionScore)); + return $this->addQuery(FunctionScore::create($value)); } } diff --git a/src/DSL/Queries/Compound/Functions/Function_.php b/src/DSL/Queries/Compound/Functions/Function_.php index bb203fa..dfbdbdb 100644 --- a/src/DSL/Queries/Compound/Functions/Function_.php +++ b/src/DSL/Queries/Compound/Functions/Function_.php @@ -75,48 +75,48 @@ public function script($value): static * Uses a numeric field value to influence the score. * * @param mixed $field - * @param mixed $fieldValueFactor + * @param mixed $value * @return static */ - public function fieldValueFactor($field, $fieldValueFactor = null): static + public function fieldValueFactor($field, $value = null): static { - return $this->addProperty('field_value_factor', FieldValueFactor::create($field, $fieldValueFactor)); + return $this->addProperty('field_value_factor', FieldValueFactor::create($field, $value)); } /** * Scores documents using normal (Gaussian) decay based on distance from an origin point. * * @param mixed $field - * @param mixed $gauss + * @param mixed $value * @return static */ - public function gauss($field, $gauss = null): static + public function gauss($field, $value = null): static { - return $this->addProperty('gauss', Gauss::create($field, $gauss)); + return $this->addProperty('gauss', Gauss::create($field, $value)); } /** * Scores documents using linear decay based on distance from an origin point. * * @param mixed $field - * @param mixed $linear + * @param mixed $value * @return static */ - public function linear($field, $linear = null): static + public function linear($field, $value = null): static { - return $this->addProperty('linear', Linear::create($field, $linear)); + return $this->addProperty('linear', Linear::create($field, $value)); } /** * Scores documents using exponential decay based on distance from an origin point. * * @param mixed $field - * @param mixed $exp + * @param mixed $value * @return static */ - public function exp($field, $exp = null): static + public function exp($field, $value = null): static { - return $this->addProperty('exp', Exp::create($field, $exp)); + return $this->addProperty('exp', Exp::create($field, $value)); } /** diff --git a/src/DSL/Queries/FullText.php b/src/DSL/Queries/FullText.php index 298d46a..7056c9b 100644 --- a/src/DSL/Queries/FullText.php +++ b/src/DSL/Queries/FullText.php @@ -108,22 +108,22 @@ public function combinedFields($value): static /** * Add a query_string query. * - * @param mixed $queryString + * @param mixed $value * @return $this */ - public function queryString($queryString): static + public function queryString($value): static { - return $this->addQuery(QueryString::create($queryString)); + return $this->addQuery(QueryString::create($value)); } /** * Add a simple_query_string query. * - * @param mixed $simpleQueryString + * @param mixed $value * @return $this */ - public function simpleQueryString($simpleQueryString): static + public function simpleQueryString($value): static { - return $this->addQuery(SimpleQueryString::create($simpleQueryString)); + return $this->addQuery(SimpleQueryString::create($value)); } } diff --git a/src/DSL/Queries/FullText/Intervals/AllOf.php b/src/DSL/Queries/FullText/Intervals/AllOf.php index 030d0c9..c139ace 100644 --- a/src/DSL/Queries/FullText/Intervals/AllOf.php +++ b/src/DSL/Queries/FullText/Intervals/AllOf.php @@ -43,8 +43,6 @@ public function addInterval($value): static $target = $this->_properties['intervals']; if ($value instanceof \Closure) { $value($target); - } elseif ($value instanceof Node) { - $target->addQuery($value); } return $this; } diff --git a/src/DSL/Queries/FullText/Intervals/AnyOf.php b/src/DSL/Queries/FullText/Intervals/AnyOf.php index 77408ee..b5fd8e9 100644 --- a/src/DSL/Queries/FullText/Intervals/AnyOf.php +++ b/src/DSL/Queries/FullText/Intervals/AnyOf.php @@ -42,8 +42,6 @@ public function addInterval($value): static $target = $this->_properties['intervals']; if ($value instanceof \Closure) { $value($target); - } elseif ($value instanceof Node) { - $target->addQuery($value); } return $this; } diff --git a/src/DSL/Queries/Joining.php b/src/DSL/Queries/Joining.php index 98e3446..caf8527 100644 --- a/src/DSL/Queries/Joining.php +++ b/src/DSL/Queries/Joining.php @@ -73,11 +73,11 @@ public function hasParent($type, $query = null): static /** * Add a parent_id query. * - * @param mixed $parentId + * @param mixed $value * @return $this */ - public function parentId($parentId): static + public function parentId($value): static { - return $this->addQuery(ParentId::create($parentId)); + return $this->addQuery(ParentId::create($value)); } } diff --git a/src/DSL/Queries/MatchAll.php b/src/DSL/Queries/MatchAll.php index 74e4605..4f0af23 100644 --- a/src/DSL/Queries/MatchAll.php +++ b/src/DSL/Queries/MatchAll.php @@ -15,12 +15,12 @@ trait MatchAll /** * Add a match_all query. * - * @param mixed $matchAll + * @param mixed $value * @return $this */ - public function matchAll($matchAll = null): static + public function matchAll($value = null): static { - return $this->addQuery(QMatchAll::create($matchAll)); + return $this->addQuery(QMatchAll::create($value)); } /** diff --git a/src/DSL/Queries/Span.php b/src/DSL/Queries/Span.php index 111ef5c..d20e19a 100644 --- a/src/DSL/Queries/Span.php +++ b/src/DSL/Queries/Span.php @@ -23,78 +23,78 @@ trait Span /** * Add a span_containing query. * - * @param mixed $spanContaining + * @param mixed $value * @return $this */ - public function spanContaining($spanContaining): static + public function spanContaining($value): static { - return $this->addQuery(SpanContaining::create($spanContaining)); + return $this->addQuery(SpanContaining::create($value)); } /** * Add a span_field_masking query. * - * @param mixed $spanFieldMasking + * @param mixed $value * @return $this */ - public function spanFieldMasking($spanFieldMasking): static + public function spanFieldMasking($value): static { - return $this->addQuery(SpanFieldMasking::create($spanFieldMasking)); + return $this->addQuery(SpanFieldMasking::create($value)); } /** * Add a span_first query. * - * @param mixed $spanFirst + * @param mixed $value * @return $this */ - public function spanFirst($spanFirst): static + public function spanFirst($value): static { - return $this->addQuery(SpanFirst::create($spanFirst)); + return $this->addQuery(SpanFirst::create($value)); } /** * Add a span_multi query. * - * @param mixed $spanMulti + * @param mixed $value * @return $this */ - public function spanMulti($spanMulti): static + public function spanMulti($value): static { - return $this->addQuery(SpanMulti::create($spanMulti)); + return $this->addQuery(SpanMulti::create($value)); } /** * Add a span_near query. * - * @param mixed $spanNear + * @param mixed $value * @return $this */ - public function spanNear($spanNear): static + public function spanNear($value): static { - return $this->addQuery(SpanNear::create($spanNear)); + return $this->addQuery(SpanNear::create($value)); } /** * Add a span_not query. * - * @param mixed $spanNot + * @param mixed $value * @return $this */ - public function spanNot($spanNot): static + public function spanNot($value): static { - return $this->addQuery(SpanNot::create($spanNot)); + return $this->addQuery(SpanNot::create($value)); } /** * Add a span_or query. * - * @param mixed $spanOr + * @param mixed $value * @return $this */ - public function spanOr($spanOr): static + public function spanOr($value): static { - return $this->addQuery(SpanOr::create($spanOr)); + return $this->addQuery(SpanOr::create($value)); } /** @@ -112,11 +112,11 @@ public function spanTerm($field, $value = null): static /** * Add a span_within query. * - * @param mixed $spanWithin + * @param mixed $value * @return $this */ - public function spanWithin($spanWithin): static + public function spanWithin($value): static { - return $this->addQuery(SpanWithin::create($spanWithin)); + return $this->addQuery(SpanWithin::create($value)); } } diff --git a/src/DSL/Queries/Specialized.php b/src/DSL/Queries/Specialized.php index ea94d56..0bdcb10 100644 --- a/src/DSL/Queries/Specialized.php +++ b/src/DSL/Queries/Specialized.php @@ -21,88 +21,88 @@ trait Specialized /** * Add a distance_feature query. * - * @param mixed $distanceFeature + * @param mixed $value * @return $this */ - public function distanceFeature($distanceFeature): static + public function distanceFeature($value): static { - return $this->addQuery(DistanceFeature::create($distanceFeature)); + return $this->addQuery(DistanceFeature::create($value)); } /** * Add a more_like_this query. * - * @param mixed $moreLikeThis + * @param mixed $value * @return $this */ - public function moreLikeThis($moreLikeThis): static + public function moreLikeThis($value): static { - return $this->addQuery(MoreLikeThis::create($moreLikeThis)); + return $this->addQuery(MoreLikeThis::create($value)); } /** * Add a percolate query. * - * @param mixed $percolate + * @param mixed $value * @return $this */ - public function percolate($percolate): static + public function percolate($value): static { - return $this->addQuery(Percolate::create($percolate)); + return $this->addQuery(Percolate::create($value)); } /** * Add a rank_feature query. * - * @param mixed $rankFeature + * @param mixed $value * @return $this */ - public function rankFeature($rankFeature): static + public function rankFeature($value): static { - return $this->addQuery(RankFeature::create($rankFeature)); + return $this->addQuery(RankFeature::create($value)); } /** * Add a script query. * - * @param mixed $script + * @param mixed $value * @return $this */ - public function script($script): static + public function script($value): static { - return $this->addQuery(Script::create($script)); + return $this->addQuery(Script::create($value)); } /** * Add a script_score query. * - * @param mixed $scriptScore + * @param mixed $value * @return $this */ - public function scriptScore($scriptScore): static + public function scriptScore($value): static { - return $this->addQuery(ScriptScore::create($scriptScore)); + return $this->addQuery(ScriptScore::create($value)); } /** * Add a wrapper query. * - * @param mixed $wrapper + * @param mixed $value * @return $this */ - public function wrapper($wrapper): static + public function wrapper($value): static { - return $this->addQuery(Wrapper::create($wrapper)); + return $this->addQuery(Wrapper::create($value)); } /** * Add a pinned query. * - * @param mixed $pinned + * @param mixed $value * @return $this */ - public function pinned($pinned): static + public function pinned($value): static { - return $this->addQuery(Pinned::create($pinned)); + return $this->addQuery(Pinned::create($value)); } } diff --git a/src/DSL/Queries/TermLevel.php b/src/DSL/Queries/TermLevel.php index 2b1583a..6f1e34c 100644 --- a/src/DSL/Queries/TermLevel.php +++ b/src/DSL/Queries/TermLevel.php @@ -60,15 +60,15 @@ public function exists($field): static /** * Returns documents based on their IDs. This query uses document IDs stored in the _id field. * - * @param mixed $ids + * @param mixed $value * @return $this */ - public function ids($ids): static + public function ids($value): static { - if (is_array($ids) && !isset($ids['values'])) { - $ids = ['values' => $ids]; + if (is_array($value) && !isset($value['values'])) { + $value = ['values' => $value]; } - return $this->addQuery(IDs::create($ids)); + return $this->addQuery(IDs::create($value)); } /** diff --git a/src/DSL/Query.php b/src/DSL/Query.php index c6f0d63..24eaf55 100644 --- a/src/DSL/Query.php +++ b/src/DSL/Query.php @@ -118,12 +118,12 @@ public function getQueries(): array /** * Add a query clause to the query container. * - * @param mixed $value + * @param mixed $clause * @return $this */ - public function addQuery($value): static + public function addQuery($clause): static { - $this->_queries[] = $value; + $this->_queries[] = $clause; return $this; } @@ -135,7 +135,7 @@ public function addQuery($value): static * @param mixed $default * @return $this */ - public function when($condition, $query, $default = null): static + public function when(bool|callable $condition, $query, $default = null): static { $truthy = is_callable($condition) ? $condition() : $condition; diff --git a/tests/ParamsTest.php b/tests/ParamsTest.php index e26e5f9..bb22f33 100644 --- a/tests/ParamsTest.php +++ b/tests/ParamsTest.php @@ -317,6 +317,26 @@ public function testIndicesBoost() $this->assertQuery($expectedJson, $query); } + public function testIndicesBoostChained() + { +$expectedJson = <<matchAll(); + $query->indicesBoost(['index-1' => 1.4]) + ->indicesBoost(['index-2' => 1.2]); + $this->assertQuery($expectedJson, $query); + } + public function testChainingParamsAndQuery() { $expectedJson = << Date: Fri, 19 Jun 2026 14:13:02 +0800 Subject: [PATCH 20/24] =?UTF-8?q?refactor(index):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E5=8F=82=E6=95=B0=E5=B9=B6=E8=A1=A5=20Rebuil?= =?UTF-8?q?d::source=20=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - $name → $connection(ClientManager::set / Index::setClient) - $newName → $newIndex(Rebuild,对齐 Index 模式) - $document → $data(Doc/Bulk 的 index/save/create,全库文档载荷统一) - Rebuild::source 补 callable|iterable 参数类型,修正 docblock \Iterator 笔误 Co-Authored-By: Claude --- CLAUDE.md | 2 +- src/Index/Bulk.php | 18 +++++++++--------- src/Index/ClientManager.php | 6 +++--- src/Index/Doc.php | 18 +++++++++--------- src/Index/Index.php | 6 +++--- src/Index/Rebuild.php | 38 ++++++++++++++++++------------------- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 75b1dc9..cec014b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -47,7 +47,7 @@ PSR-5 规范。 - [x] **移除 Index::insert()**:等价功能由 Doc::save() 覆盖 - [x] **实例入口**:新增 on()/newQuery()/newDoc()/setConnection()/getConnection(),query()/doc() 委托实例方法 - [x] **测试 mock 污染修复**:所有测试文件补 tearDown 清理静态状态 -- [ ] **命名参数一致性**:公开方法参数名是 API 的一部分,全库审查确保命名统一(如 connection/name/client 不混用) +- [x] **命名参数一致性**:公开方法参数名是 API 的一部分,全库审查确保命名统一(如 connection/name/client 不混用) - [x] **PHP 8 现代化(Index 层)**:全 12 文件 strict_types + 构造器提升 + readonly + 属性/返回/参数类型 + 联合类型;callable 属性(resolver / errorHandler / dataSource)因 PHP 禁止 callable 作属性类型,保留 docblock - [x] **PHP 8 现代化(DSL 层)**:Node/Query/Agg + 122 leaf 类全部完成。strict_types 全 151 文件;4 原子属性类型同步全 leaf;leaf 参数类型对照 ES docblock 完成;`$_properties` 三模式统一为 `?array`(新增 `$_raw` 承接整体透传,null 保留为合法空态);`toJson` 加 `:string` + false 检查;`toArray` 因多态返回(array/stdClass/null)不强加 PHP 返回类型 - [ ] **Rebuild 异常处理**:run() 改为 try-catch + releaseLock 分离,releaseLock 不吞任何异常,forceUnlock 单独处理 404(文档不存在 vs 索引不存在的 404 需区分);isLocked() 只吞 404 不吞其他 ClientResponseException;rebuild 失败优先抛原始异常;ensureLockIndex() replicas=0 在多节点集群有风险需注释说明 diff --git a/src/Index/Bulk.php b/src/Index/Bulk.php index 470af0e..f5c2ed3 100644 --- a/src/Index/Bulk.php +++ b/src/Index/Bulk.php @@ -111,17 +111,17 @@ public function retryOnConflict(int $count): static * Queue an index (create/overwrite) action. * * @param string|int|null $id document ID, or null to let ES auto-generate - * @param array $document + * @param array $data * @return $this */ - public function index(string|int|null $id, array $document): static + public function index(string|int|null $id, array $data): static { $action = ['index' => ['_index' => $this->resolveIndex()]]; if ($id !== null && $id !== '') { $action['index']['_id'] = $id; } $this->body[] = $action; - $this->body[] = $document; + $this->body[] = $data; $this->afterPush(); return $this; @@ -131,25 +131,25 @@ public function index(string|int|null $id, array $document): static * Alias for index(). Queue a save (create/overwrite) action. * * @param string|int|null $id - * @param array $document + * @param array $data * @return $this */ - public function save(string|int|null $id, array $document): static + public function save(string|int|null $id, array $data): static { - return $this->index($id, $document); + return $this->index($id, $data); } /** * Queue a create action (fail if document already exists). * * @param string|int $id - * @param array $document + * @param array $data * @return $this */ - public function create(string|int $id, array $document): static + public function create(string|int $id, array $data): static { $this->body[] = ['create' => ['_index' => $this->resolveIndex(), '_id' => $id]]; - $this->body[] = $document; + $this->body[] = $data; $this->afterPush(); return $this; diff --git a/src/Index/ClientManager.php b/src/Index/ClientManager.php index ae62175..443ef51 100644 --- a/src/Index/ClientManager.php +++ b/src/Index/ClientManager.php @@ -21,12 +21,12 @@ class ClientManager * Register an Elasticsearch client. Optionally name the connection. * * @param ClientInterface $client - * @param string $name connection name, defaults to 'default' + * @param string $connection connection name, defaults to 'default' * @return void */ - public static function set(ClientInterface $client, string $name = 'default'): void + public static function set(ClientInterface $client, string $connection = 'default'): void { - self::$clients[$name] = $client; + self::$clients[$connection] = $client; } /** diff --git a/src/Index/Doc.php b/src/Index/Doc.php index dd8d2fd..3ab8178 100644 --- a/src/Index/Doc.php +++ b/src/Index/Doc.php @@ -154,10 +154,10 @@ public function update(array $data, bool $upsert = false): array * * If $id is null or empty, ES auto-generates an id. * - * @param array $document + * @param array $data * @return array */ - public function index(array $document): array + public function index(array $data): array { $params = [ 'index' => $this->index->name(), @@ -167,7 +167,7 @@ public function index(array $document): array $params['id'] = $this->id; } - $params['body'] = $document; + $params['body'] = $data; if ($this->refresh !== null) { $params['refresh'] = $this->refresh; @@ -181,12 +181,12 @@ public function index(array $document): array /** * Alias for index(). Create or overwrite the document. * - * @param array $document + * @param array $data * @return array */ - public function save(array $document): array + public function save(array $data): array { - return $this->index($document); + return $this->index($data); } /** @@ -195,10 +195,10 @@ public function save(array $document): array * If $id is null or empty, ES auto-generates an id (always a create, since * auto-generated ids are unique). * - * @param array $document + * @param array $data * @return array */ - public function create(array $document): array + public function create(array $data): array { $params = [ 'index' => $this->index->name(), @@ -208,7 +208,7 @@ public function create(array $document): array $params['id'] = $this->id; } - $params['body'] = $document; + $params['body'] = $data; $params['op_type'] = 'create'; if ($this->refresh !== null) { diff --git a/src/Index/Index.php b/src/Index/Index.php index a7c9c98..35426e0 100644 --- a/src/Index/Index.php +++ b/src/Index/Index.php @@ -50,12 +50,12 @@ abstract class Index * Register an Elasticsearch client. Optionally name the connection. * * @param ClientInterface $client - * @param string $name connection name, defaults to 'default' + * @param string $connection connection name, defaults to 'default' * @return void */ - public static function setClient(ClientInterface $client, string $name = 'default'): void + public static function setClient(ClientInterface $client, string $connection = 'default'): void { - ClientManager::set($client, $name); + ClientManager::set($client, $connection); } /** diff --git a/src/Index/Rebuild.php b/src/Index/Rebuild.php index 7979d3d..81f2be3 100644 --- a/src/Index/Rebuild.php +++ b/src/Index/Rebuild.php @@ -37,7 +37,7 @@ class Rebuild private bool $allowEmpty = false; /** - * @var callable|\Iterator>|null + * @var callable|iterable>|null */ private $dataSource; @@ -90,10 +90,10 @@ public function allowEmpty(bool $allow = true): static * Set a custom data source. Accepts a callable or iterable. * Defaults to Index::source() when not set. * - * @param callable|\Iterator> $source + * @param callable|iterable> $source * @return $this */ - public function source($source): static + public function source(callable|iterable $source): static { $this->dataSource = $source; return $this; @@ -212,16 +212,16 @@ private function doRun(array $context): array EventDispatcher::dispatch(new Event('rebuild.run.before', $name)); - $newName = $this->createIndex(); + $newIndex = $this->createIndex(); try { - $this->import($newName, $context); + $this->import($newIndex, $context); } catch (\Throwable $e) { - $client->delete(['index' => $newName]); + $client->delete(['index' => $newIndex]); throw $e; } - $client->refresh(['index' => $newName]); + $client->refresh(['index' => $newIndex]); $oldIndex = null; @@ -232,25 +232,25 @@ private function doRun(array $context): array foreach ($oldIndices as $idx) { $actions[] = ['remove' => ['index' => $idx, 'alias' => $name]]; } - $actions[] = ['add' => ['index' => $newName, 'alias' => $name]]; + $actions[] = ['add' => ['index' => $newIndex, 'alias' => $name]]; $client->updateAliases(['body' => ['actions' => $actions]]); } elseif ($client->exists(['index' => $name])->asBool()) { - $client->delete(['index' => $newName]); + $client->delete(['index' => $newIndex]); throw new RuntimeException( "Index [{$name}] is a real index, not an alias. " . "Rebuild requires an alias to swap atomically. " . "Delete the index manually or convert it to alias mode before running rebuild." ); } else { - $client->putAlias(['index' => $newName, 'name' => $name]); + $client->putAlias(['index' => $newIndex, 'name' => $name]); } $e = new Event('rebuild.run.after', $name); - $e->newIndex = $newName; + $e->newIndex = $newIndex; $e->oldIndex = $oldIndex; EventDispatcher::dispatch($e); - return ['newIndex' => $newName, 'oldIndex' => $oldIndex]; + return ['newIndex' => $newIndex, 'oldIndex' => $oldIndex]; } /** @@ -340,28 +340,28 @@ private function ensureLockIndex(): void */ protected function createIndex(): string { - $newName = $this->index->rebuildName(); + $newIndex = $this->index->rebuildName(); $mappings = $this->index->mappings(); $settings = $this->index->settings(); $this->index->getClient()->indices()->create([ - 'index' => $newName, + 'index' => $newIndex, 'body' => [ 'mappings' => empty($mappings) ? new stdClass() : $mappings, 'settings' => empty($settings) ? new stdClass() : $settings, ], ]); - return $newName; + return $newIndex; } /** * Import data into the target index. * - * @param string $newName + * @param string $newIndex * @param array $context */ - protected function import(string $newName, array $context): void + protected function import(string $newIndex, array $context): void { if ($this->dataSource !== null) { $items = is_callable($this->dataSource) ? ($this->dataSource)($context) : $this->dataSource; @@ -369,7 +369,7 @@ protected function import(string $newName, array $context): void $items = $this->index->source($context); } - $bulk = (new Bulk($this->index))->target($newName)->batchSize($this->batchSize); + $bulk = (new Bulk($this->index))->target($newIndex)->batchSize($this->batchSize); if ($this->errorHandler) { $bulk->onError($this->errorHandler); } @@ -388,7 +388,7 @@ protected function import(string $newName, array $context): void if ($count === 0 && !$this->allowEmpty) { throw new RuntimeException( - "Rebuild imported 0 documents for index [{$newName}]. " + "Rebuild imported 0 documents for index [{$newIndex}]. " . "Call allowEmpty() if this is intentional." ); } From c6c77db38d6b7a3ad2bd38b6c47ca2b9a43aeb16 Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 19 Jun 2026 14:46:32 +0800 Subject: [PATCH 21/24] =?UTF-8?q?refactor(index)!:=20=E6=8B=86=E5=88=86=20?= =?UTF-8?q?chunk/cursor=20=E9=81=8D=E5=8E=86=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 原 cursor()(按批 yield Results)改名为 chunk() - 新增 cursor():逐条 yield 完整 hit(_id/_score/_source),flatten chunk 复用其 scroll 清理 - 低层 scroll/next/clear 保留,未来可换 PIT+search_after,上层签名不变 - 同步 README/docs/IndexTest **BC:** cursor() 返回从 Generator(按批)改为 Generator(逐条) Co-Authored-By: Claude --- README.md | 12 ++++++--- docs/guide.md | 6 ++--- docs/index.md | 18 ++++++++++--- src/Index/Search.php | 27 +++++++++++++++++--- tests/Index/IndexTest.php | 53 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 100 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 29d9ed8..d972849 100644 --- a/README.md +++ b/README.md @@ -178,12 +178,18 @@ $results->lastPage(); $results->items(); $results->toPaginator(); // 转为框架分页器(需注册 Paginator Resolver) -// 游标遍历(大批量导出) -foreach (ProductIndex::query()->cursor() as $batch) { - foreach ($batch->docs() as $doc) { +// 分批遍历(大批量导出/批处理,每次 yield 一个 Results) +foreach (ProductIndex::query()->chunk() as $results) { + foreach ($results->docs() as $doc) { // ... } } + +// 逐条遍历(导出/逐条加工,每次 yield 一个 hit:_id/_score/_source) +foreach (ProductIndex::query()->cursor() as $hit) { + $doc = $hit['_source']; + // ... +} ``` ### 文档 CRUD diff --git a/docs/guide.md b/docs/guide.md index 5cd09ff..3ca10a5 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -160,7 +160,7 @@ public function index(Request $request) } ``` -> 条件用 `if` 逐个判断,只有传了值才加查询。`should()` 实现 OR 搜索。深分页场景用 `cursor()` 替代 `paginate()`。 +> 条件用 `if` 逐个判断,只有传了值才加查询。`should()` 实现 OR 搜索。深分页场景用 `chunk()`(按批)或 `cursor()`(逐条)替代 `paginate()`。 运营还要导出筛选结果到 Excel。ES 默认 `max_result_window = 10000`,`from/size` 翻不到后面的数据,用 `cursor()` 基于 scroll 遍历: @@ -169,8 +169,8 @@ public function export(array $filters) { $search = static::searchOrders($filters)->sort('created_at', 'desc'); - foreach ($search->cursor() as $batch) { - foreach ($batch->docs() as $doc) { + foreach ($search->chunk() as $results) { + foreach ($results->docs() as $doc) { // 写入 Excel } } diff --git a/docs/index.md b/docs/index.md index 34535b0..c1811bd 100644 --- a/docs/index.md +++ b/docs/index.md @@ -116,17 +116,27 @@ while (count($results->docs()) > 0) { ProductIndex::query()->clear($scrollId); ``` -## Cursor +## Chunk / Cursor -Cursor 把 scroll 封装成 PHP 生成器: +把 scroll 封装成 PHP 生成器,scroll 自动清理。 + +**chunk** 按批遍历,每次 yield 一个 Results(含 docs/hits/total 等): ```php -foreach (ProductIndex::query()->cursor() as $results) { +foreach (ProductIndex::query()->chunk() as $results) { foreach ($results->docs() as $doc) { // 处理 } } -// scroll 自动清理 +``` + +**cursor** 逐条遍历,每次 yield 一个完整 hit(_id/_score/_source): + +```php +foreach (ProductIndex::query()->cursor() as $hit) { + $doc = $hit['_source']; + $id = $hit['_id']; +} ``` ## 文档 CRUD diff --git a/src/Index/Search.php b/src/Index/Search.php index 88b78c8..83cf276 100644 --- a/src/Index/Search.php +++ b/src/Index/Search.php @@ -210,12 +210,13 @@ protected function doScroll(string $scrollId, string $duration): Results } /** - * Return a generator that yields Results batches via scroll. + * Lazily yield Results batches via scroll. Each yielded Results is one + * scroll batch; the scroll context is cleared when iteration ends. * - * @param string $duration - * @return \Generator + * @param string $duration scroll keep-alive + * @return \Generator */ - public function cursor(string $duration = '5m'): \Generator + public function chunk(string $duration = '5m'): \Generator { $results = $this->scroll(null, $duration); @@ -229,6 +230,24 @@ public function cursor(string $duration = '5m'): \Generator } } + /** + * Lazily yield individual search hits, flattened across scroll batches. + * + * Each value is a raw ES hit (_id, _score, _source, ...) — the same shape + * as Results::hits() entries. Reuses chunk()'s scroll cleanup. + * + * @param string $duration scroll keep-alive + * @return \Generator, mixed, void> + */ + public function cursor(string $duration = '5m'): \Generator + { + foreach ($this->chunk($duration) as $results) { + foreach ($results->hits() as $hit) { + yield $hit; + } + } + } + /** * Execute a paginated search. Uses pageResolver if no arguments are given. * diff --git a/tests/Index/IndexTest.php b/tests/Index/IndexTest.php index f6cb55e..2c2b325 100644 --- a/tests/Index/IndexTest.php +++ b/tests/Index/IndexTest.php @@ -379,7 +379,7 @@ public function testClearSkipsWhenNoScrollId() $index->query()->clear($results); } - public function testCursorYieldsResultsBatches() + public function testChunkYieldsResultsBatches() { $client = $this->createMock(TestClient::class); @@ -417,7 +417,7 @@ public function testCursorYieldsResultsBatches() $index = $this->createIndex('products'); $batches = []; - foreach ($index->query()->matchAll()->cursor('1m') as $results) { + foreach ($index->query()->matchAll()->chunk('1m') as $results) { $this->assertInstanceOf(Results::class, $results); $batches[] = $results; } @@ -428,6 +428,55 @@ public function testCursorYieldsResultsBatches() $this->assertEquals(['3'], $batches[1]->ids()); } + public function testCursorYieldsIndividualHits() + { + $client = $this->createMock(TestClient::class); + + $client->method('search')->willReturn(new ArrayResponse([ + '_scroll_id' => 'scroll1', + 'hits' => [ + 'total' => ['value' => 3], + 'hits' => [ + ['_id' => '1', '_source' => ['id' => 1]], + ['_id' => '2', '_source' => ['id' => 2]], + ], + ], + ])); + + $callCount = 0; + $client->method('scroll')->willReturnCallback(function () use (&$callCount) { + $callCount++; + if ($callCount === 1) { + return new ArrayResponse([ + '_scroll_id' => 'scroll2', + 'hits' => [ + 'total' => ['value' => 3], + 'hits' => [['_id' => '3', '_source' => ['id' => 3]]], + ], + ]); + } + return new ArrayResponse([ + '_scroll_id' => 'scroll3', + 'hits' => ['total' => ['value' => 3], 'hits' => []], + ]); + }); + + $client->method('clearScroll'); + Index::setClient($client); + + $index = $this->createIndex('products'); + $hits = []; + foreach ($index->query()->matchAll()->cursor('1m') as $hit) { + $hits[] = $hit; + } + + // 3 docs flattened across 2 batches, each yielded as a raw hit + $this->assertCount(3, $hits); + $this->assertSame('1', $hits[0]['_id']); + $this->assertSame(['id' => 1], $hits[0]['_source']); + $this->assertSame('3', $hits[2]['_id']); + } + public function testNameReturnsIndexName() { $index = $this->createIndex('orders'); From ec3380f4c3210377ec60ae5e528dcd8efad7c5bb Mon Sep 17 00:00:00 2001 From: ykan821 Date: Fri, 19 Jun 2026 14:51:03 +0800 Subject: [PATCH 22/24] =?UTF-8?q?refactor(index):=20cursor=20=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20yield=20from=20=E5=A7=94=E6=89=98=E8=BF=AD=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- src/Index/Search.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Index/Search.php b/src/Index/Search.php index 83cf276..e5f9e7f 100644 --- a/src/Index/Search.php +++ b/src/Index/Search.php @@ -242,9 +242,7 @@ public function chunk(string $duration = '5m'): \Generator public function cursor(string $duration = '5m'): \Generator { foreach ($this->chunk($duration) as $results) { - foreach ($results->hits() as $hit) { - yield $hit; - } + yield from $results->hits(); } } From bc5e4d849084e1b7a9ef629f17335e59f97f056f Mon Sep 17 00:00:00 2001 From: ykan821 Date: Tue, 23 Jun 2026 22:42:18 +0800 Subject: [PATCH 23/24] =?UTF-8?q?refactor(index)!:=20=E6=94=B6=E7=B4=A7=20?= =?UTF-8?q?Rebuild=20=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - run() 分离 try-catch:失败优先抛 doRun 原始异常(释放锁失败不掩盖); 成功后释放锁失败抛 RuntimeException(说明 rebuild 已完成、需 forceUnlock) - releaseLock 移除 \Throwable 兜底,只吞 404 - forceUnlock 独立实现,吞 404(索引或文档不存在均幂等成功) - isLocked 只在 404 返回 false,其他 ES 错误传播 **BC:** forceUnlock/isLocked 不再吞非 404 的 ES 错误;run() 成功路径 在释放锁失败时抛出异常(此前被静默吞掉) Co-Authored-By: Claude --- phpstan-baseline.neon | 2 +- src/Index/Rebuild.php | 59 ++++++++++++++++--- tests/Index/RebuildTest.php | 110 ++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1321b33..f5e9a20 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -75,7 +75,7 @@ parameters: - message: '#^Call to an undefined method Elastic\\Elasticsearch\\ClientInterface\:\:delete\(\)\.$#' identifier: method.notFound - count: 1 + count: 2 path: src/Index/Rebuild.php - diff --git a/src/Index/Rebuild.php b/src/Index/Rebuild.php index 81f2be3..b032810 100644 --- a/src/Index/Rebuild.php +++ b/src/Index/Rebuild.php @@ -13,6 +13,8 @@ * * $name is always the app-facing name. After rebuild, $name becomes an alias * pointing to a backing index generated by rebuildName(). + * + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class Rebuild { @@ -107,6 +109,10 @@ public function source(callable|iterable $source): static * - $name is a real index: throws RuntimeException (convert to alias mode first) * - $name does not exist: create alias pointing to new backing index * + * The lock is always released: on failure doRun()'s exception is rethrown + * (never masked); on success a release failure surfaces as a RuntimeException + * noting the rebuild completed but the lock is stale. + * * @param array $context user-defined context passed to source() * @return array{newIndex: string, oldIndex: string|null} */ @@ -116,8 +122,25 @@ public function run(array $context = []): array try { $result = $this->doRun($context); - } finally { + } catch (\Throwable $e) { + try { + $this->releaseLock(); + } catch (\Throwable) { + // Ignore release failure; the original exception propagates below. + } + throw $e; + } + + // Success: data is swapped, so a release failure means only the lock is stale. + try { $this->releaseLock(); + } catch (\Throwable $e) { + throw new RuntimeException( + "Rebuild for [{$this->index->name()}] succeeded but the lock could not be released. " + . "Data is already swapped to the new index. Call forceUnlock() to clear the stale lock.", + 0, + $e + ); } return $result; @@ -128,15 +151,29 @@ public function run(array $context = []): array * * Under normal circumstances the lock is released automatically by run(). * Call this only when a previous rebuild crashed and the lock persists. + * + * Idempotent: a 404 (lock index or document missing) is treated as success. */ public function forceUnlock(): void { - $this->releaseLock(); + try { + $this->index->getClient()->delete([ + 'index' => self::LOCK_INDEX, + 'id' => $this->index->name(), + ]); + } catch (ClientResponseException $e) { + if ($e->getResponse()->getStatusCode() !== 404) { + throw $e; + } + } } /** * Check whether a rebuild lock is currently held for this index. * + * Returns false only on a real 404; other ES errors propagate so an + * unreachable cluster is never mistaken for an unlocked index. + * * @return bool */ public function isLocked(): bool @@ -147,7 +184,10 @@ public function isLocked(): bool 'id' => $this->index->name(), ])->asBool(); } catch (ClientResponseException $e) { - return false; + if ($e->getResponse()->getStatusCode() === 404) { + return false; + } + throw $e; } } @@ -283,7 +323,10 @@ private function acquireLock(): void } /** - * Release the distributed lock. Idempotent — silently ignores 404. + * Release the lock. Idempotent: only 404 is swallowed; other failures + * (transport, 5xx) propagate so a stale lock stays detectable. + * + * @throws ClientResponseException for any non-404 failure */ private function releaseLock(): void { @@ -293,12 +336,10 @@ private function releaseLock(): void 'id' => $this->index->name(), ]); } catch (ClientResponseException $e) { - if ($e->getResponse()->getStatusCode() !== 404) { - throw $e; + if ($e->getResponse()->getStatusCode() === 404) { + return; // Lock already gone — idempotent } - // Lock already gone — idempotent - } catch (\Throwable $e) { - // Swallow transport / server errors in finally to avoid masking the original exception + throw $e; } } diff --git a/tests/Index/RebuildTest.php b/tests/Index/RebuildTest.php index 8d25dbb..5412571 100644 --- a/tests/Index/RebuildTest.php +++ b/tests/Index/RebuildTest.php @@ -716,4 +716,114 @@ public function source(array $context = []): iterable $this->assertStringStartsWith('products_', $result['newIndex']); } + + public function testRunThrowsWhenReleaseLockFailsAfterSuccess() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturnCallback(function ($params) { + if (($params['index'] ?? '') === '.ek_locks') { + return new BoolResponse(true); + } + return new BoolResponse(false); + }); + $indices->method('existsAlias')->willReturn(new BoolResponse(false)); + $indices->method('putAlias')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $response = $this->createMock(\Psr\Http\Message\ResponseInterface::class); + $response->method('getStatusCode')->willReturn(503); + $releaseException = new \Elastic\Elasticsearch\Exception\ClientResponseException(); + $releaseException->setResponse($response); + + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + // 成功路径释放锁时抛 503 + $client->method('delete')->willThrowException($releaseException); + $client->method('bulk')->willReturn(new ArrayResponse(['items' => []])); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + yield 1 => ['title' => 'A']; + } + }; + + try { + (new Rebuild($index))->run(); + $this->fail('Expected RuntimeException when lock release fails after success'); + } catch (\RuntimeException $e) { + $this->assertStringContainsString('succeeded but the lock could not be released', $e->getMessage()); + $this->assertStringContainsString('forceUnlock', $e->getMessage()); + $this->assertSame($releaseException, $e->getPrevious()); + } + } + + public function testRunPreservesOriginalExceptionWhenReleaseFails() + { + $indices = $this->createMock(TestIndices::class); + $indices->method('create')->willReturn(new ArrayResponse(['acknowledged' => true])); + $indices->method('exists')->willReturn(new BoolResponse(true)); + $indices->method('delete')->willReturn(new ArrayResponse(['acknowledged' => true])); + + $response = $this->createMock(\Psr\Http\Message\ResponseInterface::class); + $response->method('getStatusCode')->willReturn(503); + $releaseException = new \Elastic\Elasticsearch\Exception\ClientResponseException(); + $releaseException->setResponse($response); + + $client = $this->createMock(TestClient::class); + $client->method('indices')->willReturn($indices); + $client->method('index')->willReturn(new ArrayResponse(['result' => 'created'])); + // 释放锁也失败:503 + $client->method('delete')->willThrowException($releaseException); + // bulk 导入失败 → doRun 抛异常 + $client->method('bulk')->willReturn(new ArrayResponse(['items' => [], 'errors' => true])); + Index::setClient($client); + + $index = new class extends Index { + public function __construct() + { + $this->name = 'products'; + } + + public function source(array $context = []): iterable + { + yield 1 => ['title' => 'A']; + } + }; + + try { + (new Rebuild($index))->run(); + $this->fail('Expected original import exception'); + } catch (\Throwable $e) { + // ⑤:必须抛出 doRun 的原始异常,而非释放锁的 503 ClientResponseException + $this->assertInstanceOf(\RuntimeException::class, $e); + $this->assertStringContainsString('Bulk request has errors', $e->getMessage()); + $this->assertStringNotContainsString('succeeded but the lock', $e->getMessage()); + $this->assertNotSame($releaseException, $e); + } + } + + public function testIsLockedThrowsOnServerError() + { + $response = $this->createMock(\Psr\Http\Message\ResponseInterface::class); + $response->method('getStatusCode')->willReturn(503); + $exception = new \Elastic\Elasticsearch\Exception\ClientResponseException(); + $exception->setResponse($response); + + $client = $this->createMock(TestClient::class); + $client->method('exists')->willThrowException($exception); + Index::setClient($client); + + $index = $this->createIndex('products'); + + $this->expectException(\Elastic\Elasticsearch\Exception\ClientResponseException::class); + (new Rebuild($index))->isLocked(); + } } From 02eadd2ec5f6a4c61f55010d1231befd0e239e4d Mon Sep 17 00:00:00 2001 From: ykan821 Date: Tue, 23 Jun 2026 22:49:44 +0800 Subject: [PATCH 24/24] =?UTF-8?q?chore:=20=E5=8D=87=E7=BA=A7=20phpunit.xml?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=BE=85?= =?UTF-8?q?=E5=8A=9E=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - phpunit.xml 改用 PHPUnit 10 schema 声明 + cacheDirectory - .gitignore 收纳 .phpunit.cache/ - CLAUDE.md:Rebuild 异常处理、cursor/chunk API 重构标记完成 Co-Authored-By: Claude --- .gitignore | 1 + CLAUDE.md | 4 ++-- phpunit.xml | 23 ++++++++++------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 08df105..a311532 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ Thumbs.db .env .php-cs-fixer.cache .phpunit.result.cache +.phpunit.cache/ diff --git a/CLAUDE.md b/CLAUDE.md index cec014b..4a3e1d2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -50,13 +50,13 @@ PSR-5 规范。 - [x] **命名参数一致性**:公开方法参数名是 API 的一部分,全库审查确保命名统一(如 connection/name/client 不混用) - [x] **PHP 8 现代化(Index 层)**:全 12 文件 strict_types + 构造器提升 + readonly + 属性/返回/参数类型 + 联合类型;callable 属性(resolver / errorHandler / dataSource)因 PHP 禁止 callable 作属性类型,保留 docblock - [x] **PHP 8 现代化(DSL 层)**:Node/Query/Agg + 122 leaf 类全部完成。strict_types 全 151 文件;4 原子属性类型同步全 leaf;leaf 参数类型对照 ES docblock 完成;`$_properties` 三模式统一为 `?array`(新增 `$_raw` 承接整体透传,null 保留为合法空态);`toJson` 加 `:string` + false 检查;`toArray` 因多态返回(array/stdClass/null)不强加 PHP 返回类型 -- [ ] **Rebuild 异常处理**:run() 改为 try-catch + releaseLock 分离,releaseLock 不吞任何异常,forceUnlock 单独处理 404(文档不存在 vs 索引不存在的 404 需区分);isLocked() 只吞 404 不吞其他 ClientResponseException;rebuild 失败优先抛原始异常;ensureLockIndex() replicas=0 在多节点集群有风险需注释说明 +- [x] **Rebuild 异常处理**:run() 分离 try-catch(失败优先抛原始异常,成功后释放锁失败抛 RuntimeException 说明 rebuild 已完成);releaseLock 只吞 404;forceUnlock 独立实现吞 404;isLocked 只在 404 返回 false、其他 ES 错误传播 - [x] **$client 抽到 Registry 类**:拆为 ClientManager / EventDispatcher / Pagination,Index 不再持有静态状态 - [x] **Node 构造函数重构**:拆分为 fromKeyValue/fromClosure/fromArrayField/fromScalar - [x] **Bulk/Rebuild onError 设计**:Bulk 加 onError(callback) 默认 throw,Rebuild 删 skipErrors 加 onError,删 rebuild.import.failed 事件 - [ ] **补核心路径的边界测试**:scroll、bulk 分批、rebuild 失败回滚 - [ ] **搭建集成测试基建**:`ELASTICKIT_TEST_HOST` 驱动,随机索引名隔离 -- [ ] **cursor/chunk API 重构**:现 `cursor()` 返回批次(Results)命名不准。拆为 `chunk($duration): Generator`(按批,即现 cursor 改名)+ `cursor($duration): Generator`(逐条 doc,内部扁平化 chunk、复用其 finally clear);保留 `scroll()/next()/clear()` 作低层原语。待定:单条 yield 完整 hit(带 _id/_score)还是只 _source;底层未来可换 PIT+search_after(上层签名不变) +- [x] **cursor/chunk API 重构**:`chunk($duration): Generator` 按批 yield Results;`cursor($duration): Generator` 逐条 yield 完整 hit(_id/_score/_source,yield from chunk 的 hits、复用其 finally clear);保留 `scroll()/next()/clear()` 作低层原语。底层未来可换 PIT+search_after(上层签名不变) ## 测试 diff --git a/phpunit.xml b/phpunit.xml index 944f10f..4166425 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,15 +1,12 @@ - - - - tests - tests/Index - - - tests/Index - - + + + + tests + tests/Index + + + tests/Index + +