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( "ping", $r ); } function testReConnectAndPing() { $this->solr->reconnect(); $r = $this->solr->sendRawGetCommand( 'admin/ping' ); self::assertContains( "ping", $r ); } function testCloseReConnectAndPing() { fclose( $this->solr->connection ); $this->solr->reconnect(); $r = $this->solr->sendRawGetCommand( 'admin/ping' ); self::assertContains( "ping", $r ); } function testSearchEmptyResultsSimple() { $r = $this->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 testSearchWithBrokenQuery() { try { $r = $this->solr->search( 'id:[0 to', '' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchNetworkException $e ) { self::assertContains( 'A network issue occurred:', $e->getMessage() ); self::assertContains( 'ParseException:', $e->rawBody ); } } 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 ); } function testSolrHttpStatusCodeOk() { $this->solr = new testSolrFileWrapper( dirname( __FILE__ ) . '/../testfiles/solr-http-status.txt' ); $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); } function testSolrHttpStatusCodeFail() { $this->solr = new testSolrFileWrapper( dirname( __FILE__ ) . '/../testfiles/solr-http-status-fail.txt' ); try { $r = $this->solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), 'cfe5cc06-9b07-4e4b-930e-7e99f5202570solr' ); self::fail( 'Expected exception not thrown.' ); } catch ( ezcSearchNetworkException $e ) { self::assertEquals( 'A network issue occurred: The HTTP server reported: HTTP/1.1 500 Internal Server Error', $e->getMessage() ); } fclose( $this->solr->connection ); } } ?>