Changeset 1304
- Timestamp:
- Aug 29, 2010, 11:54:01 PM (10 years ago)
- Location:
- cpc/trunk/project
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpc/trunk/project/lib/model/solr/SolrListener.php
r1183 r1304 1 1 <?php 2 2 3 3 4 class SolrConnector extends sfLogger … … 6 7 private $_options = NULL; 7 8 9 public static function getFileCommands() { 10 return sfConfig::get('sf_log_dir').'/solr/commands.log'; 11 } 12 8 13 protected function doLog($message, $priority) 9 14 { … … 28 33 } 29 34 35 36 public function updateFromCommands() { 37 if (!file_exists(self::getFileCommands().'.lock') && file_exists(self::getFileCommands())) 38 rename(self::getFileCommands(), self::getFileCommands().'.lock'); 39 if (!file_exists(self::getFileCommands().'.lock')) 40 return ; 41 foreach(file(self::getFileCommands().'.lock') as $line) { 42 if (preg_match('/(UPDATE|REMOVE): ([^\/]+)\/(\d+)/', $line, $matches)) { 43 if ($matches[1] == 'UPDATE') { 44 $obj = Doctrine::getTable($matches[2])->find($matches[3]); 45 if ($obj) 46 $this->updateLuceneRecord($obj); 47 else 48 echo $matches[2].'/'.$matches[3]." not found\n"; 49 }else{ 50 $this->solr->deleteById($matches[2].'/'.$matches[3]); 51 } 52 } 53 } 54 unlink(self::getFileCommands().'.lock'); 55 } 56 30 57 private function get_and_strip($obj, $field) { 31 58 $f = $obj->get($field); … … 92 119 $document->addField('title', $this->getObjFieldsValue($obj, $t), 1.2 * $extra_weight); 93 120 } 121 94 122 // La description 95 123 if (isset($content)) { … … 153 181 */ 154 182 protected $_options = array(); 183 184 protected static $fileCommand = null; 185 protected static $fileDispatcher = null; 186 187 protected static function getFileCommand() { 188 if (!self::$fileDispatcher) { 189 self::$fileDispatcher = new sfEventDispatcher(); 190 } 191 if (!self::$fileCommand) { 192 self::$fileCommand = new sfFileLogger(self::$fileDispatcher, array('file' => SolrConnector::getFileCommands())); 193 } 194 return self::$fileCommand; 195 } 196 197 private $command = null; 198 155 199 /** 156 200 * __construct … … 162 206 { 163 207 $this->_options = $options; 208 $this->command = self::getFileCommand(); 164 209 } 165 210 … … 170 215 return $this->solr; 171 216 } 217 218 private function sendCommand($status, $obj) { 219 $this->command->log($status.': '.get_class($obj).'/'.$obj->id); 220 } 172 221 173 222 // Réindexation après une création / modification … … 175 224 { 176 225 $obj = $event->getInvoker(); 177 $this->getSolrConnector()->updateLuceneRecord($obj); 226 // $this->getSolrConnector()->updateLuceneRecord($obj); 227 $this->sendCommand('UPDATE', $obj); 178 228 } 179 229 … … 181 231 public function postDelete(Doctrine_Event $event) 182 232 { 183 $this->getSolrConnector()->deleteLuceneRecord($event->getInvoker()); 233 $obj = $event->getInvoker(); 234 // $this->getSolrConnector()->deleteLuceneRecord($obj); 235 $this->sendCommand('DELETE', $obj); 184 236 } 185 237 -
cpc/trunk/project/test/unit/solrableTest.php
r1157 r1304 23 23 $i->addTag('loi:1987'); 24 24 $i->save(); 25 25 $s->updateFromCommands(); 26 26 $id = "Intervention/".$i->id; 27 27 $a = $s->search("id:$id"); 28 print_r($a); 28 29 $t->is(count($a['response']['docs']), 1, "L'intervention a été ajoutée"); 29 30 $a = $s->search("bonjour id:$id"); 31 print_r($a); 30 32 $t->is($a['response']['docs'][0]['id'], $id, "L'intervention est trouvable"); 31 33 $a = $s->search("salut id:$id"); … … 33 35 $i->intervention = $inter." salut"; 34 36 $i->save(); 37 $s->updateFromCommands(); 35 38 $a = $s->search("salut id:$id"); 36 39 $t->is($a['response']['docs'][0]['id'], $id, "L'intervention retournée sur des mots reindexés"); … … 39 42 $p->nom = "Benjamin Ooghe"; 40 43 $p->save(); 44 $s->updateFromCommands(); 41 45 $id = "Parlementaire/".$p->id; 42 46 $a = $s->search("id:$id"); … … 53 57 $q->ministere = "Ministere de la crise et du déficit"; 54 58 $q->save(); 59 $s->updateFromCommands(); 55 60 $id = "QuestionEcrite/".$q->id; 56 61 $a = $s->search("id:$id"); … … 62 67 $a = Doctrine::getTable('Amendement')->find(2); 63 68 $a->save(); 69 $s->updateFromCommands(); 70 64 71 $id = "Amendement/".$a->id; 65 72 $r = $s->search("id:$id");
Note: See TracChangeset
for help on using the changeset viewer.