Skip to content

Commit 6daeef4

Browse files
committed
Add method Client::first
1 parent 1da6cb9 commit 6daeef4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ $client = new SruClient($url, array(
6060
));
6161
```
6262

63-
To iterate over all the results from a `searchRetrieve` query, use the [Records](//scriptotek.github.io/php-sru-client/api_docs/Scriptotek/Sru/Records.html) class returned from `Client::records()`. The first argument is
63+
To get the first record matching a query:
64+
```php
65+
$client->first('bs.isbn="0415919118"');
66+
```
67+
The result is a [Record](//scriptotek.github.io/php-sru-client/api_docs/Scriptotek/Sru/Record.html)
68+
object, or `null` if not found.
69+
70+
To iterate over all the results from a `searchRetrieve` query, use the [Records](//scriptotek.github.io/php-sru-client/api_docs/Scriptotek/Sru/Records.html) object returned from `Client::records()`. The first argument is
6471
the CQL query, and the second optional argument is the number of records to fetch for each request (defaults to 10).
6572

6673
```php

src/Client.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ public function records($cql, $count = 10, $extraParams = array(), $httpClient =
160160
return new Records($cql, $this, $count, $extraParams, $httpClient);
161161
}
162162

163+
/**
164+
* Perform a searchRetrieve request and return first record
165+
*
166+
* @param string $cql
167+
* @param array $extraParams Extra GET parameters
168+
* @param mixed $httpClient A http client
169+
* @return Record
170+
*/
171+
public function first($cql, $extraParams = array(), $httpClient = null)
172+
{
173+
$recs = new Records($cql, $this, 1, $extraParams, $httpClient);
174+
return $recs->numberOfRecords() ? $recs->current() : null;
175+
}
176+
163177
/**
164178
* Perform an explain request
165179
*

0 commit comments

Comments
 (0)