search($query); var_export($result); } /** * 清空索引 * * @command: php console.php article_index clean */ public function cleanAction() { $handler = new ArticleSearcher(); $index = $handler->getXS()->getIndex(); echo '------ start clean article index ------' . PHP_EOL; $index->clean(); echo '------ end clean article index ------' . PHP_EOL; } /** * 重建索引 * * @command: php console.php article_index rebuild */ public function rebuildAction() { $articles = $this->findArticles(); if ($articles->count() == 0) return; $handler = new ArticleSearcher(); $doc = new ArticleDocument(); $index = $handler->getXS()->getIndex(); echo '------ start rebuild article index ------' . PHP_EOL; $index->beginRebuild(); foreach ($articles as $article) { $document = $doc->setDocument($article); $index->add($document); } $index->endRebuild(); echo '------ end rebuild article index ------' . PHP_EOL; } /** * 刷新索引缓存 * * @command: php console.php article_index flush_index */ public function flushIndexAction() { $handler = new ArticleSearcher(); $index = $handler->getXS()->getIndex(); echo '------ start flush article index ------' . PHP_EOL; $index->flushIndex(); echo '------ end flush article index ------' . PHP_EOL; } /** * 刷新搜索日志 * * @command: php console.php article_index flush_logging */ public function flushLoggingAction() { $handler = new ArticleSearcher(); $index = $handler->getXS()->getIndex(); echo '------ start flush article logging ------' . PHP_EOL; $index->flushLogging(); echo '------ end flush article logging ------' . PHP_EOL; } /** * 查找文章 * * @return ResultsetInterface|Resultset|ArticleModel[] */ protected function findArticles() { return ArticleModel::query() ->where('published = :published:', ['published' => ArticleModel::PUBLISH_APPROVED]) ->andWhere('deleted = 0') ->execute(); } }