Class: DNZ::Search
Overview
This class represents a digitalnz search API call. It should not be created directly. Instead use the Client.search
method.
Example
search = client.search('text')
puts "%d results found on %d pages" % [search.result_count, search.pages]
Instance Method Summary collapse
-
#custom_search? ⇒ Boolean
Return true if this search is using a custom search engine.
-
#initialize(client, search_options) ⇒ Search
constructor
Constructor for Search class.
- #inspect ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#options ⇒ Object
The search options passed to the digitalnz API.
-
#page=(new_page) ⇒ Object
Set the page.
-
#text ⇒ Object
The text used for searching.
- #to_s ⇒ Object
Methods included from Memoizable
Constructor Details
#initialize(client, search_options) ⇒ Search
Constructor for Search class. Do not call this directly, instead use the Client.search
method.
24 25 26 27 28 29 |
# File 'lib/dnz/search.rb', line 24 def initialize(client, ) @client = client @search_options = execute end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/dnz/search.rb', line 67 def method_missing(method, * args, & block) if @results @results.send(method, * args, & block) else super end end |
Instance Method Details
#custom_search? ⇒ Boolean
Return true if this search is using a custom search engine
63 64 65 |
# File 'lib/dnz/search.rb', line 63 def custom_search? !@search_options.has_key?(:custom_search) end |
#inspect ⇒ Object
48 49 50 |
# File 'lib/dnz/search.rb', line 48 def inspect self.to_s end |
#options ⇒ Object
The search options passed to the digitalnz API
37 38 39 |
# File 'lib/dnz/search.rb', line 37 def @search_options end |
#page=(new_page) ⇒ Object
Set the page. This will update the search :start option and call the API again. The results array will be replaced with the new page of results.
43 44 45 46 |
# File 'lib/dnz/search.rb', line 43 def page=(new_page) @search_options['start'] = (new_page-1) * num_results_requested execute end |
#text ⇒ Object
The text used for searching
32 33 34 |
# File 'lib/dnz/search.rb', line 32 def text @search_options[:search_text] end |
#to_s ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/dnz/search.rb', line 52 def to_s { :results => self.result_count, :facets => self.facets.length, :page => self.page, :pages => self.pages, :per_page => self.num_results_requested }.inspect end |