Skip to content

Commit c275ce3

Browse files
authored
Merge pull request #5 from minhd/develop
Updated core
2 parents 78a312a + 40280cb commit c275ce3

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ branches:
44
- staging
55
language: php
66
php:
7+
- 5.5
78
- 5.6
89
- 7.0
910
- hhvm
@@ -17,7 +18,7 @@ before_script:
1718
- composer dump-autoload --optimize
1819
- composer solr-get
1920
script:
20-
- phpunit
21+
- vendor/bin/phpunit
2122
after_script:
2223
- wget https://scrutinizer-ci.com/ocular.phar
2324
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/filesystem": "^3.1",
2121
"symfony/stopwatch": "^3.1",
2222
"symfony/finder": "^3.1",
23-
"illuminate/support": "5.3.0"
23+
"illuminate/support": "^5.2.0"
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "~4.8 || ~5.0",

src/SolrClient.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use MinhD\SolrClient\SolrClientTrait\ManageCollectionTrait;
1111
use MinhD\SolrClient\SolrClientTrait\ManageSchemaTrait;
1212
use MinhD\SolrClient\SolrClientTrait\SearchTrait;
13-
use Symfony\Component\Config\Definition\Exception\Exception;
1413

1514
class SolrClient
1615
{
@@ -43,8 +42,15 @@ public function __construct(
4342
$port = 8983,
4443
$core = 'gettingstarted'
4544
) {
46-
$this->host = $this->cleanHost($host);
45+
46+
$host = $this->cleanHost($host);
47+
$parts = parse_url($host);
48+
$this->host = $parts['scheme'] . "://" . $parts['host'];
49+
4750
$this->port = $port;
51+
if (array_key_exists('port', $parts)) {
52+
$this->port = $parts['port'];
53+
}
4854

4955
$this->client = new HttpClient([
5056
'base_uri' => $this->getBaseUrl()

src/SolrClientTrait/SearchTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function getSearchParams()
5050

5151
/**
5252
* @param string $name
53+
* @return null
5354
*/
5455
public function getSearchParam($name)
5556
{

src/SolrSearchResult.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class SolrSearchResult
88
private $numFound;
99
private $docs;
1010

11+
private $errorMessage = null;
12+
1113
private $facets = null;
1214
private $facetFields = null;
1315

@@ -35,12 +37,22 @@ public function __construct($payload, SolrClient $client)
3537

3638
/**
3739
* @param mixed $payload
40+
* @throws \Exception
3841
*/
3942
public function init($payload)
4043
{
4144
$this->params = $payload['responseHeader']['params'];
45+
46+
// error
47+
if (!array_key_exists('response', $payload)) {
48+
$this->errorMessage = $payload['error']['msg'];
49+
return;
50+
}
51+
52+
// numFound
4253
$this->numFound = $payload['response']['numFound'];
4354

55+
// facet_counts
4456
if (array_key_exists('facet_counts', $payload)) {
4557
$this->facets = $payload['facet_counts'];
4658
$this->facetFields = [];
@@ -51,6 +63,7 @@ public function init($payload)
5163
}
5264
}
5365

66+
// docs
5467
$this->docs = [];
5568
foreach ($payload['response']['docs'] as $doc) {
5669
$this->docs[] = new SolrDocument($doc);
@@ -117,6 +130,11 @@ public function getDocs($format = 'array')
117130
return $this->docs;
118131
}
119132

133+
public function errored()
134+
{
135+
return $this->errorMessage != null;
136+
}
137+
120138
/**
121139
* @return mixed
122140
*/
@@ -158,4 +176,12 @@ public function getNextCursorMark()
158176
{
159177
return $this->nextCursorMark;
160178
}
179+
180+
/**
181+
* @return null
182+
*/
183+
public function getErrorMessage()
184+
{
185+
return $this->errorMessage;
186+
}
161187
}

tests/SolrClientTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ public function it_should_be_able_to_get_base_url()
2929
$solr = new SolrClient('development.dev/', 8080);
3030
$solr->setPath('solr2');
3131
$this->assertEquals('http://development.dev:8080/solr2/', $solr->getBaseUrl());
32+
33+
34+
}
35+
36+
/** @test **/
37+
public function it_should_find_host_with_port()
38+
{
39+
$solr = new SolrClient('development.dev:8984');
40+
$this->assertEquals('http://development.dev:8984/solr/', $solr->getBaseUrl());
3241
}
3342

3443
/** @test **/

tests/SolrClientTrait/SearchTraitTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ public function it_should_search_correctly()
2626
$solr->remove([1, 2]);
2727
}
2828

29+
/** @test **/
30+
public function it_should_handle_error_correctly()
31+
{
32+
$solr = new SolrClient('localhost', 8983, 'gettingstarted');
33+
$solr->setAutoCommit(true);
34+
35+
$result = $solr->search([
36+
'q' => 'Something:bad!- )'
37+
]);
38+
39+
$this->assertTrue($result->errored());
40+
$this->assertNotEmpty($result->getErrorMessage());
41+
}
42+
2943
/** @test **/
3044
public function it_should_search_and_go_next_page()
3145
{

0 commit comments

Comments
 (0)