class RDoc::Servlet

def root_search req, res

def root_search req, res
  search_index = []
  info         = []
  installed_docs.map do |name, href, exists, type, path|
    next unless exists
    search_index << name
    case type
    when :gem
      gemspec = path.gsub(%r%/doc/([^/]*?)/ri$%,
                          '/specifications/\1.gemspec')
      spec = Gem::Specification.load gemspec
      path    = spec.full_name
      comment = spec.summary
    when :system then
      path    = 'ruby'
      comment = 'Documentation for the Ruby standard library'
    when :site then
      path    = 'site'
      comment = 'Documentation for non-gem libraries'
    when :home then
      path    = 'home'
      comment = 'Documentation from your home directory'
    when :extra
      comment = name
    end
    info << [name, '', path, '', comment]
  end
  index = {
    :index => {
      :searchIndex     => search_index,
      :longSearchIndex => search_index,
      :info            => info,
    }
  }
  res.body = "var search_data = #{JSON.dump index};"
  res.content_type = 'application/javascript'
end