<commit_before>class FactsController < ApplicationController
  layout "client"

  respond_to :json, :html

  before_filter :load_fact,
    only: [
      :show,
      :discussion_page_redirect,
      :destroy,
      :update,
      :opinion,
      :evidence_search,
      :share
      ]

  def show
    authorize! :show, Fact
    dead_fact = query(:'facts/get_dead', id: @fact.id.to_s)
    render json: dead_fact
  end

  def discussion_page_redirect
    redirect_to FactUrl.new(@fact).proxy_open_url, status: :moved_permanently
  end

  def create
    authorize! :create, Fact

    dead_fact = interactor(:'facts/create',
                           displaystring: params[:displaystring].to_s,
                           url: params[:url].to_s,
                           title: params[:site_title].to_s)

    render json: dead_fact
  end

  # TODO: This search is way to simple now, we need to make sure already
  # evidenced Factlinks are not shown in search results and therefore we need
  # to move this search to the evidence_controller, to make sure it's
  # type-specific
  def evidence_search
    authorize! :index, Fact
    search_for = params[:s]

    raise_404 if Fact.invalid(@fact)
    facts = interactor(:'search_evidence', keywords: search_for, fact_id: @fact.id)

    render json: facts
  end

  def recently_viewed
    @facts = interactor :"facts/recently_viewed"

    render json: @facts.map { |f| query(:'facts/get_dead', id: f.id.to_s) }
  end

  def share
    authorize! :share, @fact

    interactor :'facts/social_share', fact_id: @fact.id,
      message: params[:message], provider_names: params[:provider_names]

    render json: {}
  end

  private

  def load_fact
    fact_id = params[:fact_id] || params[:id]
    @fact = interactor(:'facts/get', id: fact_id) or raise_404
  end
end<commit_msg>fact_id is not used in routes anymore<commit_after>class FactsController < ApplicationController
  layout "client"

  respond_to :json, :html

  before_filter :load_fact,
    only: [
      :show,
      :discussion_page_redirect,
      :destroy,
      :update,
      :opinion,
      :evidence_search,
      :share
      ]

  def show
    authorize! :show, Fact
    dead_fact = query(:'facts/get_dead', id: @fact.id.to_s)
    render json: dead_fact
  end

  def discussion_page_redirect
    redirect_to FactUrl.new(@fact).proxy_open_url, status: :moved_permanently
  end

  def create
    authorize! :create, Fact

    dead_fact = interactor(:'facts/create',
                           displaystring: params[:displaystring].to_s,
                           url: params[:url].to_s,
                           title: params[:site_title].to_s)

    render json: dead_fact
  end

  # TODO: This search is way to simple now, we need to make sure already
  # evidenced Factlinks are not shown in search results and therefore we need
  # to move this search to the evidence_controller, to make sure it's
  # type-specific
  def evidence_search
    authorize! :index, Fact
    search_for = params[:s]

    raise_404 if Fact.invalid(@fact)
    facts = interactor(:'search_evidence', keywords: search_for, fact_id: @fact.id)

    render json: facts
  end

  def recently_viewed
    @facts = interactor :"facts/recently_viewed"

    render json: @facts.map { |f| query(:'facts/get_dead', id: f.id.to_s) }
  end

  def share
    authorize! :share, @fact

    interactor :'facts/social_share', fact_id: @fact.id,
      message: params[:message], provider_names: params[:provider_names]

    render json: {}
  end

  private

  def load_fact
    fact_id = params[:id]
    @fact = interactor(:'facts/get', id: fact_id) or raise_404
  end
end
{'fraction_non_alphanumeric': 0.09742041712403952, 'fraction_numerical': 0.003293084522502744, 'mean_word_length': 2.865323435843054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '398744', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1131, 'n_words': 316}