Module: Olibrary::Search

Included in:
Client
Defined in:
lib/olibrary/client/search.rb

Instance Method Summary collapse

Instance Method Details

#search(search_params, limit = 10, offset = 0) ⇒ Object

Robust access to the Olibrary free-text search.

A simple search is converted to a cross field query. You can add multiple requirements to a single parameter by including a comma within the string. @example: search(“Science, Physics”) will find all books with both science AND physics as subjects)

Likewise you can combine multiple parameters to refine your results Possible search parameter keys include :q (cross-field query) :author :publisher :isbn :title :person :place :subject

Examples:

search(“A brief history of time”)

search(Brief History of Time”, subject: “Science, Physics”, author: “Stephen Hawking”)

Parameters:

  • limit (defaults to: 10)

    defaults to 10 but can be set to any number or nil for all. OpenLibrary returns results in batches of 100 so a limit greater than that will make subsequent requests until the limit or end of results is reached. Be warned that high limits on broad queries will take considerable time and return large data sets.

  • offset (defaults to: 0)

    is useful if you want to continue a search from a given offset.

Returns:

  • An array of documents matching the query with all attributes accessible via method calls. Additional convenience methods ‘book’ and ‘authors’ are procs for retrieving the full document for the book and authors respectively. Usage: results.book.call() => client.book(results[‘cover_edition_key’])



27
28
29
30
# File 'lib/olibrary/client/search.rb', line 27

def search(search_params, limit = 10, offset = 0)
  processed_params = search_params.is_a?(String) ? { q: search_params } : search_params
  _search(processed_params, limit, offset)
end