Skip to content

Commit 6ff42a0

Browse files
committed
Merge branch 'master' into 2019-04-05-mapping-generation-changes
2 parents 1152d7a + a2225fd commit 6ff42a0

25 files changed

+65
-324
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ php:
44
- '7.0'
55

66
env:
7-
- SYMFONY_VERSION="3.4.*" ES_VERSION="5.6.8"
7+
- SYMFONY_VERSION="3.4.*" ES_VERSION="6.2.4"
88

99
matrix:
1010
allow_failures:
1111
- php: hhvm
1212
include:
1313
- php: 7.1
14-
env: SYMFONY_VERSION="3.3.*" ES_VERSION="5.6.8"
14+
env: SYMFONY_VERSION="3.3.*" ES_VERSION="6.2.4"
1515
- php: 7.1
16-
env: SYMFONY_VERSION="3.2.*" ES_VERSION="5.6.8"
16+
env: SYMFONY_VERSION="3.2.*" ES_VERSION="6.2.4"
1717
- php: 7.1
18-
env: SYMFONY_VERSION="2.7.*" ES_VERSION="5.6.8"
18+
env: SYMFONY_VERSION="2.7.*" ES_VERSION="6.2.4"
1919

2020
install:
2121
- composer require --no-update symfony/symfony:${SYMFONY_VERSION}

Annotation/Document.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ final class Document implements DumperInterface
2222
*/
2323
public $repositoryClass;
2424

25-
/**
26-
* Document parent type.
27-
*
28-
* @var string
29-
*/
30-
public $parent;
31-
3225
/**
3326
* Settings directly passed to Elasticsearch client as-is
3427
*

Annotation/ParentId.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

DTO/BulkQueryItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct($operation, $index, $type, array $query, array $meta
5454

5555
// in case some meta param is specified as part of the query and not in $metaParams, move it there
5656
// (this happens when converting a document entity to an array)
57-
foreach (['_id', '_parent'] as $metaParam) {
57+
foreach (['_id'] as $metaParam) {
5858
if (isset($query[$metaParam])) {
5959
$metaParams[$metaParam] = $query[$metaParam];
6060
unset($query[$metaParam]);

Mapping/DocumentParser.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Sineflow\ElasticsearchBundle\Annotation\DocObject;
88
use Sineflow\ElasticsearchBundle\Annotation\Document;
99
use Sineflow\ElasticsearchBundle\Annotation\Id;
10-
use Sineflow\ElasticsearchBundle\Annotation\ParentId;
1110
use Sineflow\ElasticsearchBundle\Annotation\Property;
1211
use Sineflow\ElasticsearchBundle\Annotation\Score;
1312
use Sineflow\ElasticsearchBundle\LanguageProvider\LanguageProviderInterface;
@@ -88,27 +87,15 @@ public function parse(\ReflectionClass $documentReflection, array $indexAnalyzer
8887
/** @var Document $classAnnotation */
8988
$classAnnotation = $this->reader->getClassAnnotation($documentReflection, Document::class);
9089

91-
if ($classAnnotation !== null) {
92-
if ($classAnnotation->parent !== null) {
93-
$parent = $this->getDocumentType(
94-
new \ReflectionClass($this->documentLocator->resolveClassName($classAnnotation->parent))
95-
);
96-
} else {
97-
$parent = null;
98-
}
90+
if (null !== $classAnnotation) {
9991
$type = $this->getDocumentType($documentReflection);
10092

10193
$properties = $this->getProperties($documentReflection, $indexAnalyzers);
10294

10395
$metadata = [
10496
'type' => $type,
10597
'properties' => $properties,
106-
'fields' => array_filter(
107-
array_merge(
108-
$classAnnotation->dump(),
109-
['_parent' => $parent === null ? null : ['type' => $parent]]
110-
)
111-
),
98+
'fields' => array_filter($classAnnotation->dump()),
11299
'propertiesMetadata' => $this->getPropertiesMetadata($documentReflection),
113100
'objects' => $this->getObjects(),
114101
'repositoryClass' => $classAnnotation->repositoryClass,
@@ -140,7 +127,6 @@ public function getPropertiesMetadata(\ReflectionClass $documentReflection)
140127
foreach ($this->getDocumentPropertiesReflection($documentReflection) as $propertyName => $property) {
141128
$propertyAnnotation = $this->getPropertyAnnotationData($property);
142129
$propertyAnnotation = $propertyAnnotation ?: $this->reader->getPropertyAnnotation($property, Id::class);
143-
$propertyAnnotation = $propertyAnnotation ?: $this->reader->getPropertyAnnotation($property, ParentId::class);
144130
$propertyAnnotation = $propertyAnnotation ?: $this->reader->getPropertyAnnotation($property, Score::class);
145131

146132
// Ignore class properties without any recognized annotation
@@ -184,15 +170,6 @@ public function getPropertiesMetadata(\ReflectionClass $documentReflection)
184170
];
185171
break;
186172

187-
case ParentId::class:
188-
$propertyAnnotation->name = '_parent';
189-
$propertyAnnotation->type = 'keyword';
190-
$propertyMetadata[$propertyAnnotation->name] = [
191-
'propertyName' => $propertyName,
192-
'type' => $propertyAnnotation->type,
193-
];
194-
break;
195-
196173
case Score::class:
197174
$propertyAnnotation->name = '_score';
198175
$propertyAnnotation->type = 'float';
@@ -283,7 +260,6 @@ private function registerAnnotations()
283260
'Property',
284261
'DocObject',
285262
'Id',
286-
'ParentId',
287263
'Score',
288264
];
289265

@@ -314,7 +290,7 @@ private function getDocumentPropertiesReflection(\ReflectionClass $documentRefle
314290
}
315291

316292
$parentReflection = $documentReflection->getParentClass();
317-
if ($parentReflection !== false) {
293+
if (false !== $parentReflection) {
318294
$properties = array_merge(
319295
$properties,
320296
array_diff_key($this->getDocumentPropertiesReflection($parentReflection), $properties)

Resources/doc/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ sineflow_elasticsearch:
2626
analysis:
2727
filter:
2828
unigram_filter:
29-
type: nGram
29+
type: ngram
3030
min_gram: 1
3131
max_gram: 20
3232
3333
tokenizer:
3434
email_tokenizer:
35-
type: nGram
35+
type: ngram
3636
min_gram: 3
3737
max_gram: 60
3838

Resources/doc/crud.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $repo->persistRaw($product);
8686
$im->getConnection()->commit();
8787
```
8888

89-
> **id** is a special field that comes from `AbstractDocument` and translates to **\_id** in Elasticsearch, just like **parent**, which translates to **\_parent**.
89+
> **id** is a special field that comes from `AbstractDocument` and translates to **\_id** in Elasticsearch.
9090
9191
## Update a document
9292

Resources/doc/mapping.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ The class representing a document must be annotated as `@ES\Document`. The follo
4040
repositoryClass="AppBundle\Document\Repository\ProductRepository"
4141
```
4242

43-
- `parent` Allows you to specify a parent type ([more info here](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-parent-field.html))
44-
```
45-
parent="AppBundle:ParentDoc"
46-
```
47-
This should be used in conjunction with the <a href="#parentid">@ES\ParentId</a> meta annotation
48-
4943
- `options` Allows to specify any type option supported by Elasticsearch, such as [\_all](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html), [dynamic_templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html), [dynamic_date_formats](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html#date-detection), etc.
5044

5145
### Property annotation
@@ -147,34 +141,6 @@ class Product
147141
```
148142
> Such property is already defined in `AbstractDocument`, so you can just extend it.
149143
150-
#### <a name=parentid></a>@ES\ParentId
151-
152-
When you need to have a parent-child relation between two types in your index, you'd need access to the `_parent` meta field of the document.
153-
To do that, you will need a class property with that annotation that can be used for both setting and getting the `_parent` value.
154-
155-
```php
156-
use Sineflow\ElasticsearchBundle\Annotation as ES;
157-
158-
/**
159-
* @ES\Document(
160-
* type="answers",
161-
* parent="AppBundle:Question"
162-
* );
163-
*/
164-
class Answer
165-
{
166-
/**
167-
* @var string
168-
*
169-
* @ES\ParentId
170-
*/
171-
public $parent;
172-
}
173-
```
174-
> Do not forget to also set the `parent` property of the `@ES\Document` annotation to specify the parent entity for that type.
175-
176-
**WARNING**: If using Elasticsearch 1.x, the parent property value will NOT be populated when retrieving documents, as Elasticsearch does not return it by default!
177-
178144
## DocObject class annotation
179145

180146
Object classes are almost the same as document classes:

Result/DocumentConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function convertToDocument($rawData, $documentClass)
7171
}
7272

7373
// Add special fields to data
74-
foreach (['_id', '_parent', '_score'] as $specialField) {
74+
foreach (['_id', '_score'] as $specialField) {
7575
if (isset($rawData[$specialField])) {
7676
$data[$specialField] = $rawData[$specialField];
7777
}

Subscriber/EntityTrackerSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function onPostCommit(PostCommitEvent $postCommitEvent)
7070
$idValue = current($postCommitEvent->getBulkResponse()['items'][$bulkOperationIndex])['_id'];
7171
$idPropertyMetadata = $entityData['metadata']['_id'];
7272
$entity = $entityData['entity'];
73-
if ($idPropertyMetadata['propertyAccess'] == DocumentMetadata::PROPERTY_ACCESS_PRIVATE) {
73+
if (DocumentMetadata::PROPERTY_ACCESS_PRIVATE === $idPropertyMetadata['propertyAccess']) {
7474
$entity->{$idPropertyMetadata['methods']['setter']}($idValue);
7575
} else {
7676
$entity->{$idPropertyMetadata['propertyName']} = $idValue;

0 commit comments

Comments
 (0)