/** * 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); }
/** * Tests invalid arguments. * * @param $param The argument to test. * * @expectedException InvalidArgumentException * @dataProvider provideInvalidArguments */ function testInvalidArguments($param) { $this->solr->query($param); }
/** * Opens a new Solr connection. * * @param string $url The URL for Solr queries. * @return SolrConnection * * @throws SolrException */ public static function connect($url = 'http://localhost:8983/solr') { self::autoload('SolrConnection'); return SolrConnection::connect($url); }
/** * Tests {@link SolrConnection::deleteByQuery()}. */ function testDeleteByQuery() { $this->httpClientMock->expects($this->once())->method('sendRequest')->with($this->equalTo('/update'), $this->equalTo('<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<delete><query>foo:bar</query></delete>' . "\n"))->will($this->returnValue(new HTTP_Request2_Response('HTTP/1.0 200 OK'))); $this->solr->deleteByQuery('foo:bar'); }