当前位置: 首页>>代码示例>>PHP>>正文


PHP eZSolr::optimize方法代码示例

本文整理汇总了PHP中eZSolr::optimize方法的典型用法代码示例。如果您正苦于以下问题:PHP eZSolr::optimize方法的具体用法?PHP eZSolr::optimize怎么用?PHP eZSolr::optimize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZSolr的用法示例。


在下文中一共展示了eZSolr::optimize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: runMain

 /**
  * Run main process
  */
 protected function runMain()
 {
     $startTS = microtime_float();
     $searchEngine = new eZSolr();
     $processLimit = min($this->Options['conc'] ? $this->Options['conc'] : 2, 10);
     // Maximum 10 processes
     $useFork = function_exists('pcntl_fork') && function_exists('posix_kill');
     if ($useFork) {
         $this->CLI->output('Using fork.');
     } else {
         $processLimit = 1;
     }
     $this->CLI->output('Using ' . $processLimit . ' concurent process(es)');
     $processList = array();
     for ($i = 0; $i < $processLimit; $i++) {
         $processList[$i] = -1;
     }
     $this->ObjectCount = $this->objectCount();
     $this->CLI->output('Number of objects to index: ' . $this->ObjectCount);
     $this->Script->resetIteration($this->ObjectCount, 0);
     $topNodeArray = eZPersistentObject::fetchObjectList(eZContentObjectTreeNode::definition(), null, array('parent_node_id' => 1, 'depth' => 1));
     // Loop through top nodes.
     foreach ($topNodeArray as $node) {
         $nodeID = $node->attribute('node_id');
         $offset = 0;
         $subtreeCount = $node->subTreeCount(array('Limitation' => array(), 'MainNodeOnly' => true));
         // While $offset < subtree count, loop through the nodes.
         while ($offset < $subtreeCount) {
             // Loop trough the available processes, and see if any has finished.
             for ($i = 0; $i < $processLimit; $i++) {
                 $pid = $processList[$i];
                 if ($useFork) {
                     if ($pid === -1 || !posix_kill($pid, 0)) {
                         $newPid = $this->forkAndExecute($nodeID, $offset, $this->Limit);
                         $this->CLI->output("\n" . 'Creating a new thread: ' . $newPid);
                         if ($newPid > 0) {
                             $offset += $this->Limit;
                             $this->iterate();
                             $processList[$i] = $newPid;
                         } else {
                             $this->CLI->error("\n" . 'Returned invalid PID: ' . $newPid);
                         }
                     }
                 } else {
                     // Execute in same process
                     $count = $this->execute($nodeID, $offset, $this->Limit);
                     $this->iterate($count);
                     $offset += $this->Limit;
                 }
                 if ($offset >= $subtreeCount) {
                     break;
                 }
             }
             // If using fork, the main process must sleep a bit to avoid
             // 100% cpu usage. Sleep for 100 millisec.
             if ($useFork) {
                 $status = 0;
                 pcntl_wait($status, WNOHANG);
                 usleep(100000);
             }
         }
     }
     // Wait for all processes to finish.
     $break = false;
     while ($useFork && !$break) {
         $break = true;
         for ($i = 0; $i < $processLimit; $i++) {
             $pid = $processList[$i];
             if ($pid !== -1) {
                 // Check if process is still alive.
                 if (posix_kill($pid, 0)) {
                     $break = false;
                 } else {
                     $this->CLI->output('Process finished: ' . $pid);
                     $processList[$i] = -1;
                 }
             }
         }
         // Sleep for 500 msec.
         $status = 0;
         pcntl_wait($status, WNOHANG);
         usleep(500000);
     }
     $this->CLI->output('Optimizing. Please wait ...');
     $searchEngine->optimize(true);
     $endTS = microtime_float();
     $this->CLI->output('Indexing took ' . ($endTS - $startTS) . ' secs ' . '( average: ' . $this->ObjectCount / ($endTS - $startTS) . ' objects/sec )');
     $this->CLI->output('Finished updating the search index.');
 }
开发者ID:legende91,项目名称:ez,代码行数:92,代码来源:updatesearchindexsolr.php

示例2: iterate

 /**
  * Iterate index counter
  *
  * @param int $count
  */
 protected function iterate($count = false)
 {
     if (!$count) {
         $count = $this->Limit;
     }
     for ($iterateCount = 0; $iterateCount < $count; ++$iterateCount) {
         if (++$this->IterateCount > $this->ObjectCount) {
             break;
         }
         $this->Script->iterate($this->CLI, true);
         if ($this->IterateCount % 1000 === 0) {
             $this->CLI->output("\n" . 'Comitting and optimizing index ...');
             $searchEngine = new eZSolr();
             $searchEngine->optimize();
             eZContentObject::clearCache();
         }
     }
 }
开发者ID:netbliss,项目名称:ezfind,代码行数:23,代码来源:updatesearchindexsolr.php


注:本文中的eZSolr::optimize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。