echo "正在生成 " . substr($entry, 0, -3) . " ...\n"; $file = $output . '/' . substr($entry, 0, -3); if (file_exists($file)) { copy($file, $file . '.bak'); } $content = file_get_contents($input . '/' . $entry); $content = strtr($content, $vars); if ($vars['@charset@'] !== 'UTF-8') { $content = XS::convert($content, $vars['@charset@'], 'UTF-8'); } file_put_contents($file, $content); } else { echo "正在复制 " . $entry . " ...\n"; $file = $output . '/' . $entry; if (is_dir($input . '/' . $entry)) { XSUtil::copyDir($input . '/' . $entry, $file); } else { if (file_exists($file)) { copy($file, $file . '.bak'); } copy($input . '/' . $entry, $file); } } } $dir->close(); echo "完成,请将 `{$output}` 目录转移到 web 可达目录,然后访问 search.php 即可。\n"; } catch (XSException $e) { // Exception $start = dirname(dirname(__FILE__)) . '/'; $relative = substr(XSException::getRelPath($start), 0, -1); $traceString = $e->getTraceAsString();
if ($rebuild !== null) { echo "开始重建索引 ...\n"; $index->beginRebuild(); } // import data from source $fid = $xs->getFieldId(); if (!empty($source)) { echo "初始化数据源 ... {$source} \n"; $total = $total_ok = $total_failed = 0; $src = XSDataSource::instance($source, strpos($source, ':') ? $sql : $file); $dcs = $src->getCharset(); if ($dcs === false) { $dcs = $charset === null ? 'UTF-8' : $charset; } echo "开始批量导入数据 (" . (empty($file) ? "请直接输入数据" : $file) . ") ...\n"; XSUtil::flush(); $index->setTimeout(0); $index->openBuffer(); while ($data = $src->getData()) { $doc = new XSDocument($dcs); if ($source == 'csv') { $data = csvTransform($data); if (is_null($data)) { continue; } } $pk = $data[$fid->name]; if ($filter !== null && ($data = $filter->process($data, $dcs)) === false) { $total++; echo "警告:过滤器忽略了第 {$total} 条数据, 主键为:" . $pk . "\n"; continue;
function out_line() { $args = func_get_args(); if (count($args) == 4) { printf("| %s | %s | %s | %s |\n", XSUtil::fixWidth($args[0], 10), XSUtil::fixWidth($args[1], 10), XSUtil::fixWidth($args[2], 24), XSUtil::fixWidth($args[3], 30)); } else { printf("+-%s-+-%s-+-%s-+-%s-+\n", XSUtil::fixWidth('', 10, '-'), XSUtil::fixWidth('', 10, '-'), XSUtil::fixWidth('', 24, '-'), XSUtil::fixWidth('', 30, '-')); } }
/** * 解析命令行参数 * @param array $valued 需要附加值的参数列表 * @return array 解析完的参数数组,未指定 - 开头的选项统一放入 '-' 的子数组 */ public static function parseOpt($valued = array()) { $result = array('-' => array()); $params = isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); for ($i = 0; $i < count($params); $i++) { if ($params[$i] === '--') { for ($i = $i + 1; $i < count($params); $i++) { $result['-'][] = $params[$i]; } break; } elseif ($params[$i][0] === '-') { $value = true; $pname = substr($params[$i], 1); if ($pname[0] === '-') { $pname = substr($pname, 1); if (($pos = strpos($pname, '=')) !== false) { $value = substr($pname, $pos + 1); $pname = substr($pname, 0, $pos); } } elseif (strlen($pname) > 1) { for ($j = 1; $j < strlen($params[$i]); $j++) { $pname = substr($params[$i], $j, 1); if (in_array($pname, $valued)) { $value = substr($params[$i], $j + 1); break; } elseif ($j + 1 != strlen($params[$i])) { $result[$pname] = true; } } } if ($value === true && in_array($pname, $valued) && isset($params[$i + 1])) { $value = $params[$i + 1]; $i++; } $result[$pname] = $value; } else { $result['-'][] = $params[$i]; } } self::$options = $result; self::$optind = 1; return $result; }
用法 {$_SERVER['argv'][0]} [options] [-p|--project] <project> [[-o|--output] <dir>] \t 选项说明 --project=<name|ini> -p <project> 用于指定要搜索的项目名称或项目配置文件的路径, 如果指定的是名称,则使用 ../app/<name>.ini 作为配置文件 --output=<dir>\t -o <dir> 指定生成的骨架代码存储位置,默认为当前目录 -h|--help 显示帮助信息 EOF; exit(0); } // output dir $output = XSUtil::getOpt('o', 'output', true); if ($output === null) { $output = '.'; } if (!is_dir($output)) { echo "错误:输出目录 ({$output}) 不是一个有效的目录。\n"; exit(-1); } if (!is_writable($output)) { echo "错误:输出目录 ({$output}) 不可写入,请注意检查权限。\n"; exit(-1); } // execute the search try { // create xs object echo "初始化项目对象 ...\n";
if ($pos = strpos($cut_off, ',')) { $search->setCutOff(substr($cut_off, 0, $pos), substr($cut_off, $pos + 1)); } elseif (strpos($cut_off, '.') !== false) { $search->setCutOff(0, $cut_off); } else { $search->setCutOff($cut_off); } } // preform search $begin = microtime(true); $result = $search->setLimit($limit1, $offset)->search(); $cost = microtime(true) - $begin; $matched = $search->getLastCount(); $total = $search->getDbTotal(); // show query? if (XSUtil::getOpt(null, 'show-query') !== null) { echo str_repeat("-", 20) . "\n"; echo "解析后的 QUERY 语句:" . $search->getQuery() . "\n"; echo str_repeat("-", 20) . "\n"; } // related & corrected $correct = $search->getCorrectedQuery(); $related = $search->getRelatedQuery(); // info printf("在 %s 条数据中,大约有 %d 条包含 [7m%s[m ,第 %d-%d 条,用时:%.4f 秒。\n", number_format($total), $matched, $query, min($matched, $offset + 1), min($matched, $limit1 + $offset), $cost); // correct if (count($correct) > 0) { echo "您是不是想找:[4m" . implode("[m [4m", $correct) . "[m\n"; } // show result foreach ($result as $doc) {
// Usage: burst.php // $Id$ require_once dirname(__FILE__) . '/../util/XSUtil.class.php'; // check arguments XSUtil::parseOpt(array('i', 'c', 't')); $test_con = XSUtil::getOpt('c', null, true); $test_type = XSUtil::getOpt('t'); $test_index = XSUtil::getOpt('i'); if ($test_type !== 'search') { $test_type = 'index'; } if ($test_index === null && $test_con === null) { $test_con = 100; } // show help if (XSUtil::getOpt('h', 'help') !== null || $test_con == null && $test_index == null) { echo <<<EOF Burst - XS 服务端并发测试工具 用法 {$_SERVER['argv'][0]} [options] [-c|-i] <num> \t 选项说明 -c <num> 设置测试的并发总量,用于启动进程,默认 100 -i <num> 设置测试的序列,用于实际运行进程 -t <type> 设置测试的类型,其值为 index 或 search,默认为 index -h|--help 显示帮助说明 EOF; exit(0); }