Skip to content
Snippets Groups Projects
Commit 5b4ce5c3 authored by Hoop, Bert Jan de's avatar Hoop, Bert Jan de
Browse files

L05DOCBST-38 add get_hits method

parent 039c07e0
No related branches found
No related tags found
No related merge requests found
...@@ -343,6 +343,22 @@ class Webquery { ...@@ -343,6 +343,22 @@ class Webquery {
} }
/**
* return value of the hits element in search response
* @return number of hits or false if there is no valid search reponse
*/
public function get_hits() {
$resp_xml = $this->get_resp_xml();
if (!isset($resp_xml)) {
return false;
}
$hits = $resp_xml->xpath("//hits");
return empty($hits) ? false : (string) $hits[0];
}
/** /**
* @return boolean true if response contains next element * @return boolean true if response contains next element
*/ */
......
...@@ -140,6 +140,7 @@ EOT; ...@@ -140,6 +140,7 @@ EOT;
$this->assertEquals($expect, $records, '1st: search response records'); $this->assertEquals($expect, $records, '1st: search response records');
$this->assertEquals('', $wq->get_error_code(), '1st: search response error code'); $this->assertEquals('', $wq->get_error_code(), '1st: search response error code');
$this->assertEquals('', $wq->get_error_message(), '1st: search response error message'); $this->assertEquals('', $wq->get_error_message(), '1st: search response error message');
$this->assertEquals(1, $wq->get_hits(), '1st: search response hits');
// second request fails // second request fails
$wq->set_query('record=nothing'); $wq->set_query('record=nothing');
...@@ -160,6 +161,7 @@ EOT; ...@@ -160,6 +161,7 @@ EOT;
$this->assertEquals($expect, $records, '2nd: search response records'); $this->assertEquals($expect, $records, '2nd: search response records');
$this->assertEquals('WQW_NO_HITS', $wq->get_error_code(), '2nd: search response error code'); $this->assertEquals('WQW_NO_HITS', $wq->get_error_code(), '2nd: search response error code');
$this->assertEquals('nothing found', $wq->get_error_message(), '2nd: search response error message'); $this->assertEquals('nothing found', $wq->get_error_message(), '2nd: search response error message');
$this->assertEquals(false, $wq->get_hits(), '2nd: search response hits');
$this->assertEquals(2, count($request_history), 'request history count'); $this->assertEquals(2, count($request_history), 'request history count');
// check first request // check first request
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment