To query Aleph, just create one of the Queries - ISBNQuery for example and put it into aleph.datastructures.requests.SearchRequest wrapper and send the message to the Aleph’s exchange:
isbnq = ISBNQuery("80-251-0225-4")
request = SearchRequest(isbnq)
amqp.send(
message = serialize(request),
properties = "..",
exchange = "ALEPH'S_EXCHANGE"
)
and you will get back AMQP message with SearchResult.
Note
You don’t have to import all structures from datastructures, they should be automatically imported and made global in __init__.py.
If you want to just get count of how many items is there in Aleph, just wrap the ISBNQuery with CountRequest:
isbnq = ISBNQuery("80-251-0225-4")
request = CountRequest(isbnq)
# rest is same..
and you will get back aleph.datastructures.results.CountResult.
Note
You should always use CountRequest instead of just calling len() to SearchResult.records - it doesn’t put that much load to Aleph. Also Aleph is restricted to 150 requests per second.
Here is ASCII flow diagram for you:
ISBNQuery ----. ,--> CountResult
AuthorQuery ----| | `- num_of_records
PublisherQuery ----| ExportRequest |
GenericQuery ----| ISBNValidationRequest |--> SearchResult
| | | `- AlephRecord
V | |
Count/Search/ExportRequest | |--> ISBNValidationResult
| | | - ISBN
V | |
| | |--> ExportResult
V | |
serialize()<----------' deserialize()
| ^
V Client |
AMQPMessage ------> AMQP -------> AMQPMessage
| ^
V |
| ^
V |
| ^
V |
AMQPMessage <------ AMQP <-------- AMQPMessage
| Service ^
| |
V |
reactToAMQPMessage() ............... magic_happens()
Neat, isn’t it?
AQMP is handled by edeposit.amqp module, edeposit.aqmp.aleph provides just datastructures and reactToAMQPMessage().
Bases: edeposit.amqp.aleph.AuthorQuery, edeposit.amqp.aleph._QueryTemplate
Query Aleph to get books by Author.
Parameters: |
|
---|
Bases: edeposit.amqp.aleph.GenericQuery, edeposit.amqp.aleph._QueryTemplate
Used for generic queries to aleph.
Parameters: |
|
---|
For details of base/phrase/.. parameters, see aleph.searchInAleph(). All parameters also serves as properties.
This is used mainly if you want to search by your own parameters and don’t want to use prepared wrappers (AuthorQuery/ISBNQuery/..).
Bases: edeposit.amqp.aleph.ISBNQuery, edeposit.amqp.aleph._QueryTemplate
Query Aleph to get books by ISBN.
Parameters: |
|
---|
Note
ISBN is not unique, so you can get back lot of books with same ISBN. Some books also have two or more ISBNs.
Bases: edeposit.amqp.aleph.PublisherQuery, edeposit.amqp.aleph._QueryTemplate
Query Aleph to get books by Publisher.
Parameters: |
|
---|
React to given (AMQP) message. Return data thru given callback function.
Parameters: |
|
---|---|
Returns: | result of search in Aleph. |
Raises: | ValueError – if bad type of req structure is given. |