Polymatheia supports accessing metadata records via the SRU protocol. SRU (Search/Retrieve via URL) is a standard XML-based protocol for search queries, utilizing CQL (Contextual Query Language), a standard syntax for representing queries. Each web service that implements the SRU protocol should provide an Explain record at its base URL that allows a client to retrieve a description of the facilities available at this SRU server.
Use the ~polymatheia.data.reader.SRUExplainRecordReader
. Polymatheia provides direct access to the record schemas that can be used with the SRU web service as well as to the echoed request (i.e., the request parameters echoed back to the client).
python
from polymatheia.data.reader import SRUExplainRecordReader
reader = SRUExplainRecordReader("http://sru.k10plus.de/gvk") for record in reader: print(record)
print(reader.schemas) print(reader.echo)
Use the class ~polymatheia.data.reader.SRURecordReader
to query an SRU server:
python
from polymatheia.data.reader import SRURecordReader
- reader = SRURecordReader("http://sru.k10plus.de/gvk",
query="dog cat mouse")
- for record in reader:
print(record)
Note
This will fetch ALL records that match the query. Consider limiting the size of the result set using the max_records
parameter as described below.
Provide a parameter max_records
that specifies the desired number of records to return:
python
from polymatheia.data.reader import SRURecordReader
- reader = SRURecordReader("http://sru.k10plus.de/gvk",
query="dog cat mouse", max_records=10)
- for record in reader:
print(record)
Note
This will either retrieve exactly max_records that match the query or less. It is a good idea to check the total number of records a query retrieves beforehand (see below).
The function result_count
of ~polymatheia.data.reader.SRURecordReader
returns the number of records that match the given query. Checking this value in advance allows to specify the max_records
as necessary.
python
from polymatheia.data.reader import SRURecordReader
- result_count = SRURecordReader.result_count("http://sru.k10plus.de/gvk",
query="dog cat mouse")
print(result_count)
Passing the parameter record_schema
, i.e. a metadata format, to the ~polymatheia.data.reader.SRURecordReader
returns all records in this format:
python
from polymatheia.data.reader import SRURecordReader
- reader = SRURecordReader("http://sru.k10plus.de/gvk",
query="dog cat mouse", max_records=10, record_schema="mods" )
- for record in reader:
print(record)
Note
See the SRU Explain record of the appropriate web service for all supported record schemas. Also, consider the SRU specification for more details about other available SRU parameters.
The echo
attribute of ~polymatheia.data.reader.SRURecordReader
echoes the request parameters back to the client. It is available after starting the iteration:
python
from polymatheia.data.reader import SRURecordReader
- reader = SRURecordReader("http://sru.k10plus.de/gvk",
query="dog cat mouse", max_records=10)
- for record in reader:
print(reader.echo) break