Changeset 2536


Ignore:
Timestamp:
Dec 4, 2011, 4:17:13 PM (8 years ago)
Author:
teymour
Message:

Application de la r2501 pour NosSenateurs? (Solr Optimize)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpc/branches/senat/project/lib/model/solr/SolrConnector.class.php

    r1541 r2536  
    55  private $solr = NULL;
    66  private $_options = NULL;
     7  private $nb_commit = 0;
    78
    89  protected function doLog($message, $priority)
     
    2829 
    2930
    30   public function updateFromCommands() {
     31  public function updateFromCommands($output = 0) {
    3132    $file = SolrCommands::getInstance()->getCommandContent();
    3233    foreach(file($file) as $line) {
    3334      if (preg_match('/(UPDATE|DELETE) : (.+)/', $line, $matches)) {
    3435        $obj = json_decode($matches[2]);
     36        if ($output)
     37                echo "ID: ".$obj->id."\n";
    3538        if ($matches[1] == 'UPDATE') {
    3639          $this->updateLuceneRecord($obj);
     
    4346  }
    4447
     48  public function commit() {
     49        $optimize = false;
     50        $wait = false;
     51        $this->nb_commit++;
     52        if ($this->nb_commit > 1000) {
     53                $optimize = true;
     54                $wait = true;
     55                $this->nb_commit = 0;
     56        }
     57        return $this->solr->commit($optimize, $wait);
     58  }
    4559
    4660  public function deleteLuceneRecord($solr_id)
    4761  {
    4862    if($this->solr->deleteById($solr_id) ) {
    49       return $this->solr->commit();
     63      return $this->commit();
    5064    }
    5165    return false;
     
    7286     }
    7387     $this->solr->addDocument($document);
    74      $this->solr->commit();
     88     $this->commit();
    7589  }
    7690
    7791  public function deleteAll() {
    7892    $this->solr->deleteByQuery('*:*');
    79     $this->solr->commit();
     93    $this->commit();
    8094  }
    8195
     
    93107        $results['response']['docs'][$i]['object'] = Doctrine::getTable($res['object_name'])->find($res['object_id']);
    94108      }
    95       if (!$results['response']['docs'][$i]['object'])
    96         $unset[] = $i;
     109      $results['response']['docs'][$i]['hightlighting'] = $results['response']['highlighting'][$id]['text'];
     110      $unset[] = $i;
    97111    }
    98112    foreach ($unset as $i) {
Note: See TracChangeset for help on using the changeset viewer.