From 922965183cf309b83652c553072717383735aab9 Mon Sep 17 00:00:00 2001 From: Antoine Bluchet Date: Fri, 15 Sep 2023 15:46:58 +0200 Subject: [PATCH] Revert "feat(elasticsearch): filtering on nested fields (#5820)" This reverts commit d85884d53bda3f0bfc60435f5b0e69e7522d70c8. --- .../Tests/Filter/MatchFilterTest.php | 34 +------------------ .../Tests/Filter/TermFilterTest.php | 34 +------------------ .../Tests/Util/FieldDatatypeTraitTest.php | 13 ------- src/Elasticsearch/Util/FieldDatatypeTrait.php | 6 ++-- 4 files changed, 4 insertions(+), 83 deletions(-) diff --git a/src/Elasticsearch/Tests/Filter/MatchFilterTest.php b/src/Elasticsearch/Tests/Filter/MatchFilterTest.php index 114f5fe77f5..b03b40b6764 100644 --- a/src/Elasticsearch/Tests/Filter/MatchFilterTest.php +++ b/src/Elasticsearch/Tests/Filter/MatchFilterTest.php @@ -87,7 +87,7 @@ public function testApply(): void ); } - public function testApplyWithNestedArrayProperty(): void + public function testApplyWithNestedProperty(): void { $fooType = new Type(Type::BUILTIN_TYPE_ARRAY, false, Foo::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class)); $barType = new Type(Type::BUILTIN_TYPE_STRING); @@ -119,38 +119,6 @@ public function testApplyWithNestedArrayProperty(): void ); } - public function testApplyWithNestedObjectProperty(): void - { - $fooType = new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class); - $barType = new Type(Type::BUILTIN_TYPE_STRING); - - $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); - $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([$fooType]))->shouldBeCalled(); - $propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withBuiltinTypes([$barType]))->shouldBeCalled(); - - $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); - $resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled(); - - $nameConverterProphecy = $this->prophesize(NameConverterInterface::class); - $nameConverterProphecy->normalize('foo.bar', Foo::class, null, Argument::type('array'))->willReturn('foo.bar')->shouldBeCalled(); - $nameConverterProphecy->normalize('foo', Foo::class, null, Argument::type('array'))->willReturn('foo')->shouldBeCalled(); - - $matchFilter = new MatchFilter( - $this->prophesize(PropertyNameCollectionFactoryInterface::class)->reveal(), - $propertyMetadataFactoryProphecy->reveal(), - $resourceClassResolverProphecy->reveal(), - $this->prophesize(IriConverterInterface::class)->reveal(), - $this->prophesize(PropertyAccessorInterface::class)->reveal(), - $nameConverterProphecy->reveal(), - ['foo.bar' => null] - ); - - self::assertSame( - ['bool' => ['must' => [['nested' => ['path' => 'foo', 'query' => ['match' => ['foo.bar' => 'Krupicka']]]]]]], - $matchFilter->apply([], Foo::class, null, ['filters' => ['foo.bar' => 'Krupicka']]) - ); - } - public function testApplyWithInvalidFilters(): void { $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); diff --git a/src/Elasticsearch/Tests/Filter/TermFilterTest.php b/src/Elasticsearch/Tests/Filter/TermFilterTest.php index 34c713e042a..a73abe96b4a 100644 --- a/src/Elasticsearch/Tests/Filter/TermFilterTest.php +++ b/src/Elasticsearch/Tests/Filter/TermFilterTest.php @@ -87,7 +87,7 @@ public function testApply(): void ); } - public function testApplyWithNestedArrayProperty(): void + public function testApplyWithNestedProperty(): void { $fooType = new Type(Type::BUILTIN_TYPE_ARRAY, false, Foo::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class)); $barType = new Type(Type::BUILTIN_TYPE_STRING); @@ -119,38 +119,6 @@ public function testApplyWithNestedArrayProperty(): void ); } - public function testApplyWithNestedObjectProperty(): void - { - $fooType = new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class); - $barType = new Type(Type::BUILTIN_TYPE_STRING); - - $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); - $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([$fooType]))->shouldBeCalled(); - $propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withBuiltinTypes([$barType]))->shouldBeCalled(); - - $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); - $resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled(); - - $nameConverterProphecy = $this->prophesize(NameConverterInterface::class); - $nameConverterProphecy->normalize('foo.bar', Foo::class, null, Argument::type('array'))->willReturn('foo.bar')->shouldBeCalled(); - $nameConverterProphecy->normalize('foo', Foo::class, null, Argument::type('array'))->willReturn('foo')->shouldBeCalled(); - - $termFilter = new TermFilter( - $this->prophesize(PropertyNameCollectionFactoryInterface::class)->reveal(), - $propertyMetadataFactoryProphecy->reveal(), - $resourceClassResolverProphecy->reveal(), - $this->prophesize(IriConverterInterface::class)->reveal(), - $this->prophesize(PropertyAccessorInterface::class)->reveal(), - $nameConverterProphecy->reveal(), - ['foo.bar' => null] - ); - - self::assertSame( - ['bool' => ['must' => [['nested' => ['path' => 'foo', 'query' => ['term' => ['foo.bar' => 'Krupicka']]]]]]], - $termFilter->apply([], Foo::class, null, ['filters' => ['foo.bar' => 'Krupicka']]) - ); - } - public function testApplyWithInvalidFilters(): void { $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); diff --git a/src/Elasticsearch/Tests/Util/FieldDatatypeTraitTest.php b/src/Elasticsearch/Tests/Util/FieldDatatypeTraitTest.php index 452f59cc1f5..4979c983e31 100644 --- a/src/Elasticsearch/Tests/Util/FieldDatatypeTraitTest.php +++ b/src/Elasticsearch/Tests/Util/FieldDatatypeTraitTest.php @@ -32,16 +32,6 @@ public function testGetNestedFieldPath(): void $fieldDatatype = $this->getValidFieldDatatype(); self::assertSame('foo.bar', $fieldDatatype->getNestedFieldPath(Foo::class, 'foo.bar.baz')); - self::assertSame('foo', $fieldDatatype->getNestedFieldPath(Foo::class, 'foo.baz')); - self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'baz')); - } - - public function testGetNestedFieldInNestedCollection(): void - { - $fieldDatatype = $this->getValidFieldDatatype(); - - self::assertSame('bar.foo', $fieldDatatype->getNestedFieldPath(Foo::class, 'bar.foo.baz')); - self::assertSame('bar', $fieldDatatype->getNestedFieldPath(Foo::class, 'bar.foo')); self::assertNull($fieldDatatype->getNestedFieldPath(Foo::class, 'baz')); } @@ -82,7 +72,6 @@ public function testIsNestedField(): void $fieldDatatype = $this->getValidFieldDatatype(); self::assertTrue($fieldDatatype->isNestedField(Foo::class, 'foo.bar.baz')); - self::assertTrue($fieldDatatype->isNestedField(Foo::class, 'foo.baz')); self::assertFalse($fieldDatatype->isNestedField(Foo::class, 'baz')); } @@ -90,12 +79,10 @@ private function getValidFieldDatatype() { $fooType = new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class); $barType = new Type(Type::BUILTIN_TYPE_ARRAY, false, Foo::class, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, Foo::class)); - $bazType = new Type(Type::BUILTIN_TYPE_STRING, false, Foo::class); $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); $propertyMetadataFactoryProphecy->create(Foo::class, 'foo')->willReturn((new ApiProperty())->withBuiltinTypes([$fooType]))->shouldBeCalled(); $propertyMetadataFactoryProphecy->create(Foo::class, 'bar')->willReturn((new ApiProperty())->withBuiltinTypes([$barType]))->shouldBeCalled(); - $propertyMetadataFactoryProphecy->create(Foo::class, 'baz')->willReturn((new ApiProperty())->withBuiltinTypes([$bazType])); $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); $resourceClassResolverProphecy->isResourceClass(Foo::class)->willReturn(true)->shouldBeCalled(); diff --git a/src/Elasticsearch/Util/FieldDatatypeTrait.php b/src/Elasticsearch/Util/FieldDatatypeTrait.php index d139d74f311..b4a238e148d 100644 --- a/src/Elasticsearch/Util/FieldDatatypeTrait.php +++ b/src/Elasticsearch/Util/FieldDatatypeTrait.php @@ -69,7 +69,7 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s ) { $nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties)); - return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath"; + return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath"; } if ( @@ -78,9 +78,7 @@ private function getNestedFieldPath(string $resourceClass, string $property): ?s && null !== ($className = $type->getClassName()) && $this->resourceClassResolver->isResourceClass($className) ) { - $nestedPath = $this->getNestedFieldPath($className, implode('.', $properties)); - - return null === $nestedPath ? $currentProperty : "$currentProperty.$nestedPath"; + return $currentProperty; } }