eZContentOperationCollection::registerSearchObject PHP Method

registerSearchObject() public static method

Registers the object in search engine.
public static registerSearchObject ( integer $objectID, integer $version = null, boolean $isMoved = false )
$objectID integer Id of the object.
$version integer Operation collection passes this default param. Not used in the method
$isMoved boolean true if node is being moved
    public static function registerSearchObject($objectID, $version = null, $isMoved = false)
    {
        $objectID = (int) $objectID;
        eZDebug::createAccumulatorGroup('search_total', 'Search Total');
        $ini = eZINI::instance('site.ini');
        $insertPendingAction = false;
        $object = null;
        switch ($ini->variable('SearchSettings', 'DelayedIndexing')) {
            case 'enabled':
                $insertPendingAction = true;
                break;
            case 'classbased':
                $classList = $ini->variable('SearchSettings', 'DelayedIndexingClassList');
                $object = eZContentObject::fetch($objectID);
                if (is_array($classList) && in_array($object->attribute('class_identifier'), $classList)) {
                    $insertPendingAction = true;
                }
        }
        if ($insertPendingAction) {
            $action = $isMoved ? 'index_moved_node' : 'index_object';
            eZDB::instance()->query("INSERT INTO ezpending_actions( action, param ) VALUES ( '{$action}', '{$objectID}' )");
            return;
        }
        if ($object === null) {
            $object = eZContentObject::fetch($objectID);
        }
        // Register the object in the search engine.
        $needCommit = eZSearch::needCommit();
        if (eZSearch::needRemoveWithUpdate()) {
            eZDebug::accumulatorStart('remove_object', 'search_total', 'remove object');
            eZSearch::removeObjectById($objectID);
            eZDebug::accumulatorStop('remove_object');
        }
        eZDebug::accumulatorStart('add_object', 'search_total', 'add object');
        if (!eZSearch::addObject($object, $needCommit)) {
            eZDebug::writeError("Failed adding object ID {$object->attribute('id')} in the search engine", __METHOD__);
        }
        eZDebug::accumulatorStop('add_object');
    }

Usage Example

Esempio n. 1
0
 public function execute($process, $event)
 {
     $processParameters = $process->attribute('parameter_list');
     $object = eZContentObject::fetch($processParameters['object_id']);
     $targetClassIdentifier = $object->contentClass()->attribute('identifier');
     $iniGroups = eZINI::instance('ngindexer.ini')->groups();
     $targets = array();
     foreach ($iniGroups as $iniGroupName => $iniGroup) {
         $iniGroupNameArray = explode('/', $iniGroupName);
         if (is_array($iniGroupNameArray) && count($iniGroupNameArray) == 3) {
             $class = eZContentClass::fetchByIdentifier($iniGroupNameArray[0]);
             if ($class instanceof eZContentClass) {
                 $classAttribute = $class->fetchAttributeByIdentifier($iniGroupNameArray[1]);
                 if ($classAttribute instanceof eZContentClassAttribute) {
                     $indexTarget = isset($iniGroup['IndexTarget']) ? trim($iniGroup['IndexTarget']) : '';
                     $referencedClassIdentifiers = isset($iniGroup['ClassIdentifiers']) && is_array($iniGroup['ClassIdentifiers']) ? $iniGroup['ClassIdentifiers'] : null;
                     if ($referencedClassIdentifiers != null && (empty($referencedClassIdentifiers) || in_array($targetClassIdentifier, $referencedClassIdentifiers))) {
                         switch ($indexTarget) {
                             case 'parent':
                             case 'parent_line':
                                 $children = eZContentObjectTreeNode::subTreeByNodeID(array('ClassFilterType' => 'include', 'ClassFilterArray' => array($iniGroupNameArray[0]), 'Depth' => $indexTarget == 'parent' ? 1 : false), $object->mainNode()->attribute('node_id'));
                                 if (is_array($children)) {
                                     $targets = array_merge($targets, $children);
                                 }
                                 break;
                             case 'children':
                                 $parentNode = $object->mainNode()->fetchParent();
                                 if ($parentNode->classIdentifier() == $iniGroupNameArray[0]) {
                                     $targets[] = $parentNode;
                                 }
                                 break;
                             case 'subtree':
                                 $path = $object->mainNode()->fetchPath();
                                 foreach ($path as $pathNode) {
                                     if ($pathNode->classIdentifier() == $iniGroupNameArray[0]) {
                                         $targets[] = $parentNode;
                                     }
                                 }
                                 break;
                             default:
                                 continue;
                         }
                     }
                 }
             }
         }
     }
     $filteredTargets = array();
     foreach ($targets as $target) {
         $objectID = $target->attribute('contentobject_id');
         $version = $target->object()->attribute('current_version');
         if (!isset($filteredTargets[$objectID])) {
             $filteredTargets[$objectID] = $version;
             eZContentOperationCollection::registerSearchObject($objectID, $version);
         }
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
All Usage Examples Of eZContentOperationCollection::registerSearchObject