Exemple #1
0
//	this has to be done to get all configs
$sm = Zend\Mvc\Application::init(require 'config/application.config.php')->bootstrap()->getServiceManager();
$pdo = $sm->get('PDO');
$index = $sm->get('Search\\Index\\Search');
//Event
//	index event entries.
//
$counter = 0;
$eventService = new Stjornvisi\Service\Event($pdo);
$events = $eventService->fetchAll();
$adapter = new Zend\Progressbar\Adapter\Console();
echo "\nIndexing Event entries\n";
$progressBar = new Zend\ProgressBar\ProgressBar($adapter, $counter, count($events));
$i = new Stjornvisi\Search\Index\Event();
foreach ($events as $item) {
    $i->index($item, $index);
    $progressBar->update(++$counter);
}
$index->commit();
$progressBar->finish();
//NEWS
//	index news entries.
//
$counter = 0;
$newsService = new Stjornvisi\Service\News($pdo);
$news = $newsService->fetchAll();
$adapter = new Zend\Progressbar\Adapter\Console();
echo "\nIndexing News entries\n";
$progressBar = new Zend\ProgressBar\ProgressBar($adapter, $counter, count($news));
$i = new Stjornvisi\Search\Index\News();
foreach ($news as $item) {
 /**
  * Rebuild search index.
  *
  * <code>
  * $ php index.php search index
  * </code>
  *
  * @throws \RuntimeException
  * @deprecated
  */
 public function searchIndexAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console!');
     }
     $sm = $this->getServiceLocator();
     $index = $sm->get('Search\\Index\\Search');
     //Event
     //  index event entries.
     //
     $counter = 0;
     $eventService = $sm->get('Stjornvisi\\Service\\Event');
     $events = $eventService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing Event entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($events));
     $i = new \Stjornvisi\Search\Index\Event();
     foreach ($events as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
     //NEWS
     //  index news entries.
     //
     $counter = 0;
     $newsService = $sm->get('Stjornvisi\\Service\\News');
     $news = $newsService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing News entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($news));
     $i = new \Stjornvisi\Search\Index\News();
     foreach ($news as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
     //Articles
     //  index article entries.
     //
     $counter = 0;
     $articleService = $sm->get('Stjornvisi\\Service\\Article');
     $articles = $articleService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing News entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($articles));
     $i = new \Stjornvisi\Search\Index\Article();
     foreach ($articles as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
     //Group
     //  index group entries.
     //
     $counter = 0;
     $groupService = $sm->get('Stjornvisi\\Service\\Group');
     $groups = $groupService->fetchAll();
     $adapter = new Console();
     echo "\nIndexing Group entries\n";
     $progressBar = new ProgressBar($adapter, $counter, count($groups));
     $i = new \Stjornvisi\Search\Index\Group();
     foreach ($groups as $item) {
         $i->index($item, $index);
         $progressBar->update(++$counter);
     }
     $index->commit();
     $progressBar->finish();
 }