Class: ChefAPI::Resource::Search

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-api/resources/search.rb

Instance Attribute Summary

Attributes inherited from Base

#associations

Class Method Summary collapse

Methods inherited from Base

#_attributes, #_prefix, all, #attribute?, build, classname, collection, collection_path, connection, count, create, delete, #destroy, destroy, destroy_all, #diff, #dirty?, each, #errors, exists?, expanded_collection_path, fetch, from_file, from_json, from_url, has_many, #id, #ignore_attribute?, #initialize, inspect, #inspect, list, #new_resource?, post, #primary_key, protect, #protected?, protected_resources, put, #reload!, resource_path, #resource_path, #save, #save!, schema, #to_hash, #to_json, to_s, #to_s, type, update, #update, #update_attribute, #valid?, #validate!, #validators

Constructor Details

This class inherits a constructor from ChefAPI::Resource::Base

Class Method Details

.query(index, query = '*:*', options = {}) ⇒ self

Parameters:

  • index (String)

    the name of the index to search

  • query (String) (defaults to: '*:*')

    the query string

  • options (Hash) (defaults to: {})

    the query string

Returns:

  • (self)

    the current resource



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chef-api/resources/search.rb', line 25

def query(index, query = '*:*', options = {})
  return nil if index.nil?

  params = {}.tap do |o|
    o[:q]     = query
    o[:rows]  = options[:rows]  || 1000
    o[:sort]  = options[:sort]  || 'X_CHEF_id_CHEF_X'
    o[:start] = options[:start] || 0
  end

  path = expanded_collection_path(index: index.to_s)

  response = if filter_result = options[:filter_result]
    connection.post(path, filter_result.to_json, params)
  else
    connection.get(path, params)
  end

  from_json(response, index: index.to_s)
end