private function reindex(string $locale, OutputInterface $output)
 {
     $totalEntities = $this->repository->getTotalCount();
     $iterations = $this->getIterations($totalEntities, $this->batchSize);
     $output->writeln(sprintf('<comment>Total entities:</comment> %s', $totalEntities));
     $output->writeln(sprintf('<comment>Batch size:</comment> %s', $this->batchSize));
     $output->writeln(sprintf('<comment>Iterations:</comment> %s', count($iterations)));
     $output->writeln(sprintf('<comment>Locale:</comment> %s', $locale));
     $output->writeln('<info>Flushing index</info>');
     $this->manager->flushIndex($locale);
     $progress = new ProgressBar($output, $totalEntities);
     $progress->setFormat('verbose');
     $progress->setRedrawFrequency($this->batchSize);
     $progress->start();
     foreach ($iterations as $iteration) {
         $entities = $this->getEntities($iteration);
         foreach ($entities as $entity) {
             $document = $this->type->createDocument($entity, $locale);
             $this->manager->addDocument($document);
             $progress->advance();
         }
     }
     $progress->finish();
     $output->writeln('');
     $output->writeln('<info>Optimizing index</info>');
     $this->manager->optimizeIndex($locale);
 }
 private function createSearchRequest(Request $request) : SearchRequestInterface
 {
     $type = $this->manager->getType($request->get('type'));
     $phrase = $request->query->has('phrase') ? $request->query->get('phrase') : '';
     $fields = new ArrayCollection();
     $type->getFields()->map(function (FieldInterface $field) use($fields, $request) {
         if ($request->query->has($field->getName())) {
             $field->setValue($request->query->get($field->getName(), ''));
             $fields->set($field->getName(), $field);
         }
     });
     return new SearchRequest($type, $fields, $phrase, $request->getLocale());
 }