@@ -177,8 +177,8 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
177177 }
178178
179179 if ($ node ->isRemoved ()) {
180- // TODO: handle deletion from the fulltext index as well
181180 $ mappingType ->deleteDocumentById ($ contextPathHash );
181+ $ this ->updateFulltext ($ node , [], $ targetWorkspaceName );
182182 $ this ->logger ->log (sprintf ('NodeIndexer: Removed node %s from index (node flagged as removed). ID: %s ' , $ contextPath , $ contextPathHash ), LOG_DEBUG , null , 'ElasticSearch (CR) ' );
183183
184184 return ;
@@ -231,6 +231,9 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null)
231231 $ indexer ($ node , $ targetWorkspaceName );
232232 }
233233 }
234+ if ($ node ->isRemoved ()) {
235+ $ indexer ($ node , $ targetWorkspaceName );
236+ }
234237 }
235238
236239 /**
@@ -361,10 +364,11 @@ protected function removeDuplicateDocuments($contextPath, $contextPathHash, Node
361364 */
362365 protected function updateFulltext (NodeInterface $ node , array $ fulltextIndexOfNode , $ targetWorkspaceName = null )
363366 {
364- if ((( $ targetWorkspaceName !== null && $ targetWorkspaceName !== 'live ' ) || $ node ->getWorkspace ()->getName () !== 'live ' ) || count ( $ fulltextIndexOfNode ) === 0 ) {
367+ if (($ targetWorkspaceName !== null && $ targetWorkspaceName !== 'live ' ) || ( $ node ->getWorkspace ()->getName () !== 'live ' && ! $ node -> isRemoved ()) ) {
365368 return ;
366369 }
367370
371+
368372 $ closestFulltextNode = $ node ;
369373 while (!$ this ->isFulltextRoot ($ closestFulltextNode )) {
370374 $ closestFulltextNode = $ closestFulltextNode ->getParent ();
@@ -379,6 +383,11 @@ protected function updateFulltext(NodeInterface $node, array $fulltextIndexOfNod
379383 $ closestFulltextNodeContextPath = str_replace ($ closestFulltextNode ->getContext ()->getWorkspace ()->getName (), 'live ' , $ closestFulltextNode ->getContextPath ());
380384 $ closestFulltextNodeContextPathHash = sha1 ($ closestFulltextNodeContextPath );
381385
386+ $ upsertFulltextParts = [];
387+ if (!empty ($ fulltextIndexOfNode )) {
388+ $ upsertFulltextParts [$ node ->getIdentifier ()] = $ fulltextIndexOfNode ;
389+ }
390+
382391 $ this ->currentBulkRequest [] = [
383392 [
384393 'update ' => [
@@ -395,7 +404,12 @@ protected function updateFulltext(NodeInterface $node, array $fulltextIndexOfNod
395404 if (!ctx._source.containsKey("__fulltextParts")) {
396405 ctx._source.__fulltextParts = new HashMap();
397406 }
398- ctx._source.__fulltextParts[identifier] = fulltext;
407+ if (fulltext.size() == 0) {
408+ ctx._source.__fulltextParts.remove(identifier);
409+ } else {
410+ ctx._source.__fulltextParts.put(identifier, fulltext);
411+ }
412+
399413 ctx._source.__fulltextParts.each { originNodeIdentifier, partContent -> partContent.each { bucketKey, content ->
400414 if (ctx._source.__fulltext.containsKey(bucketKey)) {
401415 value = ctx._source.__fulltext[bucketKey] + " " + content.trim();
@@ -413,9 +427,7 @@ protected function updateFulltext(NodeInterface $node, array $fulltextIndexOfNod
413427 ],
414428 'upsert ' => [
415429 '__fulltext ' => $ fulltextIndexOfNode ,
416- '__fulltextParts ' => [
417- $ node ->getIdentifier () => $ fulltextIndexOfNode
418- ]
430+ '__fulltextParts ' => $ upsertFulltextParts
419431 ],
420432 'lang ' => 'groovy '
421433 ]
0 commit comments