Forums / Developer / Best way to republish node from PHP, weird search behavior

Best way to republish node from PHP, weird search behavior

Author Message

Piotrek Karaƛ

Wednesday 04 March 2009 7:12:16 am

Hi all,

I have an extension which consists of two major parts: a datatype which stands an interface into my own DB model, and a cronjob that updates that model and refreshes the website state. It is easy enough to find content objects based on my custom datatype.

So I put together the following code, whose task is to:
- find the list of objects of interest, and for each object:
- republish the object
- clear its cache
- update the search index

Here's the code:

(...)
foreach( $contentObjectIDList as $contentObjectID )
{
    $contentObject = eZContentObject::fetch( $contentObjectID );
    if( is_object( $contentObject ) )
    {
        $nodeObject = $contentObject->mainNode();
        if( is_object( $nodeObject ) )
        {
            if ( !$isQuiet )
            {
                $cli->output( 'Republish and clear cache for content object ID: ' . $contentObjectID );
            }
            $db->begin();
            $contentObjectVersion = $contentObject->createNewVersion();
            eZOperationHandler::execute( 'content', 'publish', array(
                'object_id' => $contentObjectID,
                'version' => $contentObjectVersion->Version,
            ) );
            $db->commit();
            eZContentOperationCollection::registerSearchObject( $contentObjectID, $contentObjectVersion->Version );
            eZContentCacheManager::clearContentCacheIfNeeded( $contentObject );
        }
    }
}
(...)

Now, this seems to be working fine, but each time I run this script, I end up with some additional rows in the ezsearch_word DB table. For example:
1) I truncate ezsearch_word and ezsearch_object_word_link tables,
2) I run my script. It results in ~1300 rows in the ezsearch_word table.
3) I run my script again. Now it adds up to ~1700 rows in the ezsearch_word table.
4) I run my script again. Now it adds up to ~2100 rows in the ezsearch_word table.
And so on... and still operating on the same object...

Is the above script at fault? Or could this be a problem of the search engine?
I wasn't able to reproduce this row count behavior with standard publish process...

Also, would you carry out the task of republishing the object differently?

I'd be grateful for any thoughts on these issues.

Cheers,
Piotrek

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu