<commit_before>class ArticlesController < ApplicationController
  before_action :find_article, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show, :history, :followers]

  # TODO: This method is currently very complex and needs to be simplified
  # The first step is identifying all the scenarios that it currently covers
  # 1. If the action is called with a state_id, then the index should return
  #    articles selected within the state.
  # 2. If there is a "query" parameter present, then the index should return
  #    a paginated result of the full text search, filtered by state
  # 3. There are "by_state" filters that impact what's returned.
  # All of theses individual queries in here should be turned into scopes 
  # and then called safely
 
  def index
  	@articles = Article.by_state(params[:state_id]).search(params[:query], page: params[:page], per_page: 12) if params[:query].present? && params[:state_id].present?
  	@articles = Article.by_state(params[:state_id]) if !params[:query].present? && params[:state_id].present?
  	@articles = Article.search(params[:query], page: params[:page], per_page: 12) if params[:query].present? && !params[:state_id].present?
  	@articles = Article.all.order('date DESC').page(params[:page]).per(12)
  end

  def new
    @article = current_user.articles.build
  end

  def show
    @article = Article.friendly.find(params[:id])
    @officers = @article.officers.all
    @commentable = @article
    @comments = @commentable.comments
    @comment = Comment.new
    @subjects = @article.subjects

    # Check to make sure all required elements are here<commit_msg>Restored searching by state; #313<commit_after>class ArticlesController < ApplicationController
  before_action :find_article, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show, :history, :followers]

  # TODO: This method is currently very complex and needs to be simplified
  # The first step is identifying all the scenarios that it currently covers
  # 1. If the action is called with a state_id, then the index should return
  #    articles selected within the state.
  # 2. If there is a "query" parameter present, then the index should return
  #    a paginated result of the full text search, filtered by state
  # 3. There are "by_state" filters that impact what's returned.
  # All of theses individual queries in here should be turned into scopes 
  # and then called safely
 
  def index
  	@articles = Article.by_state(params[:state_id]).search(params[:query], page: params[:page], per_page: 12) if params[:query].present? && params[:state_id].present?
  	@articles = Article.by_state(params[:state_id]).order('date DESC').page(params[:page]).per(12) if !params[:query].present? && params[:state_id].present?
  	@articles = Article.search(params[:query], page: params[:page], per_page: 12) if params[:query].present? && !params[:state_id].present?
  	@articles = Article.all.order('date DESC').page(params[:page]).per(12)
  end

  def new
    @article = current_user.articles.build
  end

  def show
    @article = Article.friendly.find(params[:id])
    @officers = @article.officers.all
    @commentable = @article
    @comments = @commentable.comments
    @comment = Comment.new
    @subjects = @article.subjects

    # Check to make sure all required elements are here
{'fraction_non_alphanumeric': 0.11290796824463394, 'fraction_numerical': 0.006762716847985887, 'mean_word_length': 4.46067415730337, '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': '1351811', 'n_tokens_mistral': 1023, 'n_tokens_neox': 965, 'n_words': 336}