searching method.

def search
   if params[:q]
    query = params[:q]
    # First find the user hits...
    @users = User.find_by_contents(query, :limit => :all)
    # ...then the subhits.
    personals = Personal.find_by_contents(query, :limit => :all)
    #flash[:notice] = personals.size
    faqs = Faq.find_by_contents(query, :limit => :all)
    # Now combine into one list of distinct users sorted by last name.
    hits = personals + faqs

    #flash[:notice] = hits.size
    @users.concat(hits.collect { |hit| hit.user }).uniq!

    # Sort by last name (requires a personal for each user).
    @users.each { |user| user.personal ||= Personal.new }

    @users = @users.sort_by { |user| user.personal.last_name }
    #@users = @users.paginate(:page => params[:page], :per_page => 10)
    @invalid = true
   end
  end

Sir, i want to implement a search function. I got a code from one of the
book where the objective is to find a user based on a name or any thing
else..
Here 'User' is a users table..
'Faq' is table which contains info abt the user..
n 'Personal' contains personal info abt user..
Can u please help me in understanding the following lines of code..

# Now combine into one list of distinct users sorted by last name.
    hits = personals + faqs

    #flash[:notice] = hits.size
    @users.concat(hits.collect { |hit| hit.user }).uniq!

    # Sort by last name (requires a personal for each user).
    @users.each { |user| user.personal ||= Personal.new }

    @users = @users.sort_by { |user| user.personal.last_name }

i want to implement searching by tag...
Thank u..