<?php
 namespace Module\Question\Admin\Controller; use Illuminate\Routing\Controller; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Input\InputPackage; use ModStart\Core\Input\Request; use ModStart\Core\Input\Response; use Module\Question\Util\ESUtil; class ESController extends Controller { public function sync() { if (Request::isPost()) { if (!modstart_config('moduleESEnable', false)) { return Response::send(-1, '请先打开全文索引'); } $input = InputPackage::buildFromInput(); $index = $input->getTrimString('index'); ESUtil::createIndex($index, 'v1'); ESUtil::putAlias($index, 'v1'); switch ($input->getTrimString('action')) { case 'refresh': $stats = ESUtil::statsIndex($index); $data = []; $data['count'] = $stats['total']['docs']['count']; return Response::send(0, 'ok', $data); case 'sync': $nextId = $input->getInteger('nextId', 0); $data = [ 'syncCount' => 0, 'nextId' => 0, ]; switch ($index) { case 'question': $ret = ModelUtil::batch('question', $nextId, 1000); ESUtil::syncQuestions($ret['records']); $data['syncCount'] = count($ret['records']); $data['nextId'] = $ret['nextId']; break; } return Response::send(0, 'ok', $data); } return Response::send(-1, '请求错误'); } return view('module::Question.View.admin.es.sync'); } }