Forums / Extensions / eZ Find / Deleting an object via the API and delayed indexing

Deleting an object via the API and delayed indexing

Author Message

Jim Thaxton

Wednesday 09 December 2009 11:11:59 am

Our site is setup with delayed indexing that is updated after an import runs each night. We have started to implement a feature to delete inactive objects throughout the day. The delete script runs the ->purge() and ->expireAllCache() methods on the object.

I assume this does not remove the object from the Solr search index. Would we need to run updatesearchindexsolr.php as a cron job after deletes to remove these objects? Is there an API call we can make to have the object removed from the Solr index on delete? The eZ Find extension classes do not have any delete methods as far as I can tell.

Web Developer
Coupon Cabin
Chicago, IL

Paul Borgermans

Saturday 12 December 2009 4:59:00 am

Yes, there is an API in eZ Find (or any search plugin):

Before you actually remove the objects from eZ Publish, use something like this:

$searchEngine = new eZSolr();
....
//loop over objets to delete
$searchEngine->removeObject( $contentObject, false );

And call a commit at the end:

$searchEngine->commit();

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Bertrand Dunogier

Saturday 12 December 2009 6:20:12 am

Running eZContentObject::expireAllCache() is unnecessary, and actually a bit dangerous ! It completely expires all content-cache and cache-blocks... I don't feel like it is what you need.

What you could do instead is use eZContentObjectTreeNode::removeSubtrees() with the $moveToTrash parameter set to false:

eZContentObjectTreNode::removeSubtrees( $nodeIDArray, $moveToTrash = false, $infoOnly = true );

It will take care of everything for you, including clearing appropriate caches and removing the object from the search engine index.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier