Skip to content

Commit

Permalink
refactor: 优化文档搜索索引生成
Browse files Browse the repository at this point in the history
  • Loading branch information
huanglonghui committed Jan 12, 2024
1 parent e58c39c commit 1123de6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions EasySwooleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ public static function mainServerCreate(EventRegister $register)
$en->getTemplate()->setPageNotFoundTpl('404.tpl');
DocContainer::getInstance()->add($en);

Manager::getInstance()->addProcess(new TickProcess());
// Manager::getInstance()->addProcess(new TickProcess());
self::initSearch();
}
}

private static function initSearch()
{
$scheduler = new \Swoole\Coroutine\Scheduler();
$scheduler->add(function() {
go(function () {
// 写入搜索内容json
$list = Config::getInstance()->getConf("DOC.ALLOW_LANGUAGE");
try {
foreach ($list as $dir => $value) {
$json = DocSearchParser::parserDoc2JsonUrlMap(EASYSWOOLE_ROOT, "{$dir}");
file_put_contents(EASYSWOOLE_ROOT . "/Static/keyword{$dir}.json", json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
} catch (\Throwable $throwable) {
\EasySwoole\EasySwoole\Trigger::getInstance()->throwable($throwable);
}
});
});
$scheduler->start();
// 清除全部定时器
\Swoole\Timer::clearAll();
}
}

0 comments on commit 1123de6

Please sign in to comment.