<commit_before>class ItemsController < ApplicationController
  include ERB::Util
  include ApplicationHelper
  include FiltersHelper
  # GET /items
  # GET /items.json
  def index
    @filters = []
    @sources = []
    #@filters << Filter.new(:prop => "http://purl.org/rss/1.0/source", :value => tag)

    if params[:search] == nil
      #flash[:error] = "you need to create a search!"
      #redirect_to :back
      @search = Search.first
    else
      @search = Search.find(params[:search])
    end

    current_page = params[:page]
    current_page = 1 if current_page == nil
    current_page = Integer(current_page)
    per_page = 10
    @itemsNumber = @search.getItemsNumber
    #if itemsNumber > (10000 - per_page +1)
    #  itemsNumber = (10000 - per_page +1)
    #end

    @items = WillPaginate::Collection.create(current_page, per_page, @itemsNumber) do |pager|
      start = (current_page-1)*per_page # assuming current_page is 1 based.
      itemsTab = Item.all(@search,start,per_page)
      @sparqlRequest = itemsTab[:query]
      pager.replace(itemsTab[:result])
    end

    gonItemsFiltersUri = Array.new
    @items.each do |element|
      element.localURI = item_path(:id => element, :old => @filters)
      gonItemsFiltersUri << element.localURI
    end
    gon.gonItemsFiltersUri = gonItemsFiltersUri
    <commit_msg>add possibility to change the number of items per page<commit_after>class ItemsController < ApplicationController
  include ERB::Util
  include ApplicationHelper
  include FiltersHelper
  # GET /items
  # GET /items.json
  def index
    @filters = []
    @sources = []

    if params[:search] == nil
      @search = Search.first
    else
      @search = Search.find(params[:search])
    end

    if params[:per_page] != nil
      per_page = params[:per_page].to_i
    else
      per_page = 10
    end

    current_page = params[:page]
    current_page = 1 if current_page == nil
    current_page = Integer(current_page)

    @itemsNumber = @search.getItemsNumber
    #if itemsNumber > (10000 - per_page +1)
    #  itemsNumber = (10000 - per_page +1)
    #end

    @items = WillPaginate::Collection.create(current_page, per_page, @itemsNumber) do |pager|
      start = (current_page-1)*per_page # assuming current_page is 1 based.
      itemsTab = Item.all(@search,start,per_page)
      @sparqlRequest = itemsTab[:query]
      pager.replace(itemsTab[:result])
    end

    gonItemsFiltersUri = Array.new
    @items.each do |element|
      element.localURI = item_path(:id => element, :old => @filters)
      gonItemsFiltersUri << element.localURI
    end
    gon.gonItemsFiltersUri = gonItemsFiltersUri
    
{'fraction_non_alphanumeric': 0.10972379871358305, 'fraction_numerical': 0.01362088535754824, 'mean_word_length': 3.13125, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4619417', 'n_tokens_mistral': 855, 'n_tokens_neox': 820, 'n_words': 196}