class CommunityController < ApplicationController helper :profile def index @title = "Community" @letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("") if params[:id] @initial = params[:id] @pages, specs = paginate(:specs, :conditions => ["last_name LIKE ?", @initial+"%"], :order => "last_name, first_name") @users = specs.collect { |spec| spec.user } end end def browse end def search if params[:q] query = params[:q] # First find the user hits... @users = User.find_by_contents(query, :limit => :all) # ...then the subhits. specs = Spec.find_by_contents(query, :limit => :all) faqs = Faq.find_by_contents(query, :limit => :all) # Now combine into one list of distinct users sorted by last name. hits = specs + faqs @users.concat(hits.collect { |hit| hit.user }).uniq! # Sort by last name (requires a spec for each user). @users.each { |user| user.spec ||= Spec.new } @users = @users.sort_by { |user| user.spec.last_name } @pages, @users = paginate(@users) end end end