@@ -163,19 +163,24 @@ public function getIndex() {
163163 * index this node, and add it to the current bulk request.
164164 *
165165 * @param Node $node
166- * @throws \Exception
166+ * @param string $targetWorkspaceName In case this is triggered during publishing, a workspace name will be passed in
167167 * @return void
168+ * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\IndexingException
168169 */
169- public function indexNode (Node $ node ) {
170- $ contextPathHash = sha1 ($ node ->getContextPath ());
170+ public function indexNode (Node $ node , $ targetWorkspaceName = NULL ) {
171+ $ contextPath = $ node ->getContextPath ();
172+ if ($ targetWorkspaceName !== NULL ) {
173+ $ contextPath = str_replace ($ node ->getWorkspace ()->getName (), $ targetWorkspaceName , $ contextPath );
174+ }
175+ $ contextPathHash = sha1 ($ contextPath );
171176 $ nodeType = $ node ->getNodeType ();
172177
173178 $ mappingType = $ this ->getIndex ()->findType (NodeTypeMappingBuilder::convertNodeTypeNameToMappingName ($ nodeType ));
174179
175180 if ($ node ->isRemoved ()) {
176181 // TODO: handle deletion from the fulltext index as well
177182 $ mappingType ->deleteDocumentById ($ contextPathHash );
178- $ this ->logger ->log (sprintf ('NodeIndexer: Removed node %s from index (node flagged as removed). ID: %s ' , $ node -> getContextPath () , $ contextPathHash ), LOG_DEBUG , NULL , 'ElasticSearch (CR) ' );
183+ $ this ->logger ->log (sprintf ('NodeIndexer: Removed node %s from index (node flagged as removed). ID: %s ' , $ contextPath , $ contextPathHash ), LOG_DEBUG , NULL , 'ElasticSearch (CR) ' );
179184
180185 return ;
181186 }
@@ -229,6 +234,9 @@ public function indexNode(Node $node) {
229234 );
230235
231236 $ documentData = $ document ->getData ();
237+ if ($ targetWorkspaceName !== NULL ) {
238+ $ documentData ['__workspace ' ] = $ targetWorkspaceName ;
239+ }
232240
233241 if ($ fulltextIndexingEnabledForNode === TRUE ) {
234242 if ($ this ->isFulltextRoot ($ node )) {
@@ -273,7 +281,7 @@ public function indexNode(Node $node) {
273281 $ this ->updateFulltext ($ node , $ fulltextIndexOfNode );
274282 }
275283
276- $ this ->logger ->log (sprintf ('NodeIndexer: Added / updated node %s. ID: %s ' , $ node -> getContextPath () , $ contextPathHash ), LOG_DEBUG , NULL , 'ElasticSearch (CR) ' );
284+ $ this ->logger ->log (sprintf ('NodeIndexer: Added / updated node %s. ID: %s ' , $ contextPath , $ contextPathHash ), LOG_DEBUG , NULL , 'ElasticSearch (CR) ' );
277285 }
278286
279287 /**
0 commit comments