Skip to content

Commit d49d48e

Browse files
authored
Get record total count (#27)
* Add feature totalNumberOfRecords * Add cli.js * Update deps
1 parent 63aeed3 commit d49d48e

22 files changed

+4223
-4745
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ npm-debug.log
22
node_modules
33
coverage
44
dist
5-
.nyc_output
5+
.nyc_output
6+
.DS_Store
7+
.env

README.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const client = createClient({url: 'https://foo.bar', recordSchema: 'marc'});
88

99
client.searchRetrieve('foo')
1010
.on('record', record => processRecord(string))
11+
.on('total', totalNumberOfRecords => doSomething(totalNumberOfRecords))
1112
.on('end', () => endProcessing())
1213
.on('error', err => handleError(err));
1314
```
@@ -18,23 +19,39 @@ const client = createClient({url: 'https://foo.bar', recordSchema: 'marc', retri
1819

1920
client.searchRetrieve('foo')
2021
.on('record', record => processRecord(record))
22+
.on('total', totalNumberOfRecords => doSomething(totalNumberOfRecords))
2123
.on('end', nextRecordOffset => endProcessing(nextRecordOffset))
2224
.on('error', err => handleError(err));
2325
```
26+
## Retrieve total amount of records
27+
```js
28+
import createClient from '@natlibfi/sru-client';
29+
const client = createClient({url: 'https://foo.bar', recordSchema: 'marc', maxRecordsPerRequest: 0, retrieveAll: false});
30+
31+
client.searchRetrieve('foo')
32+
.on('total', totalNumberOfRecords => doSomething(totalNumberOfRecords))
33+
.on('end', () => endProcessing())
34+
.on('error', err => handleError(err));
35+
```
36+
2437
# Configuration
2538
## Client creation options
2639
- **url**: The URL of the SRU service.
2740
- **recordSchema**: Schema of the records. **Mandatory**.
2841
- **version**: SRU version. Defaults to **2.0**.
29-
- **maxRecordsPerRequest**: Maximum number of records to retrieve per requests. Defaults to **1000**.
42+
- **maxRecordsPerRequest**: Maximum number of records to retrieve per requests. Defaults to **1000**. If maxRecordsPerRequest is set to **0** search does not retrieve any records. The **total** event returns still the total number of records available for search.
3043
- **recordFormat**: Format of the record argument in **record** event. Defaults to **string** (See export **recordFormats**)
31-
- **retrieveAll**: Whether to retrieve all records or just from the first response. If **false**, the **end** event return the offset of the next record for the query
44+
- **retrieveAll**: Whether to retrieve all records or just from the first response. If **false**, the **end** event return the offset of the next record for the query. The **total** event returns still the total number of records available for search.
3245
## searchRetrieve options:
3346
The first parameter is the mandatory query string. Second is an optional object which supports the following properties:
3447
- **startRecord**: The offset of the record from which to start fetching results from. See **retrieveAll** of the client creation options.
3548
- **recordSchema**: Override default record schema
49+
50+
# Notes
51+
- The **totalNumberOfRecords** returned by the **total** event is limited to the maximum number of records provided by server. Ie. if the SRU servers limit for search and retrieve is 20 000 records, 20 000 is the maximum totalNumberOfRecords available, even if the server's database actually contains more records matching the query.
52+
3653
## License and copyright
3754

38-
Copyright (c) 2015, 2017-2018, 2020 **University Of Helsinki (The National Library Of Finland)**
55+
Copyright (c) 2015, 2017-2018, 2020-2021 **University Of Helsinki (The National Library Of Finland)**
3956

4057
This project's source code is licensed under the terms of **GNU Lesser General Public License Version 3** or any later version.

0 commit comments

Comments
 (0)