Ejemplo n.º 1
0
 protected function execute($arguments = array(), $options = array())
 {
     $app = $arguments['application'];
     $this->notifyListRow('Plugin Version', 'sfLucene ' . sfLucene::VERSION);
     if ($app) {
         $this->checkAppExists($app);
         $this->standardBootstrap($app, $options['env']);
         foreach (sfLucene::getAllInstances() as $search) {
             $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->format(sprintf('For %s/%s:', $search->getParameter('name'), $search->getParameter('culture')), array('fg' => 'red', 'bold' => true)))));
             $segments = $search->segmentCount();
             $this->notifyListRow('Document Count', $search->numDocs(), 3);
             $this->notifyListRow('Segment Count', $segments, 3);
             $rawSize = $search->byteSize();
             $size = $rawSize / 1024 > 1024 ? number_format($rawSize / pow(1024, 2), 3) . 'MB' : number_format($rawSize / 1024, 3) . ' KB';
             $this->notifyListRow('Index Size', $size, 3);
             if ($segments == 0) {
                 $condition = 'Empty: Perhaps you should rebuild the index?';
             } elseif ($segments == 1) {
                 $condition = 'Great: No optimization neccessary';
             } elseif ($segments <= 10) {
                 $condition = 'Good: Consider optimizing for full performance';
             } elseif ($segments <= 20) {
                 $condition = 'Bad: Optimization is recommended';
             } else {
                 $condition = 'Terrible: Immediate optimization neccessary!';
             }
             $this->notifyListRow('Index Condition', $condition, 3);
         }
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->standardBootstrap($arguments['application'], $options['env']);
     if ($arguments['confirmation'] == 'delete') {
         $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->format('Delete confirmation provided.  Deleting index now...', array('fg' => 'red', 'bold' => true)))));
         $instances = sfLucene::getAllInstances();
         foreach ($instances as $instance) {
             $instance->getLucene()->deleteByQuery('*:*');
             $instance->getLucene()->commit();
             $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->format('Delete ' . $instance->getPublicName(), array('fg' => 'red', 'bold' => true)))));
         }
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     $app = $arguments['application'];
     $this->checkAppExists($app);
     $this->standardBootstrap($app, $options['env']);
     $start = microtime(true);
     $instances = sfLucene::getAllInstances();
     foreach ($instances as $instance) {
         $this->optimize($instance);
     }
     $time = microtime(true) - $start;
     $final = $this->formatter->format('All done!', array('fg' => 'red', 'bold' => true)) . ' Optimized for ' . $this->formatter->format(count($instances), array('fg' => 'cyan'));
     $final .= count($instances) == 1 ? ' index in ' : ' indexes in ';
     $final .= $this->formatter->format(number_format($time, 5), array('fg' => 'cyan')) . ' seconds.';
     $this->dispatcher->notify(new sfEvent($this, 'command.log', array('', $final)));
 }
Ejemplo n.º 4
0
    sfContext::getInstance()->getUser()->setCulture('en');
    $t->is(sfLucene::getInstance('testLucene')->getParameter('culture'), 'en', '::getInstance() can guess the culture');
} catch (Exception $e) {
    $t->fail('::getInstance() can guess the culture');
}
if ($new) {
    $t->ok($new->getParameter('is_new'), 'property "is_new" is true on a new index');
    $t->is($new->numDocs(), 0, '->numDocs() indicates index is empty');
} else {
    $t->skip('index has new status new status on new index');
    $t->skip('->numDocs() indicates index is empty');
}
$t->diag('testing ::getAllInstances()');
try {
    $t->no_exception('::getAllInstance() executes without exception');
    $instances = sfLucene::getAllInstances();
    $e->no();
} catch (Exception $ex) {
    $instances = array();
    $e->caught($ex);
}
$t->is_deeply($instances, array(sfLucene::getInstance('testLucene', 'en'), sfLucene::getInstance('testLucene', 'fr'), sfLucene::getInstance('fooLucene', 'en')), '::getAllInstances() returns all instances');
$t->is_deeply(sfLucene::getAllNames(), array('testLucene', 'fooLucene'), '::getAllNames() returns all configured names');
$t->diag('testing ->loadConfig()');
$h = $lucene->getParameterHolder();
$t->isa_ok($h, 'sfParameterHolder', '->getParameterHolder() returns a parameter holder');
$t->is($h->get('name'), 'testLucene', 'property "name" is the name of the index');
$t->is($h->get('culture'), 'en', 'property "culture" is the culture of the index');
$t->is($h->get('enabled_cultures'), array('en', 'fr'), 'property "enabled_cultures" contains all enabled cultures');
$t->like($h->get('index_location'), '#/index/testLucene/en$#', 'property "index_location" is the correct path');
$t->is($h->get('encoding'), 'UTF-8', 'property "encoding" is the encoding');
 public function start($app, $env, $options = array())
 {
     if ($this->isRunning($app, $env)) {
         throw new sfException('Server is running, cannot start (pid file : ' . $this->getPidFile($app, $env) . ')');
     }
     $instances = sfLucene::getAllInstances($this->configuration);
     if (count($instances) == 0) {
         throw new sfException('There is no Solr instance for the current application');
     }
     $host = $instances[0]->getParameter('host');
     $port = $instances[0]->getParameter('port');
     $base_url = $instances[0]->getParameter('base_url');
     // start the jetty built in server
     $command = sprintf('cd %s/plugins/sfSolrPlugin/lib/vendor/Solr/example; %s %s -Xmx%s -Xms%s -Dsolr.solr.home=%s/config/solr/ -Dsolr.data.dir=%s/data/solr_index -Dsolr.lib.dir=%s/plugins/sfSolrPlugin/lib/vendor/Solr/example/solr/lib -Djetty.port=%s -Djetty.logs=%s -jar start.jar > %s/solr_server_%s_%s.log 2>&1 & echo $!', sfConfig::get('sf_root_dir'), $this->nohup, $this->java, $options['Xmx'], $options['Xms'], sfConfig::get('sf_root_dir'), sfConfig::get('sf_root_dir'), sfConfig::get('sf_root_dir'), $port, sfConfig::get('sf_root_dir') . '/log', sfConfig::get('sf_root_dir') . '/log', $app, $env);
     $this->logSection('exec ', $command);
     exec($command, $op);
     if (method_exists($this->getFilesystem(), 'execute')) {
         $this->getFilesystem()->execute(sprintf('cd %s', sfConfig::get('sf_root_dir')));
     } else {
         $this->getFilesystem()->sh(sprintf('cd %s', sfConfig::get('sf_root_dir')));
     }
     $pid = (int) $op[0];
     file_put_contents($this->getPidFile($app, $env), $pid);
     $this->logSection("solr", "Server started with pid : " . $pid);
     $this->logSection("solr", "server started  : http://" . $host . ":" . $port . $base_url);
 }
Ejemplo n.º 6
0
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
try {
    $e = $t->exception('::getInstance() rejects invalid names');
    sfLucene::getInstance('badname', 'en', $app_configuration);
    $e->no();
} catch (Exception $ex) {
    $e->caught($ex);
}
$t->skip('->numDocs() TODO !! indicates index is empty');
$t->diag('testing ::getAllInstances()');
try {
    $e = $t->no_exception('::getAllInstance() executes without exception');
    $instances = sfLucene::getAllInstances($app_configuration);
    $e->no();
} catch (Exception $ex) {
    $instances = array();
    $e->caught($ex);
}
$t->is_deeply($instances, array(sfLucene::getInstance('index', 'en', $app_configuration), sfLucene::getInstance('index', 'fr', $app_configuration), sfLucene::getInstance('fooLucene', 'en', $app_configuration)), '::getAllInstances() returns all instances');
$t->is_deeply(sfLucene::getAllNames($app_configuration), array('index', 'fooLucene'), '::getAllNames() returns all configured names');
$t->diag('testing ->loadConfig()');
$lucene = sfLucene::getInstance('index', 'en', $app_configuration);
$h = $lucene->getParameterHolder();
$t->isa_ok($h, 'sfParameterHolder', '->getParameterHolder() returns a parameter holder');
$t->is($h->get('name'), 'index', 'property "name" is the name of the index');
$t->is($h->get('culture'), 'en', 'property "culture" is the culture of the index');
$t->is($h->get('enabled_cultures'), array('en', 'fr'), 'property "enabled_cultures" contains all enabled cultures');
$t->is($h->get('encoding'), 'UTF-8', 'property "encoding" is the encoding');