protected function execute(InputInterface $input, OutputInterface $output) { $type = $input->getArgument('type'); if (!in_array($type, $this->type)) { $output->writeln("Invalid type."); return; } // Get the indexer $token = $this->getContainer()->getParameter('swiftype_api_key'); $engine = $this->getContainer()->getParameter('swiftype_engine_slug'); $indexer = new SwiftypeIndexer($token, $engine); $docBuilder = DocumentBuilderFactory::getDocumentBuilder($this->getContainer(), $type); $allDocs = $docBuilder->getDocuments(); $numDocs = count($allDocs); $totalIndexed = 0; $batch_size = 100; while ($totalIndexed < $numDocs) { $docs = array_slice($allDocs, $totalIndexed, $batch_size); $result = $indexer->bulkCreateOrUpdate($docs, $type); $totalIndexed += $batch_size; if (count(array_unique($result)) == 1) { $output->writeLn(count($result) . " documents indexed successfully"); } else { $output->writeLn("Some documents may have failed indexing. Total attempted " . count($result)); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $task = $input->getArgument('task'); $type = $input->getArgument('type'); if (!in_array($task, $this->task) && !in_array($type, $this->type)) { $output->writeln("Invalid task or type."); return; } // Get the indexer $token = $this->getContainer()->getParameter('swiftype_api_key'); $engine = $this->getContainer()->getParameter('swiftype_engine_slug'); $indexer = new SwiftypeIndexer($token, $engine); if ($task == 'create') { $result = $indexer->createDocumentType($type); } else { $result = $indexer->deleteDocumentType($type); } $output->writeln("{$task} for {$type} finished"); $output->writeln($result); }