Class: ChefAPI::Resource::PartialSearch

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-api/resources/partial_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, keys, query = '*:*', options = {}) ⇒ self

Parameters:

  • index (String)

    the name of the index to search

  • keys (Hash)

    key paths for the attributes to be returned

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

    the query string

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

    the query string

Returns:

  • (self)

    the current resource



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

def query(index, keys, 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 = connection.post(path, keys.to_json, params)
  response['rows'].map! { |row| row['data'] }
  from_json(response, index: index.to_s)
end