<commit_before>class BooksController < ApplicationController
  def index
    @books = if !params[:search].blank? || params[:sort] || params[:sort_direction]
      unless params[:search].blank?
        included_tags, excluded_tags = ActsAsTaggableOn::TagList.from(params[:search]).partition { |t| t.gsub!(/^-/, ''); $& != '-' }

        results = Book
        results = results.tagged_with(excluded_tags, :exclude => true) unless excluded_tags.empty?
        results = results.tagged_with(included_tags) unless included_tags.empty?
        #results |= Book.where(included_tags.map { |t| "title LIKE #{ActiveRecord::Base.connection.quote "%#{t}%"}" }.join(" OR ")) unless included_tags.empty?
        results.order("#{params[:sort]} #{params[:sort_direction]}")
      end

      results
    else
      Book.all
    end
  end

  def show
    @book = Book.find(params[:id])
    @book.open
  end

  def update
    @book = Book.find(params[:id])
    if @book.update_attributes(params[:book])
      render :action => 'update_fields'
    else
      #boom
    end
  end

  def destroy
    @book = Book.find(params[:id])

    #if params[:delete]<commit_msg>Fix book sorting<commit_after>class BooksController < ApplicationController
  def index
    @books = if !params[:search].blank?
      unless params[:search].blank?
        included_tags, excluded_tags = ActsAsTaggableOn::TagList.from(params[:search]).partition { |t| t.gsub!(/^-/, ''); $& != '-' }

        results = Book
        results = results.tagged_with(excluded_tags, :exclude => true) unless excluded_tags.empty?
        results = results.tagged_with(included_tags) unless included_tags.empty?
        #results |= Book.where(included_tags.map { |t| "title LIKE #{ActiveRecord::Base.connection.quote "%#{t}%"}" }.join(" OR ")) unless included_tags.empty?
        results
      end

      results
    else
      Book.scoped
    end.order("#{params[:sort]} #{params[:sort_direction]}")
  end

  def show
    @book = Book.find(params[:id])
    @book.open
  end

  def update
    @book = Book.find(params[:id])
    if @book.update_attributes(params[:book])
      render :action => 'update_fields'
    else
      #boom
    end
  end

  def destroy
    @book = Book.find(params[:id])

    #if params[:delete]
{'fraction_non_alphanumeric': 0.14893617021276595, 'fraction_numerical': 0.0, 'mean_word_length': 3.2186915887850467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5306174', 'n_tokens_mistral': 716, 'n_tokens_neox': 688, 'n_words': 145}