Exemple #1
0
 public function current()
 {
     $data = $this->_result['response']['docs'][$this->_position];
     $doc = new Twm_Service_Solr_Document();
     foreach ($data as $key => $val) {
         $field = new Twm_Service_Solr_Field($key, $val);
         $doc->addField($field);
     }
     $hit = new Twm_Service_Solr_Search_QueryHit($doc);
     $hit->score = isset($data['score']) ? $data['score'] : "";
     return $hit;
 }
Exemple #2
0
 public function addDocument(Twm_Service_Solr_Document $doc)
 {
     $xml = new DOMDocument();
     $xAdd = $xml->createElement('add');
     $xml->appendChild($xAdd);
     $xDoc = dom_import_simplexml($doc->toXml());
     $xDoc = $xml->importNode($xDoc, true);
     $xAdd->appendChild($xDoc);
     $response = $this->_post('update', $xml->saveXML());
     $xml = simplexml_load_string($response->getBody());
     $status = $xml->xpath('//int[@name=\'status\']');
     // TODO parsing errors
     if (isset($status[0]) && $status[0] == '0') {
         return true;
     }
     throw new Exception($response);
     return false;
 }