Skip to content

Commit

Permalink
Increase compatibility between stream and search result (#583)
Browse files Browse the repository at this point in the history
Increase compatibility between stream rsults ans serach result
  • Loading branch information
Markus Kalkbrenner committed Mar 19, 2018
1 parent fa38360 commit 8bcc392
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/QueryType/Stream/ResponseParser.php
Expand Up @@ -64,6 +64,7 @@ public function parse($result)
return $this->addHeaderInfo(
$data,
[
'numfound' => count($documents),
'documents' => $documents,
]
);
Expand Down
51 changes: 51 additions & 0 deletions src/QueryType/Stream/Result.php
Expand Up @@ -10,6 +10,15 @@
*/
class Result extends BaseResult implements \IteratorAggregate, \Countable
{
/**
* Solr numFound.
*
* This is NOT the number of document fetched from Solr!
*
* @var int
*/
protected $numfound;

/**
* Document instances array.
*
Expand Down Expand Up @@ -48,6 +57,36 @@ public function getStatus()
return $this->status;
}

/**
* Get Solr query time.
*
* This doesn't include things like the HTTP responsetime. Purely the Solr
* query execution time.
*
* @return int
*/
public function getQueryTime()
{
$this->parseResponse();

return $this->queryTime;
}

/**
* get Solr numFound.
*
* Returns the total number of documents found by Solr (this is NOT the
* number of document fetched from Solr!)
*
* @return int
*/
public function getNumFound()
{
$this->parseResponse();

return $this->numfound;
}

/**
* Get Solr status code.
*
Expand Down Expand Up @@ -104,6 +143,18 @@ public function getBody()
return $this->response->getBody();
}

/**
* Get Solr response body in JSON format.
*
* More expressive convenience method that just call getBody().
*
* @return string JSON
*/
public function getJson()
{
return $this->getBody();
}

/**
* Get Solr response data.
*
Expand Down

0 comments on commit 8bcc392

Please sign in to comment.