<commit_before># Inventory searcher.
# Designed to be populated from a search form using a new/create controller model.
#
class AssetSearcher < BaseSearcher

  # Include the numeric sanitizers mixin
  include TransamNumericSanitizers

  # From the application config
  ASSET_BASE_CLASS_NAME     = SystemConfig.instance.asset_base_class_name

  # add any search params to this list.  Grouped based on their logical queries
  attr_accessor :organization_ids,
                :organization_id,
                :district_id,
                :asset_type_ids,
                :asset_subtype_ids,
                :manufacturer_ids,
                :parent_id,
                :disposition_date,
                :keyword,
                :estimated_condition_type_ids,
                :reported_condition_type_ids,
                :vendor_ids,
                :service_status_type_ids,
                :manufacturer_model,
                # Comparator-based (<=>)
                :manufacture_year,
                :manufacture_year_comparator,
                :purchase_cost,
                :purchase_cost_comparator,
                :replacement_year,
                :replacement_year_comparator,
                :scheduled_replacement_year,
                :scheduled_replacement_year_comparator,
                :policy_replacement_year,
                :policy_replacement_year_comparator,
                :purchase_date,
                :purchase_date_comparator,
                :manufacture_date,
                :manufacture_date_comparator,
                :in_service_date,
                :in_service_date_comparator,
                # Checkboxes
                :in_backlog,
                :purchased_new



  # Return the name of the form to display
  def form_view
    'asset_search_form'
  end
  # Return the name of the results table to display
  def results_view
    'asset_search_results_table'
  end

  def initialize(attributes = {})
    @klass = Object.const_get ASSET_BASE_CLASS_NAME
    super(attributes)
  end

  def to_s
    queries.to_sql
  end

  def cache_variable_name
    AssetsController::INDEX_KEY_LIST_VAR
  end

  private

  #---------------------------------------------------
  # Simple Equality Queries
  #---------------------------------------------------

  def estimated_condition_type_conditions
    clean_estimated_condition_type_ids = remove_blanks(estimated_condition_type_ids)
    @klass.where(estimated_condition_type_id: estimated_condition_type_ids) unless clean_estimated_condition_type_ids.empty?
  end

  def reported_condition_type_conditions
    clean_reported_condition_type_ids = remove_blanks(reported_condition_type_ids)
    @klass.where(reported_condition_type_id: reported_condition_type_ids) unless clean_reported_condition_type_ids.empty?
  end

  def manufacturer_conditions
    clean_manufacturer_ids = remove_blanks(manufacturer_ids)
    @klass.where(manufacturer_id: clean_manufacturer_ids) unless clean_manufacturer_ids.empty?
  end

  def district_type_conditions
    @klass.where(district_id: district_id) unless district_id.blank?
  end

  def asset_type_conditions
    clean_asset_type_ids = remove_blanks(asset_type_ids)
    @klass.where(asset_type_id: clean_asset_type_ids) unless clean_asset_type_ids.empty?
  end

  def asset_subtype_conditions
    clean_asset_subtype_ids = remove_blanks(asset_subtype_ids)
    @klass.where(asset_subtype_id: clean_asset_subtype_ids) unless clean_asset_subtype_ids.empty?
  end

  def location_id_conditions
    @klass.where(parent_id: parent_id) unless parent_id.blank?
  end

  def vendor_conditions
    clean_vendor_ids = remove_blanks(vendor_ids)
    @klass.where(vendor_id: clean_vendor_ids) unless clean_vendor_ids.empty?
  end

  def service_status_type_conditions
    clean_service_status_type_ids = remove_blanks(service_status_type_ids)
    @klass.where(service_status_type: service_status_type_ids) unless clean_service_status_type_ids.empty?
  end

  #---------------------------------------------------
  # Comparator Queries
  #---------------------------------------------------
  def manufacture_year_conditions
    unless manufacture_year.blank?
      case manufacture_year_comparator
      when "-1" # Before Year X
        @klass.where("manufacture_year < ?", manufacture_year)
      when "0" # During Year X
        @klass.where("manufacture_year = ?", manufacture_year)
      when "1" # After Year X
        @klass.where("manufacture_year > ?", manufacture_year)
      end
    end
  end

  def scheduled_replacement_year_conditions
    unless scheduled_replacement_year.blank?
      case scheduled_replacement_year_comparator
      when "-1" # Before Year X
        @klass.where("scheduled_replacement_year < ?", scheduled_replacement_year)
      when "0" # During Year X
        @klass.where("scheduled_replacement_year = ?", scheduled_replacement_year)
      when "1" # After Year X
        @klass.where("scheduled_replacement_year > ?", scheduled_replacement_year)<commit_msg>Updated all simple equality searches so they can accept single id numbers or multi-select inputs<commit_after># Inventory searcher.
# Designed to be populated from a search form using a new/create controller model.
#
class AssetSearcher < BaseSearcher

  # Include the numeric sanitizers mixin
  include TransamNumericSanitizers

  # From the application config
  ASSET_BASE_CLASS_NAME     = SystemConfig.instance.asset_base_class_name

  # add any search params to this list.  Grouped based on their logical queries
  attr_accessor :organization_ids,
                :organization_id,
                :district_id,
                :asset_type_id,
                :asset_type_ids,
                :asset_subtype_id,
                :asset_subtype_ids,
                :manufacturer_id,
                :manufacturer_ids,
                :parent_id,
                :disposition_date,
                :keyword,
                :estimated_condition_type_id,
                :estimated_condition_type_ids,
                :reported_condition_type_id,
                :reported_condition_type_ids,
                :vendor_id,
                :vendor_ids,
                :service_status_type_id,
                :service_status_type_ids,
                :manufacturer_model,
                # Comparator-based (<=>)
                :manufacture_year,
                :manufacture_year_comparator,
                :purchase_cost,
                :purchase_cost_comparator,
                :replacement_year,
                :replacement_year_comparator,
                :scheduled_replacement_year,
                :scheduled_replacement_year_comparator,
                :policy_replacement_year,
                :policy_replacement_year_comparator,
                :purchase_date,
                :purchase_date_comparator,
                :manufacture_date,
                :manufacture_date_comparator,
                :in_service_date,
                :in_service_date_comparator,
                # Checkboxes
                :in_backlog,
                :purchased_new



  # Return the name of the form to display
  def form_view
    'asset_search_form'
  end
  # Return the name of the results table to display
  def results_view
    'asset_search_results_table'
  end

  def initialize(attributes = {})
    @klass = Object.const_get ASSET_BASE_CLASS_NAME
    super(attributes)
  end

  def to_s
    queries.to_sql
  end

  def cache_variable_name
    AssetsController::INDEX_KEY_LIST_VAR
  end

  private

  #---------------------------------------------------
  # Simple Equality Queries
  #---------------------------------------------------

  def estimated_condition_type_conditions
    if estimated_condition_type_id.blank?
      clean_estimated_condition_type_ids = remove_blanks(estimated_condition_type_ids)
      @klass.where(estimated_condition_type_id: clean_estimated_condition_type_ids) unless clean_estimated_condition_type_ids.empty?
    else
      @klass.where(estimated_condition_type_id: estimated_condition_type_id)
    end
  end

  def reported_condition_type_conditions
    if reported_condition_type_id.blank?
      clean_reported_condition_type_ids = remove_blanks(reported_condition_type_ids)
      @klass.where(reported_condition_type_id: clean_reported_condition_type_ids) unless clean_reported_condition_type_ids.empty?
    else
      @klass.where(reported_condition_type_id: reported_condition_type_id)
    end
  end

  def manufacturer_conditions
    if manufacturer_id.blank?
      clean_manufacturer_ids = remove_blanks(manufacturer_ids)
      @klass.where(manufacturer_id: clean_manufacturer_ids) unless clean_manufacturer_ids.empty?
    else
      @klass.where(manufacturer_id: manufacturer_id)
    end
  end

  def district_type_conditions
    @klass.where(district_id: district_id) unless district_id.blank?
  end

  def asset_type_conditions
    if asset_type_id.blank?
      clean_asset_type_ids = remove_blanks(asset_type_ids)
      @klass.where(asset_type_id: clean_asset_type_ids) unless clean_asset_type_ids.empty?
    else
      @klass.where(asset_type_id: asset_type_id)
    end
  end

  def asset_subtype_conditions
    if asset_subtype_id.blank?
      clean_asset_subtype_ids = remove_blanks(asset_subtype_ids)
      @klass.where(asset_subtype_id: clean_asset_subtype_ids) unless clean_asset_subtype_ids.empty?
    else
      @klass.where(asset_subtype_id: asset_subtype_id)
    end
  end

  def location_id_conditions
    @klass.where(parent_id: parent_id) unless parent_id.blank?
  end

  def vendor_conditions
    if vendor_id.blank?
      clean_vendor_ids = remove_blanks(vendor_ids)
      @klass.where(vendor_id: clean_vendor_ids) unless clean_vendor_ids.empty?
    else
      @klass.where(vendor_id: vendor_id)
    end
  end

  def service_status_type_conditions
    if service_status_type_id.blank?
      clean_service_status_type_ids = remove_blanks(service_status_type_ids)
      @klass.where(service_status_type: clean_service_status_type_ids) unless clean_service_status_type_ids.empty?
    else
      @klass.where(service_status_type: service_status_type_id)
    end
  end

  #---------------------------------------------------
  # Comparator Queries
  #---------------------------------------------------
  def manufacture_year_conditions
    unless manufacture_year.blank?
      case manufacture_year_comparator
      when "-1" # Before Year X
        @klass.where("manufacture_year < ?", manufacture_year)
      when "0" # During Year X
        @klass.where("manufacture_year = ?", manufacture_year)
      when "1" # After Year X
        @klass.where("manufacture_year > ?", manufacture_year)
      end
    end
  end

  def scheduled_replacement_year_conditions
    unless scheduled_replacement_year.blank?
      case scheduled_replacement_year_comparator
      when "-1" # Before Year X
        @klass.where("scheduled_replacement_year < ?", scheduled_replacement_year)
      when "0" # During Year X
        @klass.where("scheduled_replacement_year = ?", scheduled_replacement_year)
      when "1" # After Year X
        @klass.where("scheduled_replacement_year > ?", scheduled_replacement_year)
{'fraction_non_alphanumeric': 0.09152785240909905, 'fraction_numerical': 0.0010746910263299302, 'mean_word_length': 2.562041467304625, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '2464513', 'n_tokens_mistral': 3324, 'n_tokens_neox': 3196, 'n_words': 582}