<commit_before>class Species::Search

  # Constructs a query to retrieve taxon concepts based on user defined
  # parameters
  #
  # @param [Hash] a hash of search params and their values
  def initialize(options)
    @id = 1
    initialize_params(options)
    initialize_query
  end

  def initialize_params(options)
    options = Species::SearchParams.sanitize(options)
    options.keys.each { |k| instance_variable_set("@#{k}", options[k]) }
    @scientific_name = @taxon_concept_query
  end

  def initialize_query
    @taxon_concepts_rel = MTaxonConcept.taxonomic_layout.
      where(:rank_name => @ranks)

    @taxon_concepts_rel = if @taxonomy == :cms
      @taxon_concepts_rel.by_cms_taxonomy
    else
      @taxon_concepts_rel.by_cites_eu_taxonomy
    end

    if !@geo_entities.empty? && @geo_entity_scope == :cites
      @taxon_concepts_rel = MTaxonConceptFilterByAppendixPopulationQuery.new(
        @taxon_concepts_rel, ['I', 'II', 'III'], @geo_entities
      ).relation('CITES')
    elsif !@geo_entities.empty? && @geo_entity_scope == :eu
      @taxon_concepts_rel = MTaxonConceptFilterByAppendixPopulationQuery.new(
        @taxon_concepts_rel, ['A', 'B', 'C', 'D'], @geo_entities
      ).relation('EU')
    elsif !@geo_entities.empty? && @geo_entity_scope == :occurrences
      @taxon_concepts_rel = MTaxonConceptFilterByAppendixPopulationQuery.new(
        @taxon_concepts_rel, [], @geo_entities
      ).relation
    end

    unless @scientific_name.blank?
      @taxon_concepts_rel = @taxon_concepts_rel.
        by_name(@scientific_name, {:synonyms => true, :subspecies => true, :common_names => false}).
        where(:name_status => 'A').
        select(<<-SQL
                taxon_concepts_mview.*,
                ARRAY(
                  SELECT * FROM UNNEST(synonyms_ary) name WHERE name ILIKE '#{@scientific_name}%'
                ) AS synonyms_ary
               SQL
        )
    end
  end

  def results
    @taxon_concepts_rel
  end

end
<commit_msg>Name_status should be filtered even if there's no scientific_name provided<commit_after>class Species::Search

  # Constructs a query to retrieve taxon concepts based on user defined
  # parameters
  #
  # @param [Hash] a hash of search params and their values
  def initialize(options)
    @id = 1
    initialize_params(options)
    initialize_query
  end

  def initialize_params(options)
    options = Species::SearchParams.sanitize(options)
    options.keys.each { |k| instance_variable_set("@#{k}", options[k]) }
    @scientific_name = @taxon_concept_query
  end

  def initialize_query
    @taxon_concepts_rel = MTaxonConcept.taxonomic_layout.
      where(:rank_name => @ranks, :name_status => 'A')

    @taxon_concepts_rel = if @taxonomy == :cms
      @taxon_concepts_rel.by_cms_taxonomy
    else
      @taxon_concepts_rel.by_cites_eu_taxonomy
    end

    if !@geo_entities.empty? && @geo_entity_scope == :cites
      @taxon_concepts_rel = MTaxonConceptFilterByAppendixPopulationQuery.new(
        @taxon_concepts_rel, ['I', 'II', 'III'], @geo_entities
      ).relation('CITES')
    elsif !@geo_entities.empty? && @geo_entity_scope == :eu
      @taxon_concepts_rel = MTaxonConceptFilterByAppendixPopulationQuery.new(
        @taxon_concepts_rel, ['A', 'B', 'C', 'D'], @geo_entities
      ).relation('EU')
    elsif !@geo_entities.empty? && @geo_entity_scope == :occurrences
      @taxon_concepts_rel = MTaxonConceptFilterByAppendixPopulationQuery.new(
        @taxon_concepts_rel, [], @geo_entities
      ).relation
    end

    unless @scientific_name.blank?
      @taxon_concepts_rel = @taxon_concepts_rel.
        by_name(@scientific_name, {:synonyms => true, :subspecies => true, :common_names => false}).
        select(<<-SQL
                taxon_concepts_mview.*,
                ARRAY(
                  SELECT * FROM UNNEST(synonyms_ary) name WHERE name ILIKE '#{@scientific_name}%'
                ) AS synonyms_ary
               SQL
        )
    end
  end

  def results
    @taxon_concepts_rel
  end

end

{'fraction_non_alphanumeric': 0.1059850374064838, 'fraction_numerical': 0.0004987531172069825, 'mean_word_length': 3.217665615141956, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '1655744', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1297, 'n_words': 259}