Beispiel #1
0
 public function getForLuceneQuery($query)
 {
     $hits = Job::getLuceneIndex()->find($query);
     $pks = array();
     foreach ($hits as $hit) {
         $pks[] = $hit->pk;
     }
     if (empty($pks)) {
         return array();
     }
     $q = $this->createQueryBuilder('j')->where('j.id IN (:pks)')->setParameter('pks', $pks)->andWhere('j.is_activated = :active')->setParameter('active', 1)->setMaxResults(20)->getQuery();
     return $q->getResult();
 }
Beispiel #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $days = $input->getArgument('days');
     $em = $this->getContainer()->get('doctrine')->getManager();
     //clean up Lucene index
     $index = Job::getLuceneIndex();
     $q = $em->getRepository('IbwJobeetBundle:Job')->createQueryBuilder('j')->where('j.expires_at < :date')->setParameter('date', date('Y-m-d'))->getQuery();
     $jobs = $q->getResult();
     foreach ($jobs as $job) {
         if ($hit = $index->find('pk:' . $job->getId())) {
             $index->delete($hit->id);
         }
     }
     $index->optimize();
     $output->writeln('Cleaned up and optimized the job index');
     //Remoce stale jobs
     $nb = $em->getRepository('IbwJobeetBundle:Job')->cleanup($days);
     $output->writeln(sprintf('Removed %d stale Job.', $nb));
 }