<commit_before>class BookmarksController < ApplicationController
  include Pagy::Backend

  before_action :require_login
  before_action :set_bookmark, only: %i(show edit update destroy)

  # GET /bookmarks
  # GET /bookmarks.json
  def index
    @pagy, @bookmarks = pagy(
      Bookmark.includes(:tags).order(created_at: :desc).all, items: 10
    )
  end

  # GET /bookmarks/1
  # GET /bookmarks/1.json
  def show
  end

  # GET /bookmarks/new
  def new
    @bookmark = Bookmark.new
  end

  # GET /bookmarks/1/edit
  def edit
  end

  # POST /bookmarks
  # POST /bookmarks.json
  # rubocop:disable Metrics/MethodLength
  def create
    @bookmark = Bookmark.new(bookmark_params)

    respond_to do |format|
      if @bookmark.save
        format.html do
          redirect_to @bookmark, notice: t('.success')
        end

        format.json { render :show, status: :created, location: @bookmark }
      else
        format.html { render :new }
        format.json do
          render json: @bookmark.errors, status: :unprocessable_entity
        end
      end
    end
  end
  # rubocop:enable Metrics/MethodLength

  # PATCH/PUT /bookmarks/1
  # PATCH/PUT /bookmarks/1.json
  # rubocop:disable Metrics/MethodLength
  def update
    respond_to do |format|
      if @bookmark.update(bookmark_params)
        format.html { redirect_to @bookmark, notice: t('.success') }
        format.json { render :show, status: :ok, location: @bookmark }
      else
        format.html { render :edit }
        format.json do
          render json: @bookmark.errors, status: :unprocessable_entity
        end
      end
    end
  end
  # rubocop:enable Metrics/MethodLength

  # DELETE /bookmarks/1
  # DELETE /bookmarks/1.json
  def destroy
    @bookmark.destroy
    respond_to do |format|
      format.html do
        redirect_to(
          bookmarks_url,
          notice: t('.success'),
        )
      end
      format.json { head :no_content }
    end
  end

  def search
    @pagy, @bookmarks = pagy(
      Bookmark.includes(:tags)
              .where(tags: { name: params[:q].split(',') })
              .order(created_at: :desc).all, items: 10
            )

    render :index
  end
<commit_msg>Strip whitespace from search query tags<commit_after>class BookmarksController < ApplicationController
  include Pagy::Backend

  before_action :require_login
  before_action :set_bookmark, only: %i(show edit update destroy)

  # GET /bookmarks
  # GET /bookmarks.json
  def index
    @pagy, @bookmarks = pagy(
      Bookmark.includes(:tags).order(created_at: :desc).all, items: 10
    )
  end

  # GET /bookmarks/1
  # GET /bookmarks/1.json
  def show
  end

  # GET /bookmarks/new
  def new
    @bookmark = Bookmark.new
  end

  # GET /bookmarks/1/edit
  def edit
  end

  # POST /bookmarks
  # POST /bookmarks.json
  # rubocop:disable Metrics/MethodLength
  def create
    @bookmark = Bookmark.new(bookmark_params)

    respond_to do |format|
      if @bookmark.save
        format.html do
          redirect_to @bookmark, notice: t('.success')
        end

        format.json { render :show, status: :created, location: @bookmark }
      else
        format.html { render :new }
        format.json do
          render json: @bookmark.errors, status: :unprocessable_entity
        end
      end
    end
  end
  # rubocop:enable Metrics/MethodLength

  # PATCH/PUT /bookmarks/1
  # PATCH/PUT /bookmarks/1.json
  # rubocop:disable Metrics/MethodLength
  def update
    respond_to do |format|
      if @bookmark.update(bookmark_params)
        format.html { redirect_to @bookmark, notice: t('.success') }
        format.json { render :show, status: :ok, location: @bookmark }
      else
        format.html { render :edit }
        format.json do
          render json: @bookmark.errors, status: :unprocessable_entity
        end
      end
    end
  end
  # rubocop:enable Metrics/MethodLength

  # DELETE /bookmarks/1
  # DELETE /bookmarks/1.json
  def destroy
    @bookmark.destroy
    respond_to do |format|
      format.html do
        redirect_to(
          bookmarks_url,
          notice: t('.success'),
        )
      end
      format.json { head :no_content }
    end
  end

  def search
    @pagy, @bookmarks = pagy(
      Bookmark.includes(:tags)
              .where(tags: { name: params[:q].split(',').map(&:strip) })
              .order(created_at: :desc).all, items: 10
            )

    render :index
  end

{'fraction_non_alphanumeric': 0.09938872537921667, 'fraction_numerical': 0.00498075616934571, 'mean_word_length': 2.3044128646222886, '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': '808436', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1406, 'n_words': 351}