Exemplo n.º 1
0
 /**
  * Delete document on objects after being remove
  *
  * @param LifecycleEventArgs $args
  * @return void
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($index = $this->getIndexForObject($entity)) {
         $indexManager = new IndexManager($index);
         $indexManager->remove($entity);
     }
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get repository
     $entityClass = $input->getArgument('entityClass');
     $repository = $this->getHelper('em')->getEntityManager()->getRepository($entityClass);
     $reflClass = new ReflectionClass($entityClass);
     $reader = new AnnotationReader();
     $annotation = $reader->getClassAnnotation($reflClass, '\\Keratine\\Lucene\\Mapping\\Annotation\\Indexable');
     if (!$annotation) {
         $output->writeln(sprintf('<error>%s must define the "%s" annotation.</error>', $entityClass, '\\Keratine\\Lucene\\Mapping\\Annotation\\Indexable'));
         return;
     }
     $indexManager = new IndexManager($this->getHelper('zendsearch')->getIndices()[$annotation->index]);
     // delete all indexed documents
     $numDocs = $indexManager->numDocs();
     for ($id = 0; $id < $numDocs; $id++) {
         $indexManager->delete($id);
     }
     // index each entity
     foreach ($repository->findAll() as $entity) {
         $indexManager->index($entity);
     }
     // optimize index
     $indexManager->optimize();
     // get number of indexed documents
     $numDocs = $indexManager->numDocs();
     $output->writeln(sprintf('<info>%d document(s) indexed</info>', $numDocs));
 }