search_controller.rb 488 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2
class SearchController < ApplicationController
  def index
Zac Wood's avatar
Zac Wood committed
3
    redirect_to(home_url) unless params[:query].length > 1
Zac Wood's avatar
Zac Wood committed
4

Zac Wood's avatar
Zac Wood committed
5 6 7 8 9
    if params[:query].casecmp('god').zero?
      bell = Instructor.find_by_name('Jonathan Bell')
      redirect_to(instructor_url(bell))
    end

10
    results = SearchHelper::GenericItem.fetchall(String.new(params[:query]), semester: @semester).group_by(&:type)
Zac Wood's avatar
Zac Wood committed
11 12
    @instructors = results[:instructor]&.map(&:data)
    @courses = results[:course]&.map(&:data)
Zac Wood's avatar
Zac Wood committed
13 14
  end
end