/** * add solrdocument for indexing * * @param SolrDocument $docs */ public function add($docs) { // echo "executed\n\n\n\n"; if ($docs instanceof SolrDocument) { $docs = array($docs); } $defaultFields = Configuration::get('default-fields'); foreach ($docs as $doc) { foreach ($defaultFields as $field_key => $field_value) { $doc->addField(new SolrSimpleField($field_key, $field_value)); } } print_r($docs); return parent::add($docs); }
/** * Tests if a document with multiple fields is added correctly. */ function testAddComplexDocument() { $field1 = $this->getMock('SolrField'); $field1->expects($this->any())->method('getName')->will($this->returnValue('dummy1')); $field1->expects($this->any())->method('getValue')->will($this->returnValue('foobar')); $field1->expects($this->any())->method('getBoost')->will($this->returnValue(null)); $field2 = $this->getMock('SolrField'); $field2->expects($this->any())->method('getName')->will($this->returnValue('dummy2')); $field2->expects($this->any())->method('getValue')->will($this->returnValue('foobar')); $field2->expects($this->any())->method('getBoost')->will($this->returnValue(1.6)); $field3 = $this->getMock('SolrField'); $field3->expects($this->any())->method('getName')->will($this->returnValue('dummy3')); $field3->expects($this->any())->method('getValue')->will($this->returnValue('foobar')); $field3->expects($this->any())->method('getBoost')->will($this->returnValue(null)); $document = $this->getMock('SolrDocument'); $document->expects($this->any())->method('getFields')->will($this->returnValue(array($field1, $field2, $field3))); $document->expects($this->any())->method('getBoost')->will($this->returnValue(2.5)); $this->httpClientMock->expects($this->once())->method('sendRequest')->with($this->equalTo('/update'), $this->equalTo('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<add><doc boost="2.5"><field name="dummy1">foobar</field><field name="dummy2" boost="1.6">foobar</field><field name="dummy3">foobar</field></doc></add>' . "\n"))->will($this->returnValue(new HTTP_Request2_Response('HTTP/1.0 200 OK'))); $this->solr->add($document); }