solr = new ezcSearchSolrHandler; } catch ( ezcSearchCanNotConnectException $e ) { self::markTestSkipped( 'Solr is not running.' ); } $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'timestamp:[* TO *]' ); $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '' ); } function testUnableToConnect() { try { $s = new ezcSearchSolrHandler( 'localhost', 58983 ); $r = $s->sendRawGetCommand( 'admin/ping' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchCanNotConnectException $e ) { self::assertEquals( "Could not connect to 'solr' at 'http://localhost:58983/solr'.", $e->getMessage() ); } } function testConnectAndPing() { $r = $this->solr->sendRawGetCommand( 'admin/ping' ); self::assertContains( "solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); } function testSearchEmptyResults() { $r = $this->solr->search( 'solr', 'name_s' ); self::assertType( 'stdClass', $r ); self::assertEquals( 0, $r->response->numFound ); self::assertEquals( 0, $r->response->start ); self::assertEquals( 0, $r->responseHeader->status ); } function testSimpleIndex() { $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '' ); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 1, $r->response->numFound ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570' ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '' ); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); } function testCommit() { $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '' ); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 1, $r->response->numFound ); } function testTransaction() { $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->beginTransaction(); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->commit(); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 1, $r->response->numFound ); } function testNestedTransaction() { $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->beginTransaction(); $r = $this->solr->beginTransaction(); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->commit(); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->commit(); $r = $this->solr->sendRawGetCommand( 'select', array( 'q' => 'solr', 'wt' => 'json', 'df' => 'name_s' ) ); $r = json_decode( $r ); self::assertEquals( 1, $r->response->numFound ); } function testCommitWithoutBegin() { try { $r = $this->solr->commit(); self::fail( "Expected exception not thrown." ); } catch ( ezcSearchTransactionException $e ) { self::assertEquals( 'Cannot commit without a transaction.', $e->getMessage() ); } } function testSimpleIndexWithSearch() { $r = $this->solr->search( 'solr', 'name_s' ); self::assertEquals( 0, $r->response->numFound ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '' ); $r = $this->solr->search( 'solr', 'name_s', array( 'id', 'name_s' ), array( 'id', 'name_s', 'score' ) ); self::assertEquals( 1, $r->response->numFound ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570' ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), '' ); $r = $this->solr->search( 'solr', 'name_s' ); self::assertEquals( 0, $r->response->numFound ); } } ?>