Skip to content

Commit 79a3f7c

Browse files
committed
Merge pull request #373 from martiis/extra_document_properties
Added dynamic, transform, dynamic_date_format properties for Document an...
2 parents 1dcff15 + b99ba80 commit 79a3f7c

File tree

6 files changed

+54
-13
lines changed

6 files changed

+54
-13
lines changed

Annotation/Document.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
namespace ONGR\ElasticsearchBundle\Annotation;
1313

14+
use ONGR\ElasticsearchBundle\Mapping\DumperInterface;
15+
1416
/**
1517
* Annotation to mark a class as an Elasticsearch document.
1618
*
1719
* @Annotation
1820
* @Target("CLASS")
1921
*/
20-
final class Document
22+
final class Document implements DumperInterface
2123
{
2224
/**
2325
* @var bool
@@ -48,4 +50,37 @@ final class Document
4850
* @var array
4951
*/
5052
public $all;
53+
54+
/**
55+
* @var string
56+
*/
57+
public $dynamic;
58+
59+
/**
60+
* @var array
61+
*/
62+
public $transform;
63+
64+
/**
65+
* @var array
66+
*/
67+
public $dynamicDateFormats;
68+
69+
/**
70+
* {@inheritdoc}
71+
*/
72+
public function dump(array $exclude = [])
73+
{
74+
return array_diff_key(
75+
[
76+
'_ttl' => $this->ttl,
77+
'_all' => $this->all,
78+
'enabled' => $this->enabled,
79+
'dynamic' => $this->dynamic,
80+
'transform' => $this->transform,
81+
'dynamic_date_formats' => $this->dynamicDateFormats,
82+
],
83+
$exclude
84+
);
85+
}
5186
}

Mapping/DocumentParser.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,10 @@ public function parse(\ReflectionClass $reflectionClass)
112112
return [
113113
$type => [
114114
'properties' => $properties,
115-
'fields' => [
116-
'_parent' => $parent === null ? null : ['type' => $parent],
117-
'_ttl' => $class->ttl,
118-
'enabled' => $class->enabled,
119-
'_all' => $class->all,
120-
],
115+
'fields' => array_merge(
116+
$class->dump(),
117+
['_parent' => $parent === null ? null : ['type' => $parent]]
118+
),
121119
'aliases' => $this->getAliases($reflectionClass),
122120
'objects' => $this->getObjects(),
123121
'proxyNamespace' => ProxyFactory::getProxyNamespace($reflectionClass, true),

Tests/Functional/Annotation/DocumentTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public function testDocumentMappingWithAllFieldSetToFalse()
2929
'_ttl' => null,
3030
'enabled' => null,
3131
'_all' => ['enabled' => false],
32+
'dynamic' => null,
33+
'transform' => null,
34+
'dynamic_date_formats' => null,
3235
];
3336
$this->assertEquals($expectedResult, $result);
3437
}

Tests/Functional/DSL/Aggregation/DateRangeAggregationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ protected function getDataArray()
2828
'comment' => [
2929
[
3030
'_parent' => 1,
31-
'sub_title' => 'foo',
31+
'userName' => 'foo',
3232
'createdAt' => '2010',
3333
],
3434
[
3535
'_parent' => 1,
36-
'sub_title' => 'bar bar',
36+
'userName' => 'bar bar',
3737
'createdAt' => '2011',
3838
],
3939
[
4040
'_parent' => 2,
41-
'sub_title' => 'foo bar',
41+
'userName' => 'foo bar',
4242
'createdAt' => '2013',
4343
],
4444
[
4545
'_parent' => 2,
46-
'sub_title' => 'bar',
46+
'userName' => 'bar',
4747
'createdAt' => '2015',
4848
],
4949
],

Tests/app/fixture/Acme/TestBundle/Document/Comment.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
/**
2020
* Comment document for testing.
2121
*
22-
* @ES\Document(type="comment", parent="AcmeTestBundle:Content", ttl={"enabled":true, "default": "1d"})
22+
* @ES\Document(
23+
* type="comment",
24+
* parent="AcmeTestBundle:Content",
25+
* ttl={"enabled":true, "default": "1d"},
26+
* dynamic="strict"
27+
* )
2328
*/
2429
class Comment extends AbstractDocument
2530
{

Tests/app/fixture/Json/collector_body_0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
}
88
},
99
"fields": [
10-
"_parent",
1110
"_ttl",
11+
"_parent",
1212
"_source"
1313
]
1414
}

0 commit comments

Comments
 (0)