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


PHP FinderIndexer::toggleTables方法代码示例

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


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

示例1: tokenizeToDB

 /**
  * Method to parse input, tokenize it, and then add it to the database.
  *
  * @param   mixed    $input    String or resource to use as input. A resource
  *                             input will automatically be chunked to conserve
  *                             memory. Strings will be chunked if longer than
  *                             2K in size.
  * @param   integer  $context  The context of the input. See context constants.
  * @param   string   $lang     The language of the input.
  * @param   string   $format   The format of the input.
  *
  * @return  integer  The number of tokens extracted from the input.
  *
  * @since   2.5
  */
 protected static function tokenizeToDB($input, $context, $lang, $format)
 {
     $count = 0;
     $buffer = null;
     // If the input is a resource, batch the process out.
     if (is_resource($input)) {
         // Batch the process out to avoid memory limits.
         while (!feof($input)) {
             // Read into the buffer.
             $buffer .= fread($input, 2048);
             // If we haven't reached the end of the file, seek to the last
             // space character and drop whatever is after that to make sure
             // we didn't truncate a term while reading the input.
             if (!feof($input)) {
                 // Find the last space character.
                 $ls = strrpos($buffer, ' ');
                 // Adjust string based on the last space character.
                 if ($ls) {
                     // Truncate the string to the last space character.
                     $string = substr($buffer, 0, $ls);
                     // Adjust the buffer based on the last space for the
                     // next iteration and trim.
                     $buffer = JString::trim(substr($buffer, $ls));
                 } else {
                     $string = $buffer;
                 }
             } else {
                 $string = $buffer;
             }
             // Parse the input.
             $string = FinderIndexerHelper::parse($string, $format);
             // Check the input.
             if (empty($string)) {
                 continue;
             }
             // Tokenize the input.
             $tokens = FinderIndexerHelper::tokenize($string, $lang);
             // Add the tokens to the database.
             $count += FinderIndexer::addTokensToDB($tokens, $context);
             // Check if we're approaching the memory limit of the token table.
             if ($count > self::$state->options->get('memory_table_limit', 30000)) {
                 FinderIndexer::toggleTables(false);
             }
             unset($string);
             unset($tokens);
         }
     } elseif (strlen($input) > 2048) {
         $start = 0;
         $end = strlen($input);
         $chunk = 2048;
         // As it turns out, the complex regular expressions we use for
         // sanitizing input are not very efficient when given large
         // strings. It is much faster to process lots of short strings.
         while ($start < $end) {
             // Setup the string.
             $string = substr($input, $start, $chunk);
             // Find the last space character if we aren't at the end.
             $ls = $start + $chunk < $end ? strrpos($string, ' ') : false;
             // Truncate to the last space character.
             if ($ls !== false) {
                 $string = substr($string, 0, $ls);
             }
             // Adjust the start position for the next iteration.
             $start += $ls !== false ? $ls + 1 - $chunk + $chunk : $chunk;
             // Parse the input.
             $string = FinderIndexerHelper::parse($string, $format);
             // Check the input.
             if (empty($string)) {
                 continue;
             }
             // Tokenize the input.
             $tokens = FinderIndexerHelper::tokenize($string, $lang);
             // Add the tokens to the database.
             $count += FinderIndexer::addTokensToDB($tokens, $context);
             // Check if we're approaching the memory limit of the token table.
             if ($count > self::$state->options->get('memory_table_limit', 30000)) {
                 FinderIndexer::toggleTables(false);
             }
         }
     } else {
         // Parse the input.
         $input = FinderIndexerHelper::parse($input, $format);
         // Check the input.
         if (empty($input)) {
             return $count;
//.........这里部分代码省略.........
开发者ID:acculitx,项目名称:fleetmatrixsite,代码行数:101,代码来源:indexer.php


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