Class: Search

Inherits:
Application show all
Defined in:
app/controllers/search.rb

Instance Method Summary collapse

Methods inherited from Application

#access_denied, #admin_or_requesting_node, #authenticate_every, #display, #get_available_recipes, #is_admin, #is_admin_or_validator, #redirect_back_or_default, #store_location

Instance Method Details

#indexObject



28
29
30
31
# File 'app/controllers/search.rb', line 28

def index
  indexes = valid_indexes
  display(indexes.inject({}) { |r,i| r[i] = absolute_url(:search_show, i); r })
end

#reindexObject



54
55
56
# File 'app/controllers/search.rb', line 54

def reindex
  display(Chef::SolrQuery.new.rebuild_index)
end

#showObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/search.rb', line 38

def show
  unless valid_indexes.include?(params[:id])
    raise NotFound, "I don't know how to search for #{params[:id]} data objects."
  end
  params[:type] = params.delete(:id)
  display(Chef::SolrQuery.from_params(params).search)
rescue Chef::Exceptions::QueryParseError => e
  # we set status rather than raising BadRequest to avoid a
  # stacktrace in the server log
  self.status = 400
  e_msg = e.message.gsub(/\n/, " ")
  msg = "invalid search query: '#{params[:q]}' #{e_msg}"
  Chef::Log.warn("400 #{msg}")
  display({ "error" => [msg] })
end

#valid_indexesObject



33
34
35
36
# File 'app/controllers/search.rb', line 33

def valid_indexes
  indexes = Chef::DataBag.cdb_list(false)
  indexes += %w{ role node client environment}
end