enju_search_log 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +45 -0
  4. data/app/controllers/search_histories_controller.rb +48 -0
  5. data/app/helpers/search_histories_helper.rb +32 -0
  6. data/app/models/search_history.rb +42 -0
  7. data/app/views/search_histories/edit.html.erb +74 -0
  8. data/app/views/search_histories/index.html.erb +56 -0
  9. data/app/views/search_histories/new.html.erb +10 -0
  10. data/app/views/search_histories/show.html.erb +73 -0
  11. data/config/locales/translation_en.yml +31 -0
  12. data/config/locales/translation_ja.yml +31 -0
  13. data/config/routes.rb +3 -0
  14. data/db/migrate/090_create_search_histories.rb +31 -0
  15. data/db/migrate/20100623173800_rename_search_history_version_to_sru_version.rb +9 -0
  16. data/lib/enju_search_log.rb +16 -0
  17. data/lib/enju_search_log/engine.rb +8 -0
  18. data/lib/enju_search_log/version.rb +3 -0
  19. data/lib/tasks/enju_search_log_tasks.rake +4 -0
  20. data/spec/controllers/search_histories_controller_spec.rb +303 -0
  21. data/spec/dummy/Rakefile +7 -0
  22. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  23. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +62 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/models/ability.rb +20 -0
  27. data/spec/dummy/app/models/role.rb +5 -0
  28. data/spec/dummy/app/models/user.rb +27 -0
  29. data/spec/dummy/app/models/user_has_role.rb +4 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/app/views/page/403.html.erb +9 -0
  32. data/spec/dummy/app/views/page/403.xml.erb +4 -0
  33. data/spec/dummy/app/views/page/404.html.erb +9 -0
  34. data/spec/dummy/app/views/page/404.xml.erb +4 -0
  35. data/spec/dummy/config.ru +4 -0
  36. data/spec/dummy/config/application.rb +45 -0
  37. data/spec/dummy/config/boot.rb +10 -0
  38. data/spec/dummy/config/database.yml +25 -0
  39. data/spec/dummy/config/environment.rb +5 -0
  40. data/spec/dummy/config/environments/development.rb +30 -0
  41. data/spec/dummy/config/environments/production.rb +60 -0
  42. data/spec/dummy/config/environments/test.rb +39 -0
  43. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/dummy/config/initializers/devise.rb +209 -0
  45. data/spec/dummy/config/initializers/inflections.rb +10 -0
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  47. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  48. data/spec/dummy/config/initializers/session_store.rb +8 -0
  49. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/spec/dummy/config/locales/en.yml +5 -0
  51. data/spec/dummy/config/routes.rb +60 -0
  52. data/spec/dummy/db/migrate/20111201121844_create_roles.rb +12 -0
  53. data/spec/dummy/db/migrate/20111201155456_create_users.rb +13 -0
  54. data/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb +31 -0
  55. data/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb +10 -0
  56. data/spec/dummy/db/schema.rb +81 -0
  57. data/spec/dummy/db/test.sqlite3 +0 -0
  58. data/spec/dummy/log/development.log +0 -0
  59. data/spec/dummy/log/test.log +1737 -0
  60. data/spec/dummy/public/404.html +26 -0
  61. data/spec/dummy/public/422.html +26 -0
  62. data/spec/dummy/public/500.html +26 -0
  63. data/spec/dummy/public/favicon.ico +0 -0
  64. data/spec/dummy/script/rails +6 -0
  65. data/spec/fixtures/roles.yml +21 -0
  66. data/spec/fixtures/search_histories.yml +90 -0
  67. data/spec/fixtures/user_has_roles.yml +41 -0
  68. data/spec/fixtures/users.yml +69 -0
  69. data/spec/spec_helper.rb +33 -0
  70. data/spec/support/controller_macros.rb +48 -0
  71. data/spec/support/devise.rb +4 -0
  72. metadata +245 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = EnjuSearchLog
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'EnjuPurchaseRequest'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+ require 'rspec/core'
39
+ require 'rspec/core/rake_task'
40
+
41
+ RSpec::Core::RakeTask.new(:spec) do |spec|
42
+ spec.pattern = FileList['spec/**/*_spec.rb']
43
+ end
44
+
45
+ task :default => :spec
@@ -0,0 +1,48 @@
1
+ class SearchHistoriesController < ApplicationController
2
+ # index, show以外は外部からは呼び出されないはず
3
+ load_and_authorize_resource
4
+
5
+ # GET /search_histories
6
+ # GET /search_histories.json
7
+ def index
8
+ if params[:mode] == 'not_found'
9
+ if current_user.has_role?('Administrator')
10
+ @search_histories = SearchHistory.not_found.order('created_at DESC').page(params[:page])
11
+ else
12
+ @search_histories = current_user.search_histories.not_found.order('created_at DESC').page(params[:page])
13
+ end
14
+ else
15
+ if current_user.has_role?('Administrator')
16
+ @search_histories = SearchHistory.order('created_at DESC').page(params[:page])
17
+ else
18
+ @search_histories = current_user.search_histories.order('created_at DESC').page(params[:page])
19
+ end
20
+ end
21
+
22
+ respond_to do |format|
23
+ format.html # index.rhtml
24
+ format.json { render :json => @search_histories.to_json }
25
+ end
26
+ end
27
+
28
+ # GET /search_histories/1
29
+ # GET /search_histories/1.json
30
+ def show
31
+ respond_to do |format|
32
+ format.html # show.rhtml
33
+ format.json { render :json => @search_history.to_json }
34
+ end
35
+ end
36
+
37
+ # DELETE /search_histories/1
38
+ # DELETE /search_histories/1.json
39
+ def destroy
40
+ @search_history.destroy
41
+
42
+ respond_to do |format|
43
+ #format.html { redirect_to user_search_histories_url(@user) }
44
+ format.html { redirect_to search_histories_url }
45
+ format.json { head :ok }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ module SearchHistoriesHelper
2
+ def reverse_tag_cloud(query_and_numbers)
3
+ return nil if query_and_numbers.nil?
4
+ # TODO: add options to specify different limits and sorts
5
+ #tags = Tag.all(:limit => 100, :order => 'taggings_count DESC').sort_by(&:name)
6
+
7
+ # TODO: add option to specify which classes you want and overide this if you want?
8
+ classes = %w(popular v-popular vv-popular vvv-popular vvvv-popular)
9
+
10
+ max, min = 0, 0
11
+ query_and_numbers.each do |query|
12
+ #if options[:max] or options[:min]
13
+ # max = options[:max].to_i
14
+ # min = options[:min].to_i
15
+ #end
16
+ max = query[1] if query[1].to_i > max
17
+ min = query[1] if query[1].to_i < min
18
+ end
19
+ divisor = ((max - min).div(classes.size)) + 1
20
+
21
+ html = %(<div class="hTagcloud">\n)
22
+ html << %( <ul class="popularity">\n)
23
+ query_and_numbers.each do |query|
24
+ html << %( <li>)
25
+ html << link_to(h(query[0]), manifestations_url(:query => query[0]), :class => classes[(query[1] - min).div(divisor)])
26
+ html << %( </li>\n) # FIXME: IEのために文末の空白を入れている
27
+ end
28
+ html << %( </ul>\n)
29
+ html << %(</div>\n)
30
+ html.html_safe
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ class SearchHistory < ActiveRecord::Base
2
+ scope :not_found, where(:number_of_records => 0)
3
+
4
+ belongs_to :user
5
+ def self.per_page
6
+ 10
7
+ end
8
+
9
+ # http://d.hatena.ne.jp/rubyco/20070528
10
+ def self.not_found_query(number, duration = 1.year.ago)
11
+ 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
12
+ end
13
+ end
14
+
15
+ # == Schema Information
16
+ #
17
+ # Table name: search_histories
18
+ #
19
+ # id :integer not null, primary key
20
+ # user_id :integer
21
+ # operation :string(255) default("searchRetrieve")
22
+ # sru_version :float default(1.2)
23
+ # query :string(255)
24
+ # start_record :integer
25
+ # maximum_records :integer
26
+ # record_packing :string(255)
27
+ # record_schema :string(255)
28
+ # result_set_ttl :integer
29
+ # stylesheet :string(255)
30
+ # extra_request_data :string(255)
31
+ # number_of_records :integer default(0)
32
+ # result_set_id :string(255)
33
+ # result_set_idle_time :integer
34
+ # records :text
35
+ # next_record_position :integer
36
+ # diagnostics :text
37
+ # extra_response_data :text
38
+ # echoed_search_retrieve_request :text
39
+ # created_at :datetime
40
+ # updated_at :datetime
41
+ #
42
+
@@ -0,0 +1,74 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.editing', :model => t('activerecord.models.search_history')) -%></h1>
3
+ <div id="content_list">
4
+
5
+ <%= form_for(@search_history) do |f| -%>
6
+ <%= f.error_messages -%>
7
+ <div class="field">
8
+ <%= f.label :operation -%><br />
9
+ <%= f.text_field :operation -%>
10
+ </div>
11
+
12
+ <div class="field">
13
+ <%= f.label :version -%><br />
14
+ <%= f.text_field :version -%>
15
+ </div>
16
+
17
+ <div class="field">
18
+ <%= f.label :query -%><br />
19
+ <%= f.text_field :query -%>
20
+ </div>
21
+
22
+ <div class="field">
23
+ <%= f.label :start_record -%><br />
24
+ <%= f.text_field :start_record -%>
25
+ </div>
26
+
27
+ <div class="field">
28
+ <%= f.label :maximum_records -%><br />
29
+ <%= f.text_field :maximum_records -%>
30
+ </div>
31
+
32
+ <div class="field">
33
+ <%= f.label :record_packing -%><br />
34
+ <%= f.text_field :record_packing -%>
35
+ </div>
36
+
37
+ <div class="field">
38
+ <%= f.label :record_schema -%><br />
39
+ <%= f.text_field :record_schema -%>
40
+ </div>
41
+
42
+ <div class="field">
43
+ <%= f.label :result_set_ttl -%><br />
44
+ <%= f.text_field :result_set_ttl -%>
45
+ </div>
46
+
47
+ <div class="field">
48
+ <%= f.label :stylesheet -%><br />
49
+ <%= f.text_field :stylesheet -%>
50
+ </div>
51
+
52
+ <div class="field">
53
+ <%= f.label :extra_request_data -%><br />
54
+ <%= f.text_field :extra_request_data -%>
55
+ </div>
56
+
57
+ <div class="field">
58
+ <%= f.label t('activerecord.models.user') -%><br />
59
+ <%= f.text_field :user_id -%>
60
+ </div>
61
+
62
+ <div class="actions">
63
+ <%= f.submit %>
64
+ </div>
65
+ <%- end -%>
66
+ </div>
67
+ </div>
68
+
69
+ <div id="submenu" class="ui-corner-all">
70
+ <ul>
71
+ <li><%= link_to t('page.show'), user_search_history_path(@search_history.user, @search_history) -%></li>
72
+ <li><%= link_to t('page.back'), user_search_histories_path(@search_history.user) -%></li>
73
+ </ul>
74
+ </div>
@@ -0,0 +1,56 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.listing', :model => t('activerecord.models.search_history')) -%></h1>
3
+ <div id="content_list">
4
+ <% if current_user.try(:has_role?, 'Librarian') %>
5
+ <%- if params[:mode] == 'not_found' -%>
6
+ <%= reverse_tag_cloud(SearchHistory.not_found_query(2, 6.month.ago)) -%>
7
+ <p>
8
+ <%= link_to t('search_history.all_history'), search_histories_path -%>
9
+ </p>
10
+ <%- else -%>
11
+ <p>
12
+ <%= link_to t('search_history.failed_search'), search_histories_path(:mode => 'not_found') -%>
13
+ </p>
14
+ <%- end -%>
15
+ <% end %>
16
+
17
+ <table class="index">
18
+ <tr>
19
+ <th><%= t('activerecord.attributes.search_history.query') -%></th>
20
+ <th><%= t('activerecord.attributes.search_history.number_of_records') -%></th>
21
+ <%- unless params[:mode] == 'not_found' -%>
22
+ <th><%= t('activerecord.attributes.search_history.start_record') -%></th>
23
+ <%- end -%>
24
+ <th><%= t('search_history.searched_at') -%></th>
25
+ <th></th>
26
+ <th></th>
27
+ </tr>
28
+
29
+ <%- @search_histories.each_with_index do |search_history, i| -%>
30
+ <tr class="line<%= cycle("0", "1") -%>">
31
+ <td><%= link_to h(search_history.query), manifestations_path(:query => search_history.query) -%></td>
32
+ <td><%= search_history.number_of_records -%></td>
33
+ <%- unless params[:mode] == 'not_found' -%>
34
+ <td><%= search_history.start_record -%></td>
35
+ <%- end -%>
36
+ <td><%= l(search_history.created_at) -%></td>
37
+ <td>
38
+ <%- if can? :destroy, search_history -%>
39
+ <%= link_to t('page.show'), search_history -%>
40
+ <% end %>
41
+ </td>
42
+ <td>
43
+ <%- if can? :destroy, search_history -%>
44
+ <%= link_to t('page.destroy'), search_history, :confirm => t('page.are_you_sure'), :method => :delete -%>
45
+ <%- end -%>
46
+ </td>
47
+ </tr>
48
+ <%- end -%>
49
+ </table>
50
+
51
+ <%= will_paginate(@search_histories) -%>
52
+ </div>
53
+ </div>
54
+
55
+ <div id="submenu" class="ui-corner-all">
56
+ </div>
@@ -0,0 +1,10 @@
1
+ <h1 class="title"><%= t('page.new', :model => t('activerecord.models.search_history')) -%></h1>
2
+
3
+ <!--
4
+ <%= form_for(:search_history, :url => search_histories_path) do |f| -%>
5
+ <%= f.error_messages -%>
6
+
7
+ <%- end -%>
8
+ -->
9
+
10
+ <%= link_to t('page.back'), search_histories_path -%>
@@ -0,0 +1,73 @@
1
+ <div id="content_detail" class="ui-corner-all">
2
+ <h1 class="title"><%= t('page.showing', :model => t('activerecord.models.search_history')) -%></h1>
3
+ <div id="content_list">
4
+ <p id="notice"><%= notice %></p>
5
+
6
+ <p>
7
+ <strong>Operation:</strong>
8
+ <%= @search_history.operation -%>
9
+ </p>
10
+
11
+ <p>
12
+ <strong>Version:</strong>
13
+ <%= @search_history.sru_version -%>
14
+ </p>
15
+
16
+ <p>
17
+ <strong><%= t('activerecord.attributes.search_history.query') -%>:</strong>
18
+ <%= link_to @search_history.query, manifestations_path(:query => @search_history.query) -%>
19
+ </p>
20
+
21
+ <p>
22
+ <strong><%= t('activerecord.attributes.search_history.start_record') -%>:</strong>
23
+ <%= @search_history.start_record -%>
24
+ </p>
25
+
26
+ <p>
27
+ <strong><%= ('Maximum records') -%>:</strong>
28
+ <%= @search_history.maximum_records -%>
29
+ </p>
30
+
31
+ <p>
32
+ <strong>Record packing:</strong>
33
+ <%= @search_history.record_packing -%>
34
+ </p>
35
+
36
+ <p>
37
+ <strong>Record schema:</strong>
38
+ <%= @search_history.record_schema -%>
39
+ </p>
40
+
41
+ <p>
42
+ <strong>Result set ttl:</strong>
43
+ <%= @search_history.result_set_ttl -%>
44
+ </p>
45
+
46
+ <p>
47
+ <strong>Stylesheet:</strong>
48
+ <%= @search_history.stylesheet -%>
49
+ </p>
50
+
51
+ <p>
52
+ <strong>Extra request data:</strong>
53
+ <%= @search_history.extra_request_data -%>
54
+ </p>
55
+
56
+ <p>
57
+ <strong><%= t('page.created_at') -%>:</strong>
58
+ <%= l(@search_history.created_at) -%>
59
+ </p>
60
+
61
+ <p>
62
+ <strong><%= t('activerecord.models.user') -%>:</strong>
63
+ <%= @search_history.user.username if @search_history.user -%>
64
+ </p>
65
+
66
+ </div>
67
+ </div>
68
+
69
+ <div id="submenu" class="ui-corner-all">
70
+ <ul>
71
+ <li><%= back_to_index(flash[:page_info]) -%></li>
72
+ </ul>
73
+ </div>
@@ -0,0 +1,31 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ search_history: Search history
5
+
6
+ attributes:
7
+ user:
8
+ save_search_history: Save search history
9
+ search_history:
10
+ operation: Operation
11
+ version: Version
12
+ query: Query
13
+ start_record: Start record
14
+ maximum_records: Maximum records
15
+ record_packing: Record packing
16
+ record_schema: Record schema
17
+ result_set_ttl: Result set ttl
18
+ stylesheet: Stylesheet
19
+ extra_request_data: Extra request data
20
+ number_of_records: Number of records
21
+ result_set_idle_time: Result set idle time
22
+ records: Records
23
+ next_record_position: Next record position
24
+ diagnostics: Diagnostics
25
+ extra_response_data: Extra response data
26
+ echoed_search_retrieve_request: Echoed search retrieve request
27
+
28
+ search_history:
29
+ all_history: "All search history"
30
+ failed_search: "Failed searches"
31
+ searched_at: "Searched at"