10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/spice/connection/search.rb', line 10
def search(index, options=Mash.new)
index = index.to_s
options = {:q => options} if options.is_a? String
options.symbolize_keys!
options[:q] ||= '*:*'
options[:sort] ||= "X_CHEF_id_CHEF_X asc"
options[:start] ||= 0
options[:rows] ||= 1000
options.delete_if{|k,v| !%w(q sort start rows).include?(k.to_s)}
params = options.collect{ |k, v| "#{k}=#{CGI::escape(v.to_s)}"}.join("&")
case index
when 'node'
get("/search/#{CGI::escape(index.to_s)}?#{params}")['rows'].map do |node|
Spice::Node.get_or_new(node)
end
when 'role'
get("/search/#{CGI::escape(index.to_s)}?#{params}")['rows'].map do |role|
Spice::Role.get_or_new(role)
end
when 'client'
get("/search/#{CGI::escape(index.to_s)}?#{params}")['rows'].map do |client|
Spice::Client.get_or_new(client)
end
when 'environment'
get("/search/#{CGI::escape(index.to_s)}?#{params}")['rows'].map do |env|
env['attrs'] = env.delete('attributes')
Spice::Environment.get_or_new(env)
end
else
get("/search/#{CGI::escape(index.to_s)}?#{params}")['rows'].map do |db|
data = db['raw_data']
Spice::DataBagItem.get_or_new(data)
end
end
end
|