diff --git a/lib/vierbergenlars/Forage/Transport/Http.php b/lib/vierbergenlars/Forage/Transport/Http.php index ce77f13..8a808be 100644 --- a/lib/vierbergenlars/Forage/Transport/Http.php +++ b/lib/vierbergenlars/Forage/Transport/Http.php @@ -145,7 +145,13 @@ public function search( if(curl_errno($ch)) throw new TransportException('cURL error: '.curl_error($ch), curl_errno($ch)); curl_close($ch); - + if($resp === 'no results') { + return array( + 'totalHits'=>0, + 'facets'=>array(), + 'hits'=> array(), + ); + } return json_decode($resp, true); } diff --git a/test/transport/http.php b/test/transport/http.php index 5c988e5..a9518f2 100644 --- a/test/transport/http.php +++ b/test/transport/http.php @@ -72,6 +72,17 @@ function testBasicSearch() $this->assertEqual($lolCatSearch['totalHits'], 2); } + function testSearchEmptyResultSet() + { + $search = $this->transport->search('s'); + var_dump($search); + $this->assertTrue(is_array($search)); + $this->assertEqual($search['totalHits'], 0); + $this->assertEqual($search['hits'], array()); + $this->assertEqual($search['facets'], array()); + } + + function testFieldedSearch() { $lolSearch = $this->transport->search('Lol', array('title')); @@ -131,5 +142,4 @@ function testDelete() $lolSearch = $this->transport->search('Lol'); $this->assertEqual($lolSearch['totalHits'], 2); } - }