Skip to content

Commit

Permalink
Re-index subtree on move (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkeung authored Nov 13, 2021
1 parent 23081b7 commit 29686e9
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions search/plugins/ezsolr/ezsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ public function updateObjectsSection( array $objectIDs, $sectionID )
/**
* Called when a node's visibility is modified.
* Will re-index content identified by $nodeID.
* If the node has children, they will be also re-indexed, but this action is deferred to ezfindexsubtree cronjob.
* If the node has children, they will be also re-indexed, but this action is deferred to ezfindexsubtree cronjob, just like addNodeAssignment() when a node is moved
*
* @todo when Solr supports it: update fields only
*
Expand Down Expand Up @@ -1478,10 +1478,10 @@ public function updateNodeVisibility( $nodeID, $action )
}

/**
* Called when a node assignement is added to an object.
* Called when a node assignment is added to an object.
* Simply re-index for now.
* If the node has children, they will be also re-indexed, but this action is deferred to ezfindexsubtree cronjob, just like updateNodeVisibility()
*
* @todo: defer to cron if there are children involved and re-index these too
* @todo when Solr supports it: update fields only
*
* @param $mainNodeID
Expand All @@ -1494,6 +1494,32 @@ public function updateNodeVisibility( $nodeID, $action )
public function addNodeAssignment( $mainNodeID, $objectID, $nodeAssignmentIDList, $isMoved )
{
eZContentOperationCollection::registerSearchObject( $objectID, null, $isMoved );

// Re-index the children, if any
if ( $isMoved )
{
// When moving, the node ID list contains only the node being moved
// Ref: eZContentObjectTreeNodeOperations::move()
$nodeID = $nodeAssignmentIDList[0];
$node = eZContentObjectTreeNode::fetch( $nodeID );
$params = array(
'Depth' => 1,
'DepthOperator' => 'eq',
'Limitation' => array(),
'IgnoreVisibility' => true,
);
if ( $node->subTreeCount( $params ) > 0 )
{
$pendingAction = new eZPendingActions(
array(
'action' => self::PENDING_ACTION_INDEX_SUBTREE,
'created' => time(),
'param' => $nodeID
)
);
$pendingAction->store();
}
}
}

/**
Expand Down

0 comments on commit 29686e9

Please sign in to comment.