From fe5c675d7f98edc7cda5ca97f0370292f53db899 Mon Sep 17 00:00:00 2001 From: Morne Alberts Date: Mon, 6 Jan 2025 06:26:06 +0200 Subject: [PATCH 1/3] Update badges (#2239) --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c61642113..e5ac0f5436 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ Elastica: elasticsearch PHP Client ================================== -[![Latest Stable Version](https://poser.pugx.org/ruflin/Elastica/v/stable.png)](https://packagist.org/packages/ruflin/elastica) -[![Build Status](https://github.com/ruflin/elastica/workflows/Continuous%20integration/badge.svg?branch=master)](https://github.com/ruflin/Elastica/actions?query=workflow%3A%22Continuous%20integration%22%20branch%3Amaster) -[![codecov.io](http://codecov.io/github/ruflin/Elastica/coverage.svg?branch=master)](http://codecov.io/github/ruflin/Elastica?branch=master) -[![Dependency Status](https://www.versioneye.com/php/ruflin:elastica/dev-master/badge.svg)](https://www.versioneye.com/php/ruflin:elastica/dev-master) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ruflin/Elastica/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ruflin/Elastica/?branch=master) -[![Total Downloads](https://poser.pugx.org/ruflin/Elastica/downloads.png)](https://packagist.org/packages/ruflin/elastica) +[![Latest Stable Version](https://poser.pugx.org/ruflin/Elastica/v/stable)](https://packagist.org/packages/ruflin/elastica) +[![Build Status](https://github.com/ruflin/elastica/actions/workflows/continuous-integration.yaml/badge.svg?branch=7.x)](https://github.com/ruflin/Elastica/actions/workflows/continuous-integration.yaml?query=branch%3A7.x) +[![codecov.io](https://codecov.io/gh/ruflin/Elastica/branch/7.x/graph/badge.svg)](https://app.codecov.io/github/ruflin/Elastica/tree/7.x) +[![Total Downloads](https://poser.pugx.org/ruflin/Elastica/downloads)](https://packagist.org/packages/ruflin/elastica) [![Join the chat at https://gitter.im/ruflin/Elastica](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ruflin/Elastica?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) All documentation for Elastica can be found under [Elastica.io](http://Elastica.io/). From cc585d325b9a81652dbc2b140639c5f5c331e6f8 Mon Sep 17 00:00:00 2001 From: ryu818 Date: Fri, 16 May 2025 07:59:49 +0900 Subject: [PATCH 2/3] Add support for Search Option "seq_no_primary_term" and Index Options "if_primary_term","if_seq_no" --- src/Index.php | 6 ++++-- src/Search.php | 2 ++ tests/IndexTest.php | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Index.php b/src/Index.php index 745bd5579d..3dee202193 100644 --- a/src/Index.php +++ b/src/Index.php @@ -232,6 +232,8 @@ public function addDocument(Document $doc): Response 'retry_on_conflict', 'routing', 'timeout', + 'if_primary_term', + 'if_seq_no', ] ); @@ -243,8 +245,8 @@ public function addDocument(Document $doc): Response $data = $response->getData(); // set autogenerated id to document if ($response->isOk() && ( - $doc->isAutoPopulate() || $this->getClient()->getConfigValue(['document', 'autoPopulate'], false) - )) { + $doc->isAutoPopulate() || $this->getClient()->getConfigValue(['document', 'autoPopulate'], false) + )) { if (isset($data['_id']) && !$doc->hasId()) { $doc->setId($data['_id']); } diff --git a/src/Search.php b/src/Search.php index f80f144da9..59aea2aa39 100644 --- a/src/Search.php +++ b/src/Search.php @@ -37,6 +37,7 @@ class Search public const OPTION_SHARD_REQUEST_CACHE = 'request_cache'; public const OPTION_FILTER_PATH = 'filter_path'; public const OPTION_TYPED_KEYS = 'typed_keys'; + public const OPTION_SEQ_NO_PRIMARY_TERM = 'seq_no_primary_term'; /* * Search types @@ -457,6 +458,7 @@ protected function validateOption(string $key): void case self::OPTION_SHARD_REQUEST_CACHE: case self::OPTION_FILTER_PATH: case self::OPTION_TYPED_KEYS: + case self::OPTION_SEQ_NO_PRIMARY_TERM: return; } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 604837d9cb..38b0605ea4 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -569,7 +569,14 @@ public function testAddDocumentAcrossIndices(): void $index1Doc = $index1->getDocument(1); - $index2->addDocument($index1Doc); + // Since if_primary_term and if_seq_no are automatically set in getDocument, + // it is an error to add them to another Index as is. + // Therefore, convert the acquired document to an Array before calling + $doc = new Document('1'); + $arr = $index1Doc->toArray(); + $doc->setData($arr['_source']); + + $index2->addDocument($doc); $index2Doc = $index1->getDocument(1); $this->assertEquals('Hello world', $index2Doc->get('title')); From f2d664e935968f43b72bfd0f0ad523480db2fa40 Mon Sep 17 00:00:00 2001 From: ryu818 Date: Thu, 12 Jun 2025 13:17:52 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20array=5Ffilter=E3=81=AF=E3=83=87?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E3=81=A7=E5=80=A4=E3=81=8C?= =?UTF-8?q?false=E3=81=A8=E8=A9=95=E4=BE=A1=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=82=82=E3=81=AE=E3=82=92=E9=99=A4=E5=A4=96=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=80=81if=5Fseq=5Fno=E3=81=AE=E5=80=A4?= =?UTF-8?q?=E3=81=8C0=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AF=E9=99=A4?= =?UTF-8?q?=E5=A4=96=E3=81=95=E3=82=8C=E3=82=8B=E3=80=82=E3=81=9D=E3=81=AE?= =?UTF-8?q?=E3=81=9F=E3=82=81=E9=99=A4=E5=A4=96=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AbstractUpdateAction.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/AbstractUpdateAction.php b/src/AbstractUpdateAction.php index 6ddbf84163..b6c46dad59 100644 --- a/src/AbstractUpdateAction.php +++ b/src/AbstractUpdateAction.php @@ -470,16 +470,33 @@ public function hasUpsert() } /** + * array_filterはデフォルトで値がfalseと評価されるものを除外するため、if_seq_noの値が0の場合は除外される。そのため除外しないように修正 + * * @param array $fields if empty array all options will be returned * * @return array */ public function getOptions(array $fields = []) + { + if ($fields) { + return array_filter( + array_intersect_key($this->getParams(), array_flip($fields)), + function ($value) { + return $value !== null; // nullのみ除外し、0は含める + } + ); + } + + return array_filter($this->getParams(), function ($value) { + return $value !== null; // nullのみ除外し、0は含める + }); + } + /*public function getOptions(array $fields = []) { if ($fields) { return \array_filter(\array_intersect_key($this->getParams(), \array_flip($fields))); } return \array_filter($this->getParams()); - } + }*/ }