<commit_before>class PeopleController < ApplicationController
  def index
    people = Person.all

    if params[:q]
      begin
        regex = Regexp.new(params[:q].gsub(/\s/, '.*'), Regexp::IGNORECASE)
        people = people.any_of(
          {uuid: regex},
          {first_name: regex},
          {preferred_name: regex},
          {last_name: regex},
          {display_name: regex},
          {title: regex},
          {department: regex},
          {residence: regex},
          {'emails.address' => regex},
          {'ids.identifier' => regex}
        )
      rescue RegexpError
        people = Person.none
      end
    end

    @raw_people = people.asc(:last_name, :preferred_name).page(params[:page])
    @people = PersonPresenter.map(@raw_people)
  end

  def show
    @person = PersonPresenter.find(params[:id])
  end
end<commit_msg>Fix searching concatenated first_name & last_name<commit_after>class PeopleController < ApplicationController
  def index
    people = Person.all

    if params[:q]
      begin
        regex = Regexp.new(params[:q].gsub(/\s/, '.*'), Regexp::IGNORECASE)
        ids = Person.collection.aggregate(
          {:$project =>
            {
              uuid: '$uuid',
              display_name: '$display_name',
              title: '$title',
              department: '$department',
              residence: '$residence',
              'emails.address' => '$emails.address',
              'ids.identifier' => '$ids.identifier',
              legal_name: {:$concat => ['$first_name', ' ', '$last_name']},
              full_name: {:$concat => ['$preferred_name', ' ', '$last_name']}
            }
          },
          {:$match => {:$or => [
            {uuid: regex},
            {display_name: regex},
            {title: regex},
            {department: regex},
            {residence: regex},
            {'emails.address' => regex},
            {'ids.identifier' => regex},
            {legal_name: regex},
            {full_name: regex}
          ]}}
        ).map{|p| p[:_id]}

        people = Person.where(:id.in => ids)
      rescue RegexpError
        people = Person.none
      end
    end

    @raw_people = people.asc(:last_name, :preferred_name).page(params[:page])
    @people = PersonPresenter.map(@raw_people)
  end

  def show
    @person = PersonPresenter.find(params[:id])
  end
end
{'fraction_non_alphanumeric': 0.14595744680851064, 'fraction_numerical': 0.0, 'mean_word_length': 1.9609571788413098, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1867230', 'n_tokens_mistral': 705, 'n_tokens_neox': 690, 'n_words': 137}