Sha256: 42c3fa26d419159efb391322ccd7a442ab19d74bbac375354e0cc00a3006253b

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

class SearchHistory < ActiveRecord::Base
  scope :not_found, -> { where(number_of_records: 0) }
  belongs_to :user

  paginates_per 10

  # http://d.hatena.ne.jp/rubyco/20070528
  def self.not_found_query(number, duration = 1.year.ago)
    self.not_found.where('created_at > ?', duration).all.collect(&:query).inject(Hash.new(0)){|r,e| r[e] += 1; r}.to_a.collect{|q| q if q[1] >= number.to_i}.compact
  end

  def self.remove_all_history(user)
    user.search_histories.update_all(user_id: nil)
  end
end

# == Schema Information
#
# Table name: search_histories
#
#  id                             :integer          not null, primary key
#  user_id                        :integer
#  operation                      :string           default("searchRetrieve")
#  sru_version                    :float            default(1.2)
#  query                          :string
#  start_record                   :integer
#  maximum_records                :integer
#  record_packing                 :string
#  record_schema                  :string
#  result_set_ttl                 :integer
#  stylesheet                     :string
#  extra_request_data             :string
#  number_of_records              :integer          default(0)
#  result_set_id                  :string
#  result_set_idle_time           :integer
#  records                        :text
#  next_record_position           :integer
#  diagnostics                    :text
#  extra_response_data            :text
#  echoed_search_retrieve_request :text
#  created_at                     :datetime
#  updated_at                     :datetime
#

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
enju_search_log-0.3.0.beta.1 app/models/search_history.rb
enju_search_log-0.2.0 app/models/search_history.rb
enju_search_log-0.2.0.beta.3 app/models/search_history.rb