Skip to content

Commit 41f14b6

Browse files
authored
Merge pull request #1 from nlx-lars/es-5-aws-support
BUGFIX: Fix script compilation errors
2 parents 35c3a28 + 32f6dd6 commit 41f14b6

7 files changed

Lines changed: 130 additions & 214 deletions

File tree

Classes/Driver/Version1/IndexerDriver.php

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@ public function document($indexName, NodeInterface $node, ElasticSearchDocument
4949
]
5050
],
5151
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.7/docs-update.html
52-
'script' => [
53-
'script_id' => 'updateFulltextParts',
54-
'lang' => 'groovy',
52+
[
53+
'script' => '
54+
fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new LinkedHashMap());
55+
fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new LinkedHashMap());
56+
ctx._source = newData;
57+
ctx._source.__fulltext = fulltext;
58+
ctx._source.__fulltextParts = fulltextParts
59+
',
5560
'params' => [
5661
'newData' => $documentData
57-
]
58-
],
59-
'upsert' => $documentData
62+
],
63+
'upsert' => $documentData,
64+
'lang' => 'groovy'
65+
]
6066
];
6167
} else {
6268
// non-fulltext-root documents can be indexed as-they-are
@@ -112,22 +118,52 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, $targe
112118
]
113119
],
114120
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html
115-
// first, update the __fulltextParts, then re-generate the __fulltext from all __fulltextParts
116-
'script' => [
117-
'script_id' => 'regenerateFulltext',
118-
'lang' => 'groovy',
121+
[
122+
// first, update the __fulltextParts, then re-generate the __fulltext from all __fulltextParts
123+
'script' => '
124+
if (!(ctx._source.containsKey("__fulltextParts") && ctx._source.__fulltextParts instanceof Map)) {
125+
ctx._source.__fulltextParts = new LinkedHashMap();
126+
}
127+
128+
if (nodeIsRemoved || nodeIsHidden || fulltext.size() == 0) {
129+
if (ctx._source.__fulltextParts.containsKey(identifier)) {
130+
ctx._source.__fulltextParts.remove(identifier);
131+
}
132+
} else {
133+
ctx._source.__fulltextParts[identifier] = fulltext;
134+
}
135+
ctx._source.__fulltext = new LinkedHashMap();
136+
137+
Iterator<LinkedHashMap.Entry<String, LinkedHashMap>> fulltextByNode = ctx._source.__fulltextParts.entrySet().iterator();
138+
for (fulltextByNode; fulltextByNode.hasNext();) {
139+
Iterator<LinkedHashMap.Entry<String, String>> elementIterator = fulltextByNode.next().getValue().entrySet().iterator();
140+
for (elementIterator; elementIterator.hasNext();) {
141+
Map.Entry<String, String> element = elementIterator.next();
142+
String value;
143+
144+
if (ctx._source.__fulltext.containsKey(element.key)) {
145+
value = ctx._source.__fulltext[element.key] + " " + element.value.trim();
146+
} else {
147+
value = element.value.trim();
148+
}
149+
150+
ctx._source.__fulltext[element.key] = value;
151+
}
152+
}
153+
',
119154
'params' => [
120155
'identifier' => $node->getIdentifier(),
121156
'nodeIsRemoved' => $node->isRemoved(),
122157
'nodeIsHidden' => $node->isHidden(),
123158
'fulltext' => $fulltextIndexOfNode
124159
],
125-
],
126-
'upsert' => [
127-
'__fulltext' => $fulltextIndexOfNode,
128-
'__fulltextParts' => [
129-
$node->getIdentifier() => $fulltextIndexOfNode
130-
]
160+
'upsert' => [
161+
'__fulltext' => $fulltextIndexOfNode,
162+
'__fulltextParts' => [
163+
$node->getIdentifier() => $fulltextIndexOfNode
164+
]
165+
],
166+
'lang' => 'groovy'
131167
]
132168
];
133169
}

Classes/Driver/Version1/Mapping/NodeTypeMappingBuilder.php

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\AbstractNodeTypeMappingBuilder;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
1615
use Flowpack\ElasticSearch\Domain\Model\Index;
1716
use Flowpack\ElasticSearch\Domain\Model\Mapping;
1817
use Flowpack\ElasticSearch\Mapping\MappingCollection;
@@ -28,12 +27,6 @@
2827
*/
2928
class NodeTypeMappingBuilder extends AbstractNodeTypeMappingBuilder
3029
{
31-
/**
32-
* @Flow\Inject
33-
* @var ElasticSearchClient
34-
*/
35-
protected $client;
36-
3730
/**
3831
* Builds a Mapping Collection from the configured node types
3932
*
@@ -46,8 +39,6 @@ public function buildMappingInformation(Index $index)
4639

4740
$mappings = new MappingCollection(MappingCollection::TYPE_ENTITY);
4841

49-
$this->setupStoredScripts($index);
50-
5142
/** @var NodeType $nodeType */
5243
foreach ($this->nodeTypeManager->getNodeTypes() as $nodeTypeName => $nodeType) {
5344
if ($nodeTypeName === 'unstructured' || $nodeType->isAbstract()) {
@@ -95,58 +86,4 @@ public function buildMappingInformation(Index $index)
9586

9687
return $mappings;
9788
}
98-
99-
/**
100-
* Store scripts used during indexing in Elasticsearch.
101-
*
102-
* @param Index $index
103-
* @return void
104-
*/
105-
protected function setupStoredScripts(Index $index)
106-
{
107-
$this->client->request(
108-
'POST',
109-
'/_scripts/groovy/updateFulltextParts',
110-
[],
111-
json_encode(['script' => '
112-
fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new HashMap());
113-
fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new HashMap());
114-
ctx._source = newData;
115-
ctx._source.__fulltext = fulltext;
116-
ctx._source.__fulltextParts = fulltextParts'
117-
])
118-
);
119-
120-
$this->client->request(
121-
'POST',
122-
'/_scripts/groovy/regenerateFulltext',
123-
[],
124-
json_encode(['script' => '
125-
ctx._source.__fulltext = new HashMap();
126-
if (!ctx._source.containsKey("__fulltextParts")) {
127-
ctx._source.__fulltextParts = new HashMap();
128-
}
129-
130-
if (nodeIsRemoved || nodeIsHidden || fulltext.size() == 0) {
131-
if (ctx._source.__fulltextParts.containsKey(identifier)) {
132-
ctx._source.__fulltextParts.remove(identifier);
133-
}
134-
} else {
135-
ctx._source.__fulltextParts.put(identifier, fulltext);
136-
}
137-
138-
ctx._source.__fulltextParts.each {
139-
originNodeIdentifier, partContent -> partContent.each {
140-
bucketKey, content ->
141-
if (ctx._source.__fulltext.containsKey(bucketKey)) {
142-
value = ctx._source.__fulltext[bucketKey] + " " + content.trim();
143-
} else {
144-
value = content.trim();
145-
}
146-
ctx._source.__fulltext[bucketKey] = value;
147-
}
148-
}'
149-
])
150-
);
151-
}
15289
}

Classes/Driver/Version2/IndexerDriver.php

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ public function document($indexName, NodeInterface $node, ElasticSearchDocument
4949
]
5050
],
5151
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/2.4/docs-update.html
52-
'script' => [
53-
'script_id' => 'updateFulltextParts',
54-
'lang' => 'groovy',
55-
'params' => [
56-
'newData' => $documentData
57-
]
58-
],
59-
'upsert' => $documentData
52+
[
53+
'script' => [
54+
'inline' => '
55+
fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new HashMap());
56+
fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new HashMap());
57+
ctx._source = newData;
58+
ctx._source.__fulltext = fulltext;
59+
ctx._source.__fulltextParts = fulltextParts
60+
',
61+
'params' => [
62+
'newData' => $documentData
63+
]
64+
],
65+
'upsert' => $documentData,
66+
'lang' => 'groovy'
67+
]
6068
];
6169
}
6270

@@ -120,8 +128,31 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, $targe
120128
[
121129
// first, update the __fulltextParts, then re-generate the __fulltext from all __fulltextParts
122130
'script' => [
123-
'script_id' => 'regenerateFulltext',
124-
'lang' => 'groovy',
131+
'inline' => '
132+
ctx._source.__fulltext = new HashMap();
133+
134+
if (!(ctx._source.containsKey("__fulltextParts") && ctx._source.__fulltextParts instanceof Map)) {
135+
ctx._source.__fulltextParts = new HashMap();
136+
}
137+
138+
if (nodeIsRemoved || nodeIsHidden || fulltext.size() == 0) {
139+
if (ctx._source.__fulltextParts.containsKey(identifier)) {
140+
ctx._source.__fulltextParts.remove(identifier);
141+
}
142+
} else {
143+
ctx._source.__fulltextParts.put(identifier, fulltext);
144+
}
145+
146+
ctx._source.__fulltextParts.each { originNodeIdentifier, partContent -> partContent.each { bucketKey, content ->
147+
if (ctx._source.__fulltext.containsKey(bucketKey)) {
148+
value = ctx._source.__fulltext[bucketKey] + " " + content.trim();
149+
} else {
150+
value = content.trim();
151+
}
152+
ctx._source.__fulltext[bucketKey] = value;
153+
}
154+
}
155+
',
125156
'params' => [
126157
'identifier' => $node->getIdentifier(),
127158
'nodeIsRemoved' => $node->isRemoved(),
@@ -133,6 +164,7 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, $targe
133164
'__fulltext' => $fulltextIndexOfNode,
134165
'__fulltextParts' => $upsertFulltextParts
135166
],
167+
'lang' => 'groovy'
136168
]
137169
];
138170
}

Classes/Driver/Version2/Mapping/NodeTypeMappingBuilder.php

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
* source code.
1212
*/
1313

14-
use Flowpack\ElasticSearch\Domain\Model\Index;
15-
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version1;
1614
use TYPO3\Flow\Annotations as Flow;
15+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Driver\Version1;
1716

1817
/**
1918
* NodeTypeMappingBuilder for Elasticsearch version 2.x
@@ -22,59 +21,4 @@
2221
*/
2322
class NodeTypeMappingBuilder extends Version1\Mapping\NodeTypeMappingBuilder
2423
{
25-
/**
26-
* Store scripts used during indexing in Elasticsearch.
27-
*
28-
* @param Index $index
29-
* @return void
30-
*/
31-
protected function setupStoredScripts(Index $index)
32-
{
33-
$this->client->request(
34-
'POST',
35-
'/_scripts/groovy/updateFulltextParts',
36-
[],
37-
json_encode(['script' => '
38-
fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new HashMap());
39-
fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new HashMap());
40-
41-
ctx._source = newData;
42-
ctx._source.__fulltext = fulltext;
43-
ctx._source.__fulltextParts = fulltextParts'
44-
])
45-
);
46-
47-
$this->client->request(
48-
'POST',
49-
'/_scripts/groovy/regenerateFulltext',
50-
[],
51-
json_encode(['script' => '
52-
ctx._source.__fulltext = new HashMap();
53-
54-
if (!(ctx._source.containsKey("__fulltextParts") && ctx._source.__fulltextParts instanceof Map)) {
55-
ctx._source.__fulltextParts = new HashMap();
56-
}
57-
58-
if (nodeIsRemoved || nodeIsHidden || fulltext.size() == 0) {
59-
if (ctx._source.__fulltextParts.containsKey(identifier)) {
60-
ctx._source.__fulltextParts.remove(identifier);
61-
}
62-
} else {
63-
ctx._source.__fulltextParts.put(identifier, fulltext);
64-
}
65-
66-
ctx._source.__fulltextParts.each {
67-
originNodeIdentifier, partContent -> partContent.each {
68-
bucketKey, content ->
69-
if (ctx._source.__fulltext.containsKey(bucketKey)) {
70-
value = ctx._source.__fulltext[bucketKey] + " " + content.trim();
71-
} else {
72-
value = content.trim();
73-
}
74-
ctx._source.__fulltext[bucketKey] = value;
75-
}
76-
}'
77-
])
78-
);
79-
}
8024
}

Classes/Driver/Version5/IndexerDriver.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ public function document($indexName, NodeInterface $node, ElasticSearchDocument
4242
'_retry_on_conflict' => 3
4343
]
4444
],
45-
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/2.4/docs-update.html
45+
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/5.0/docs-update.html
4646
[
4747
'script' => [
48-
'stored' => 'updateFulltextParts',
48+
'lang' => 'painless',
49+
'inline' => '
50+
HashMap fulltext = (ctx._source.containsKey("__fulltext") ? ctx._source.__fulltext : new HashMap());
51+
HashMap fulltextParts = (ctx._source.containsKey("__fulltextParts") ? ctx._source.__fulltextParts : new HashMap());
52+
ctx._source = params.newData;
53+
ctx._source.__fulltext = fulltext;
54+
ctx._source.__fulltextParts = fulltextParts',
4955
'params' => [
5056
'newData' => $documentData
5157
]
@@ -114,7 +120,32 @@ public function fulltext(NodeInterface $node, array $fulltextIndexOfNode, $targe
114120
[
115121
// first, update the __fulltextParts, then re-generate the __fulltext from all __fulltextParts
116122
'script' => [
117-
'stored' => 'regenerateFulltext',
123+
'lang' => 'painless',
124+
'inline' => '
125+
ctx._source.__fulltext = new HashMap();
126+
if (!ctx._source.containsKey("__fulltextParts")) {
127+
ctx._source.__fulltextParts = new HashMap();
128+
}
129+
130+
if (params.nodeIsRemoved || params.nodeIsHidden || params.fulltext.size() == 0) {
131+
if (ctx._source.__fulltextParts.containsKey(params.identifier)) {
132+
ctx._source.__fulltextParts.remove(params.identifier);
133+
}
134+
} else {
135+
ctx._source.__fulltextParts.put(params.identifier, params.fulltext);
136+
}
137+
138+
for (fulltextPart in ctx._source.__fulltextParts.entrySet()) {
139+
for (entry in fulltextPart.getValue().entrySet()) {
140+
def value = "";
141+
if (ctx._source.__fulltext.containsKey(entry.getKey())) {
142+
value = ctx._source.__fulltext[entry.getKey()] + " " + entry.getValue().trim();
143+
} else {
144+
value = entry.getValue().trim();
145+
}
146+
ctx._source.__fulltext[entry.getKey()] = value;
147+
}
148+
}',
118149
'params' => [
119150
'identifier' => $node->getIdentifier(),
120151
'nodeIsRemoved' => $node->isRemoved(),

0 commit comments

Comments
 (0)