Class: Chef::Search::Query
- Inherits:
-
Object
- Object
- Chef::Search::Query
- Defined in:
- lib/chef/search/query.rb
Instance Attribute Summary collapse
-
#rest ⇒ Object
Returns the value of attribute rest.
Instance Method Summary collapse
-
#initialize(url = nil) ⇒ Query
constructor
A new instance of Query.
- #list_indexes ⇒ Object
-
#search(type, query = "*:*", sort = 'X_CHEF_id_CHEF_X asc', start = 0, rows = 1000, &block) ⇒ Object
Search Solr for objects of a given type, for a given query.
Constructor Details
Instance Attribute Details
#rest ⇒ Object
Returns the value of attribute rest.
26 27 28 |
# File 'lib/chef/search/query.rb', line 26 def rest @rest end |
Instance Method Details
#list_indexes ⇒ Object
50 51 52 |
# File 'lib/chef/search/query.rb', line 50 def list_indexes response = @rest.get_rest("search") end |
#search(type, query = "*:*", sort = 'X_CHEF_id_CHEF_X asc', start = 0, rows = 1000, &block) ⇒ Object
Search Solr for objects of a given type, for a given query. If you give it a block, it will handle the paging for you dynamically.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/search/query.rb', line 34 def search(type, query="*:*", sort='X_CHEF_id_CHEF_X asc', start=0, rows=1000, &block) raise ArgumentError, "Type must be a string or a symbol!" unless (type.kind_of?(String) || type.kind_of?(Symbol)) response = @rest.get_rest("search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}") if block response["rows"].each { |o| block.call(o) unless o.nil?} unless (response["start"] + response["rows"].length) >= response["total"] nstart = response["start"] + rows search(type, query, sort, nstart, rows, &block) end true else [ response["rows"], response["start"], response["total"] ] end end |