public function run($request)
 {
     $message = function ($content) {
         print \Director::is_cli() ? "{$content}\n" : "<p>{$content}</p>";
     };
     $message('Defining the mappings');
     $this->service->define();
     $message('Refreshing the index');
     $this->service->refresh();
 }
 public function run($request)
 {
     if (!(\Permission::check('ADMIN') || \Director::is_cli())) {
         exit("Invalid");
     }
     $message = function ($content) {
         print \Director::is_cli() ? "{$content}\n" : "<p>{$content}</p>";
     };
     $message("Specify 'rebuild' to delete the index first, and 'reindex' to re-index content items");
     if ($request->getVar('rebuild')) {
         $this->service->getIndex()->delete();
     }
     $message('Defining the mappings (if not already)');
     $this->service->define();
     if ($request->getVar('reindex')) {
         $message('Refreshing the index');
         try {
             $this->service->refresh($message);
         } catch (\Exception $ex) {
             $message("Some failures detected when indexing " . $ex->getMessage());
         }
     }
 }