<commit_before>class Api::V1::DocumentsController < ApplicationController

  def index
    if params[:taxon_concept_query].present?
      @species_search = Species::Search.new({
        visibility: :elibrary,
        taxon_concept_query: params[:taxon_concept_query]
      })
      params[:taxon_concepts_ids] = @species_search.ids.join(',')
    end
    @search = DocumentSearch.new(
      params.merge(show_private: !access_denied?, per_page: 100), 'public'
    )

    render :json => @search.cached_results,
      each_serializer: Species::DocumentSerializer,
      meta: {
        total: @search.cached_total_cnt,
        page: @search.page,
        per_page: @search.per_page
      }
  end

  def show
    @document = Document.find(params[:id])
    path_to_file = @document.filename.path;
    if access_denied? && !@document.is_public
      render :file => "#{Rails.root}/public/403.html",  :status => 403
    elsif !File.exists?(path_to_file)
      render :file => "#{Rails.root}/public/404.html",  :status => 404
    else
      send_file(
        path_to_file,
          :filename => File.basename(path_to_file),<commit_msg>Add documents cascading search logic to taxon documents tab<commit_after>class Api::V1::DocumentsController < ApplicationController

  def index
    if params[:taxon_concept_query].present?
      @species_search = Species::Search.new({
        visibility: :elibrary,
        taxon_concept_query: params[:taxon_concept_query]
      })
      params[:taxon_concepts_ids] = @species_search.ids.join(',')
    else
      if params[:taxon_concepts_ids].present?
        taxa = TaxonConcept.find(params[:taxon_concepts_ids])
        children_ids = taxa.map(&:children).map do
          |children| children.pluck(:id) if children.present?
        end.flatten.uniq.compact
        taxa_ids = taxa.map(&:id) + children_ids
        params[:taxon_concepts_ids] = taxa_ids
      end
    end
    @search = DocumentSearch.new(
      params.merge(show_private: !access_denied?, per_page: 100), 'public'
    )

    render :json => @search.cached_results,
      each_serializer: Species::DocumentSerializer,
      meta: {
        total: @search.cached_total_cnt,
        page: @search.page,
        per_page: @search.per_page
      }
  end

  def show
    @document = Document.find(params[:id])
    path_to_file = @document.filename.path;
    if access_denied? && !@document.is_public
      render :file => "#{Rails.root}/public/403.html",  :status => 403
    elsif !File.exists?(path_to_file)
      render :file => "#{Rails.root}/public/404.html",  :status => 404
    else
      send_file(
        path_to_file,
          :filename => File.basename(path_to_file),
{'fraction_non_alphanumeric': 0.12448598130841121, 'fraction_numerical': 0.011962616822429906, 'mean_word_length': 3.110599078341014, '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': '2971035', 'n_tokens_mistral': 905, 'n_tokens_neox': 850, 'n_words': 150}