enju_oai 0.0.4 → 0.1.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/enju_oai/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module EnjuOai
|
2
|
+
module Generators
|
3
|
+
class ViewsGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../../../../app/views', __FILE__)
|
5
|
+
|
6
|
+
def copy_files
|
7
|
+
directories = %w(
|
8
|
+
manifestations
|
9
|
+
)
|
10
|
+
|
11
|
+
directories.each do |dir|
|
12
|
+
directory dir, "app/views/#{dir}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,11 +1,154 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
class ApplicationController < ActionController::Base
|
2
3
|
protect_from_forgery
|
4
|
+
require_dependency 'language'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
rescue_from CanCan::AccessDenied, :with => :render_403
|
7
|
+
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
8
|
+
rescue_from Errno::ECONNREFUSED, :with => :render_500
|
9
|
+
rescue_from ActionView::MissingTemplate, :with => :render_404_invalid_format
|
10
|
+
#rescue_from ActionController::RoutingError, :with => :render_404
|
11
|
+
|
12
|
+
enju_biblio
|
13
|
+
enju_library
|
14
|
+
before_filter :get_library_group, :set_locale, :set_available_languages, :set_mobile_request
|
15
|
+
has_mobile_fu
|
16
|
+
before_filter :set_request_format
|
17
|
+
|
18
|
+
private
|
19
|
+
def after_sign_in_path_for(resource)
|
20
|
+
session[:locale] = nil
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_403
|
25
|
+
return if performed?
|
26
|
+
if user_signed_in?
|
27
|
+
respond_to do |format|
|
28
|
+
format.html {render :template => 'page/403', :status => 403}
|
29
|
+
format.mobile {render :template => 'page/403', :status => 403}
|
30
|
+
format.xml {render :template => 'page/403', :status => 403}
|
31
|
+
format.json { render :text => '{"error": "forbidden"}' }
|
32
|
+
end
|
33
|
+
else
|
34
|
+
respond_to do |format|
|
35
|
+
format.html {redirect_to new_user_session_url}
|
36
|
+
format.mobile {redirect_to new_user_session_url}
|
37
|
+
format.xml {render :template => 'page/403', :status => 403}
|
38
|
+
format.json { render :text => '{"error": "forbidden"}' }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_404
|
44
|
+
return if performed?
|
45
|
+
respond_to do |format|
|
46
|
+
format.html {render :template => 'page/404', :status => 404}
|
47
|
+
format.mobile {render :template => 'page/404', :status => 404}
|
48
|
+
format.xml {render :template => 'page/404', :status => 404}
|
49
|
+
format.json { render :text => '{"error": "not_found"}' }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def render_404_invalid_format
|
54
|
+
return if performed?
|
55
|
+
render :file => "#{Rails.root}/public/404.html"
|
56
|
+
end
|
57
|
+
|
58
|
+
def render_500
|
59
|
+
Rails.logger.fatal("please confirm that the Solr is running.")
|
60
|
+
return if performed?
|
61
|
+
#flash[:notice] = t('page.connection_failed')
|
62
|
+
respond_to do |format|
|
63
|
+
format.html {render :file => "#{Rails.root.to_s}/public/500.html", :layout => false, :status => 500}
|
64
|
+
format.mobile {render :file => "#{Rails.root.to_s}/public/500.html", :layout => false, :status => 500}
|
65
|
+
format.xml {render :template => 'page/500', :status => 500}
|
66
|
+
format.json { render :text => '{"error": "server_error"}' }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_locale
|
71
|
+
if params[:locale]
|
72
|
+
unless I18n.available_locales.include?(params[:locale].to_s.intern)
|
73
|
+
raise InvalidLocaleError
|
74
|
+
end
|
75
|
+
end
|
76
|
+
if user_signed_in?
|
77
|
+
locale = params[:locale] || session[:locale] || current_user.locale.try(:to_sym)
|
78
|
+
else
|
79
|
+
locale = params[:locale] || session[:locale]
|
80
|
+
end
|
81
|
+
if locale
|
82
|
+
I18n.locale = @locale = session[:locale] = locale.to_sym
|
83
|
+
else
|
84
|
+
I18n.locale = @locale = session[:locale] = I18n.default_locale
|
85
|
+
end
|
86
|
+
rescue InvalidLocaleError
|
87
|
+
@locale = I18n.default_locale
|
88
|
+
end
|
89
|
+
|
90
|
+
def default_url_options(options={})
|
91
|
+
{:locale => nil}
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_available_languages
|
95
|
+
if Rails.env == 'production'
|
96
|
+
@available_languages = Rails.cache.fetch('available_languages'){
|
97
|
+
Language.where(:iso_639_1 => I18n.available_locales.map{|l| l.to_s}).select([:id, :iso_639_1, :name, :native_name, :display_name, :position]).all
|
98
|
+
}
|
99
|
+
else
|
100
|
+
@available_languages = Language.where(:iso_639_1 => I18n.available_locales.map{|l| l.to_s})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def reset_params_session
|
6
105
|
session[:params] = nil
|
7
|
-
|
8
|
-
|
106
|
+
end
|
107
|
+
|
108
|
+
def not_found
|
109
|
+
raise ActiveRecord::RecordNotFound
|
110
|
+
end
|
111
|
+
|
112
|
+
def access_denied
|
113
|
+
raise CanCan::AccessDenied
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_user
|
117
|
+
@user = User.where(:username => params[:user_id]).first if params[:user_id]
|
118
|
+
#authorize! :show, @user if @user
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_user_group
|
122
|
+
@user_group = UserGroup.find(params[:user_group_id]) if params[:user_group_id]
|
123
|
+
end
|
124
|
+
|
125
|
+
def convert_charset
|
126
|
+
case params[:format]
|
127
|
+
when 'csv'
|
128
|
+
return unless configatron.csv_charset_conversion
|
129
|
+
# TODO: 他の言語
|
130
|
+
if @locale.to_sym == :ja
|
131
|
+
headers["Content-Type"] = "text/csv; charset=Shift_JIS"
|
132
|
+
response.body = NKF::nkf('-Ws', response.body)
|
133
|
+
end
|
134
|
+
when 'xml'
|
135
|
+
if @locale.to_sym == :ja
|
136
|
+
headers["Content-Type"] = "application/xml; charset=Shift_JIS"
|
137
|
+
response.body = NKF::nkf('-Ws', response.body)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def store_page
|
143
|
+
if request.get? and request.format.try(:html?) and !request.xhr?
|
144
|
+
flash[:page] = params[:page] if params[:page].to_i > 0
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def store_location
|
149
|
+
if request.get? and request.format.try(:html?) and !request.xhr?
|
150
|
+
session[:user_return_to] = request.fullpath
|
151
|
+
end
|
9
152
|
end
|
10
153
|
|
11
154
|
def set_role_query(user, search)
|
@@ -62,15 +205,68 @@ class ApplicationController < ActionController::Base
|
|
62
205
|
return search
|
63
206
|
end
|
64
207
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
208
|
+
def solr_commit
|
209
|
+
Sunspot.commit
|
210
|
+
end
|
211
|
+
|
212
|
+
def get_version
|
213
|
+
@version = params[:version_id].to_i if params[:version_id]
|
214
|
+
@version = nil if @version == 0
|
215
|
+
end
|
216
|
+
|
217
|
+
def clear_search_sessions
|
218
|
+
session[:query] = nil
|
219
|
+
session[:params] = nil
|
220
|
+
session[:search_params] = nil
|
221
|
+
session[:manifestation_ids] = nil
|
222
|
+
end
|
223
|
+
|
224
|
+
def api_request?
|
225
|
+
true unless params[:format].nil? or params[:format] == 'html'
|
226
|
+
end
|
227
|
+
|
228
|
+
def current_ability
|
229
|
+
@current_ability ||= Ability.new(current_user, request.remote_ip.split('%')[0])
|
230
|
+
end
|
231
|
+
|
232
|
+
def get_top_page_content
|
233
|
+
if defined?(EnjuNews)
|
234
|
+
@news_feeds = Rails.cache.fetch('news_feed_all'){NewsFeed.all}
|
235
|
+
@news_posts = NewsPost.limit(3)
|
68
236
|
end
|
237
|
+
@libraries = Library.real
|
69
238
|
end
|
70
239
|
|
71
|
-
def
|
72
|
-
if
|
73
|
-
|
240
|
+
def set_mobile_request
|
241
|
+
if params[:mobile_view]
|
242
|
+
if params[:mobile_view] == 'false'
|
243
|
+
session[:mobile_view] = false
|
244
|
+
else
|
245
|
+
session[:mobile_view] = true
|
246
|
+
end
|
247
|
+
else
|
248
|
+
if is_mobile_device?
|
249
|
+
session[:mobile_view] = true
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def set_request_format
|
255
|
+
if session[:mobile_view]
|
256
|
+
request.format = :mobile if is_mobile_device?
|
74
257
|
end
|
75
258
|
end
|
259
|
+
|
260
|
+
def move_position(resource, direction, redirect = true)
|
261
|
+
if ['higher', 'lower'].include?(direction)
|
262
|
+
resource.send("move_#{direction}")
|
263
|
+
if redirect
|
264
|
+
redirect_to url_for(:controller => resource.class.to_s.pluralize.underscore)
|
265
|
+
return
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
class InvalidLocaleError < StandardError
|
76
272
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enju_oai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kosuke Tanabe
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -32,17 +32,17 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 0.1.0.pre
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 0.1.0.pre
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: mobile-fu
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,33 +112,33 @@ dependencies:
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.1.0.pre
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 0.1.0.pre
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: enju_library
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
133
|
+
version: 0.1.0.pre
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|
139
|
-
- -
|
139
|
+
- - ~>
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
141
|
+
version: 0.1.0.pre
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
143
|
name: enju_manifestation_viewer
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/enju_oai/oai_model.rb
|
191
191
|
- lib/enju_oai/version.rb
|
192
192
|
- lib/enju_oai.rb
|
193
|
+
- lib/generators/enju_oai/views_generator.rb
|
193
194
|
- lib/tasks/enju_oai_tasks.rake
|
194
195
|
- MIT-LICENSE
|
195
196
|
- Rakefile
|
@@ -198,7 +199,6 @@ files:
|
|
198
199
|
- spec/dummy/app/assets/javascripts/application.js
|
199
200
|
- spec/dummy/app/assets/stylesheets/application.css
|
200
201
|
- spec/dummy/app/controllers/application_controller.rb
|
201
|
-
- spec/dummy/app/controllers/manifestations_controller.rb
|
202
202
|
- spec/dummy/app/helpers/application_helper.rb
|
203
203
|
- spec/dummy/app/models/ability.rb
|
204
204
|
- spec/dummy/app/models/role.rb
|
@@ -449,9 +449,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
449
449
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
450
450
|
none: false
|
451
451
|
requirements:
|
452
|
-
- - ! '
|
452
|
+
- - ! '>'
|
453
453
|
- !ruby/object:Gem::Version
|
454
|
-
version:
|
454
|
+
version: 1.3.1
|
455
455
|
requirements: []
|
456
456
|
rubyforge_project:
|
457
457
|
rubygems_version: 1.8.23
|
@@ -463,7 +463,6 @@ test_files:
|
|
463
463
|
- spec/dummy/app/assets/javascripts/application.js
|
464
464
|
- spec/dummy/app/assets/stylesheets/application.css
|
465
465
|
- spec/dummy/app/controllers/application_controller.rb
|
466
|
-
- spec/dummy/app/controllers/manifestations_controller.rb
|
467
466
|
- spec/dummy/app/helpers/application_helper.rb
|
468
467
|
- spec/dummy/app/models/ability.rb
|
469
468
|
- spec/dummy/app/models/role.rb
|
@@ -1,519 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
class ManifestationsController < ApplicationController
|
3
|
-
load_and_authorize_resource :except => :index
|
4
|
-
authorize_resource :only => :index
|
5
|
-
include EnjuOai::OaiController if defined?(EnjuOai)
|
6
|
-
include EnjuSearchLog if defined?(EnjuSearchLog)
|
7
|
-
|
8
|
-
# GET /manifestations
|
9
|
-
# GET /manifestations.json
|
10
|
-
def index
|
11
|
-
mode = params[:mode]
|
12
|
-
if mode == 'add'
|
13
|
-
unless current_user.try(:has_role?, 'Librarian')
|
14
|
-
access_denied; return
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
@seconds = Benchmark.realtime do
|
19
|
-
if defined?(EnjuOai)
|
20
|
-
@oai = check_oai_params(params)
|
21
|
-
next if @oai[:need_not_to_search]
|
22
|
-
if params[:format] == 'oai'
|
23
|
-
oai_search = true
|
24
|
-
from_and_until_times = set_from_and_until(Manifestation, params[:from], params[:until])
|
25
|
-
from_time = @from_time = from_and_until_times[:from]
|
26
|
-
until_time = @until_time = from_and_until_times[:until]
|
27
|
-
# OAI-PMHのデフォルトの件数
|
28
|
-
per_page = 200
|
29
|
-
if params[:resumptionToken]
|
30
|
-
current_token = get_resumption_token(params[:resumptionToken])
|
31
|
-
if current_token
|
32
|
-
page = (current_token[:cursor].to_i + per_page).div(per_page) + 1
|
33
|
-
else
|
34
|
-
@oai[:errors] << 'badResumptionToken'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
page ||= 1
|
38
|
-
|
39
|
-
if params[:verb] == 'GetRecord' and params[:identifier]
|
40
|
-
begin
|
41
|
-
@manifestation = Manifestation.find_by_oai_identifier(params[:identifier])
|
42
|
-
rescue ActiveRecord::RecordNotFound
|
43
|
-
@oai[:errors] << "idDoesNotExist"
|
44
|
-
render :formats => :oai, :layout => false
|
45
|
-
return
|
46
|
-
end
|
47
|
-
render :template => 'manifestations/show', :formats => :oai, :layout => false
|
48
|
-
return
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
set_reservable if defined?(EnjuCirculation)
|
54
|
-
|
55
|
-
manifestations, sort, @count = {}, {}, {}
|
56
|
-
query = ""
|
57
|
-
|
58
|
-
if params[:format] == 'csv'
|
59
|
-
per_page = 65534
|
60
|
-
end
|
61
|
-
|
62
|
-
if params[:format] == 'sru'
|
63
|
-
if params[:operation] == 'searchRetrieve'
|
64
|
-
sru = Sru.new(params)
|
65
|
-
query = sru.cql.to_sunspot
|
66
|
-
sort = sru.sort_by
|
67
|
-
else
|
68
|
-
render :template => 'manifestations/explain', :layout => false
|
69
|
-
return
|
70
|
-
end
|
71
|
-
else
|
72
|
-
if params[:api] == 'openurl'
|
73
|
-
openurl = Openurl.new(params)
|
74
|
-
@manifestations = openurl.search
|
75
|
-
query = openurl.query_text
|
76
|
-
sort = set_search_result_order(params[:sort_by], params[:order])
|
77
|
-
else
|
78
|
-
query = make_query(params[:query], params)
|
79
|
-
sort = set_search_result_order(params[:sort_by], params[:order])
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# 絞り込みを行わない状態のクエリ
|
84
|
-
@query = query.dup
|
85
|
-
query = query.gsub(' ', ' ')
|
86
|
-
|
87
|
-
includes = [:carrier_type, :required_role, :items, :creators, :contributors, :publishers]
|
88
|
-
includes << :bookmarks if defined?(EnjuBookmark)
|
89
|
-
search = Manifestation.search(:include => includes)
|
90
|
-
role = current_user.try(:role) || Role.default_role
|
91
|
-
case @reservable
|
92
|
-
when 'true'
|
93
|
-
reservable = true
|
94
|
-
when 'false'
|
95
|
-
reservable = false
|
96
|
-
else
|
97
|
-
reservable = nil
|
98
|
-
end
|
99
|
-
|
100
|
-
patron = get_index_patron
|
101
|
-
@index_patron = patron
|
102
|
-
manifestation = @manifestation if @manifestation
|
103
|
-
series_statement = @series_statement if @series_statement
|
104
|
-
|
105
|
-
if defined?(EnjuSubject)
|
106
|
-
subject = @subject if @subject
|
107
|
-
end
|
108
|
-
|
109
|
-
unless mode == 'add'
|
110
|
-
search.build do
|
111
|
-
with(:creator_ids).equal_to patron[:creator].id if patron[:creator]
|
112
|
-
with(:contributor_ids).equal_to patron[:contributor].id if patron[:contributor]
|
113
|
-
with(:publisher_ids).equal_to patron[:publisher].id if patron[:publisher]
|
114
|
-
with(:original_manifestation_ids).equal_to manifestation.id if manifestation
|
115
|
-
with(:series_statement_id).equal_to series_statement.id if series_statement
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
search.build do
|
120
|
-
fulltext query unless query.blank?
|
121
|
-
order_by sort[:sort_by], sort[:order] unless oai_search
|
122
|
-
order_by :updated_at, :desc if oai_search
|
123
|
-
if defined?(EnjuSubject)
|
124
|
-
with(:subject_ids).equal_to subject.id if subject
|
125
|
-
end
|
126
|
-
if series_statement
|
127
|
-
with(:periodical_master).equal_to false
|
128
|
-
if mode != 'add'
|
129
|
-
with(:periodical).equal_to true
|
130
|
-
end
|
131
|
-
else
|
132
|
-
if mode != 'add'
|
133
|
-
with(:periodical).equal_to false
|
134
|
-
end
|
135
|
-
end
|
136
|
-
facet :reservable if defined?(EnjuCirculation)
|
137
|
-
end
|
138
|
-
search = make_internal_query(search)
|
139
|
-
search.data_accessor_for(Manifestation).select = [
|
140
|
-
:id,
|
141
|
-
:original_title,
|
142
|
-
:title_transcription,
|
143
|
-
:required_role_id,
|
144
|
-
:carrier_type_id,
|
145
|
-
:access_address,
|
146
|
-
:volume_number_string,
|
147
|
-
:issue_number_string,
|
148
|
-
:serial_number_string,
|
149
|
-
:date_of_publication,
|
150
|
-
:pub_date,
|
151
|
-
:language_id,
|
152
|
-
:carrier_type_id,
|
153
|
-
:created_at,
|
154
|
-
:updated_at,
|
155
|
-
:volume_number_string,
|
156
|
-
:volume_number,
|
157
|
-
:issue_number_string,
|
158
|
-
:issue_number,
|
159
|
-
:serial_number,
|
160
|
-
:edition_string,
|
161
|
-
:edition
|
162
|
-
] if params[:format] == 'html' or params[:format].nil?
|
163
|
-
all_result = search.execute
|
164
|
-
@count[:query_result] = all_result.total
|
165
|
-
@reservable_facet = all_result.facet(:reservable).rows if defined?(EnjuCirculation)
|
166
|
-
|
167
|
-
if session[:search_params]
|
168
|
-
unless search.query.to_params == session[:search_params]
|
169
|
-
clear_search_sessions
|
170
|
-
end
|
171
|
-
else
|
172
|
-
clear_search_sessions
|
173
|
-
session[:params] = params
|
174
|
-
session[:search_params] == search.query.to_params
|
175
|
-
session[:query] = @query
|
176
|
-
end
|
177
|
-
|
178
|
-
unless session[:manifestation_ids]
|
179
|
-
manifestation_ids = search.build do
|
180
|
-
paginate :page => 1, :per_page => configatron.max_number_of_results
|
181
|
-
end.execute.raw_results.collect(&:primary_key).map{|id| id.to_i}
|
182
|
-
session[:manifestation_ids] = manifestation_ids
|
183
|
-
end
|
184
|
-
|
185
|
-
if defined?(EnjuBookmark)
|
186
|
-
if session[:manifestation_ids]
|
187
|
-
if params[:view] == 'tag_cloud'
|
188
|
-
bookmark_ids = Bookmark.where(:manifestation_id => session[:manifestation_ids]).limit(1000).select(:id).collect(&:id)
|
189
|
-
@tags = Tag.bookmarked(bookmark_ids)
|
190
|
-
render :partial => 'manifestations/tag_cloud'
|
191
|
-
#session[:manifestation_ids] = nil
|
192
|
-
return
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
page ||= params[:page] || 1
|
198
|
-
per_page ||= Manifestation.per_page
|
199
|
-
if params[:format] == 'sru'
|
200
|
-
search.query.start_record(params[:startRecord] || 1, params[:maximumRecords] || 200)
|
201
|
-
else
|
202
|
-
search.build do
|
203
|
-
facet :reservable if defined?(EnjuCirculation)
|
204
|
-
facet :carrier_type
|
205
|
-
facet :library
|
206
|
-
facet :language
|
207
|
-
facet :subject_ids if defined?(EnjuSubject)
|
208
|
-
paginate :page => page.to_i, :per_page => per_page
|
209
|
-
end
|
210
|
-
end
|
211
|
-
search_result = search.execute
|
212
|
-
if @count[:query_result] > configatron.max_number_of_results
|
213
|
-
max_count = configatron.max_number_of_results
|
214
|
-
else
|
215
|
-
max_count = @count[:query_result]
|
216
|
-
end
|
217
|
-
@manifestations = WillPaginate::Collection.create(page, per_page, max_count) do |pager|
|
218
|
-
pager.replace(search_result.results)
|
219
|
-
end
|
220
|
-
|
221
|
-
if params[:format].blank? or params[:format] == 'html'
|
222
|
-
@carrier_type_facet = search_result.facet(:carrier_type).rows
|
223
|
-
@language_facet = search_result.facet(:language).rows
|
224
|
-
@library_facet = search_result.facet(:library).rows
|
225
|
-
end
|
226
|
-
|
227
|
-
@search_engines = Rails.cache.fetch('search_engine_all'){SearchEngine.all}
|
228
|
-
|
229
|
-
if defined?(EnjuBookmark)
|
230
|
-
# TODO: 検索結果が少ない場合にも表示させる
|
231
|
-
if manifestation_ids.blank?
|
232
|
-
if query.respond_to?(:suggest_tags)
|
233
|
-
@suggested_tag = query.suggest_tags.first
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
if defined?(EnjuSearchLog)
|
239
|
-
save_search_history(query, @manifestations.offset, @count[:query_result], current_user)
|
240
|
-
end
|
241
|
-
|
242
|
-
if defined?(EnjuOai)
|
243
|
-
if params[:format] == 'oai'
|
244
|
-
unless @manifestations.empty?
|
245
|
-
@resumption = set_resumption_token(
|
246
|
-
params[:resumptionToken],
|
247
|
-
@from_time || Manifestation.last.updated_at,
|
248
|
-
@until_time || Manifestation.first.updated_at,
|
249
|
-
@manifestations.per_page
|
250
|
-
)
|
251
|
-
else
|
252
|
-
@oai[:errors] << 'noRecordsMatch'
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
store_location # before_filter ではファセット検索のURLを記憶してしまう
|
259
|
-
|
260
|
-
respond_to do |format|
|
261
|
-
format.html
|
262
|
-
format.mobile
|
263
|
-
format.xml { render :xml => @manifestations }
|
264
|
-
format.sru { render :layout => false }
|
265
|
-
format.rss { render :layout => false }
|
266
|
-
format.csv { render :layout => false }
|
267
|
-
format.rdf { render :layout => false }
|
268
|
-
format.atom
|
269
|
-
format.oai {
|
270
|
-
case params[:verb]
|
271
|
-
when 'Identify'
|
272
|
-
render :template => 'manifestations/identify'
|
273
|
-
when 'ListMetadataFormats'
|
274
|
-
render :template => 'manifestations/list_metadata_formats'
|
275
|
-
when 'ListSets'
|
276
|
-
@series_statements = SeriesStatement.select([:id, :original_title])
|
277
|
-
render :template => 'manifestations/list_sets'
|
278
|
-
when 'ListIdentifiers'
|
279
|
-
render :template => 'manifestations/list_identifiers'
|
280
|
-
when 'ListRecords'
|
281
|
-
render :template => 'manifestations/list_records'
|
282
|
-
end
|
283
|
-
}
|
284
|
-
format.mods
|
285
|
-
format.json { render :json => @manifestations }
|
286
|
-
format.js
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
private
|
291
|
-
|
292
|
-
def make_query(query, options = {})
|
293
|
-
# TODO: integerやstringもqfに含める
|
294
|
-
query = query.to_s.strip
|
295
|
-
|
296
|
-
if query.size == 1
|
297
|
-
query = "#{query}*"
|
298
|
-
end
|
299
|
-
|
300
|
-
if options[:mode] == 'recent'
|
301
|
-
query = "#{query} created_at_d:[NOW-1MONTH TO NOW]"
|
302
|
-
end
|
303
|
-
|
304
|
-
unless options[:tag].blank?
|
305
|
-
query = "#{query} tag_sm:#{options[:tag]}"
|
306
|
-
end
|
307
|
-
|
308
|
-
unless options[:creator].blank?
|
309
|
-
query = "#{query} creator_text:#{options[:creator]}"
|
310
|
-
end
|
311
|
-
|
312
|
-
unless options[:contributor].blank?
|
313
|
-
query = "#{query} contributor_text:#{options[:contributor]}"
|
314
|
-
end
|
315
|
-
|
316
|
-
unless options[:isbn].blank?
|
317
|
-
query = "#{query} isbn_sm:#{options[:isbn].gsub('-', '')}"
|
318
|
-
end
|
319
|
-
|
320
|
-
unless options[:issn].blank?
|
321
|
-
query = "#{query} issn_s:#{options[:issn].gsub('-', '')}"
|
322
|
-
end
|
323
|
-
|
324
|
-
unless options[:lccn].blank?
|
325
|
-
query = "#{query} lccn_s:#{options[:lccn]}"
|
326
|
-
end
|
327
|
-
|
328
|
-
unless options[:nbn].blank?
|
329
|
-
query = "#{query} nbn_s:#{options[:nbn]}"
|
330
|
-
end
|
331
|
-
|
332
|
-
unless options[:publisher].blank?
|
333
|
-
query = "#{query} publisher_text:#{options[:publisher]}"
|
334
|
-
end
|
335
|
-
|
336
|
-
unless options[:item_identifier].blank?
|
337
|
-
query = "#{query} item_identifier_sm:#{options[:item_identifier]}"
|
338
|
-
end
|
339
|
-
|
340
|
-
unless options[:number_of_pages_at_least].blank? and options[:number_of_pages_at_most].blank?
|
341
|
-
number_of_pages = {}
|
342
|
-
number_of_pages[:at_least] = options[:number_of_pages_at_least].to_i
|
343
|
-
number_of_pages[:at_most] = options[:number_of_pages_at_most].to_i
|
344
|
-
number_of_pages[:at_least] = "*" if number_of_pages[:at_least] == 0
|
345
|
-
number_of_pages[:at_most] = "*" if number_of_pages[:at_most] == 0
|
346
|
-
|
347
|
-
query = "#{query} number_of_pages_i:[#{number_of_pages[:at_least]} TO #{number_of_pages[:at_most]}]"
|
348
|
-
end
|
349
|
-
|
350
|
-
query = set_pub_date(query, options)
|
351
|
-
query = set_acquisition_date(query, options)
|
352
|
-
|
353
|
-
query = query.strip
|
354
|
-
if query == '[* TO *]'
|
355
|
-
# unless params[:advanced_search]
|
356
|
-
query = ''
|
357
|
-
# end
|
358
|
-
end
|
359
|
-
|
360
|
-
return query
|
361
|
-
end
|
362
|
-
|
363
|
-
def set_search_result_order(sort_by, order)
|
364
|
-
sort = {}
|
365
|
-
# TODO: ページ数や大きさでの並べ替え
|
366
|
-
case sort_by
|
367
|
-
when 'title'
|
368
|
-
sort[:sort_by] = 'sort_title'
|
369
|
-
sort[:order] = 'asc'
|
370
|
-
when 'pub_date'
|
371
|
-
sort[:sort_by] = 'date_of_publication'
|
372
|
-
sort[:order] = 'desc'
|
373
|
-
else
|
374
|
-
# デフォルトの並び方
|
375
|
-
sort[:sort_by] = 'created_at'
|
376
|
-
sort[:order] = 'desc'
|
377
|
-
end
|
378
|
-
if order == 'asc'
|
379
|
-
sort[:order] = 'asc'
|
380
|
-
elsif order == 'desc'
|
381
|
-
sort[:order] = 'desc'
|
382
|
-
end
|
383
|
-
sort
|
384
|
-
end
|
385
|
-
|
386
|
-
def render_mode(mode)
|
387
|
-
case mode
|
388
|
-
when 'holding'
|
389
|
-
render :partial => 'manifestations/show_holding', :locals => {:manifestation => @manifestation}
|
390
|
-
when 'barcode'
|
391
|
-
if defined?(EnjuBarcode)
|
392
|
-
barcode = Barby::QrCode.new(@manifestation.id)
|
393
|
-
send_data(barcode.to_svg, :disposition => 'inline', :type => 'image/svg+xml')
|
394
|
-
end
|
395
|
-
when 'tag_edit'
|
396
|
-
if defined?(EnjuBookmark)
|
397
|
-
render :partial => 'manifestations/tag_edit', :locals => {:manifestation => @manifestation}
|
398
|
-
end
|
399
|
-
when 'tag_list'
|
400
|
-
if defined?(EnjuBookmark)
|
401
|
-
render :partial => 'manifestations/tag_list', :locals => {:manifestation => @manifestation}
|
402
|
-
end
|
403
|
-
when 'show_index'
|
404
|
-
render :partial => 'manifestations/show_index', :locals => {:manifestation => @manifestation}
|
405
|
-
when 'show_creators'
|
406
|
-
render :partial => 'manifestations/show_creators', :locals => {:manifestation => @manifestation}
|
407
|
-
when 'show_all_creators'
|
408
|
-
render :partial => 'manifestations/show_creators', :locals => {:manifestation => @manifestation}
|
409
|
-
when 'pickup'
|
410
|
-
render :partial => 'manifestations/pickup', :locals => {:manifestation => @manifestation}
|
411
|
-
when 'calil_list'
|
412
|
-
if defined?(EnjuCalil)
|
413
|
-
render :partial => 'manifestations/calil_list', :locals => {:manifestation => @manifestation}
|
414
|
-
end
|
415
|
-
else
|
416
|
-
false
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
def prepare_options
|
421
|
-
@carrier_types = CarrierType.all
|
422
|
-
@content_types = ContentType.all
|
423
|
-
@roles = Role.all
|
424
|
-
@languages = Language.all_cache
|
425
|
-
@frequencies = Frequency.all
|
426
|
-
@nii_types = NiiType.all if defined?(NiiType)
|
427
|
-
end
|
428
|
-
|
429
|
-
def get_index_patron
|
430
|
-
patron = {}
|
431
|
-
case
|
432
|
-
when params[:patron_id]
|
433
|
-
patron[:patron] = Patron.find(params[:patron_id])
|
434
|
-
when params[:creator_id]
|
435
|
-
patron[:creator] = Patron.find(params[:creator_id])
|
436
|
-
when params[:contributor_id]
|
437
|
-
patron[:contributor] = Patron.find(params[:contributor_id])
|
438
|
-
when params[:publisher_id]
|
439
|
-
patron[:publisher] = Patron.find(params[:publisher_id])
|
440
|
-
end
|
441
|
-
patron
|
442
|
-
end
|
443
|
-
|
444
|
-
def set_reservable
|
445
|
-
case params[:reservable].to_s
|
446
|
-
when 'true'
|
447
|
-
@reservable = true
|
448
|
-
when 'false'
|
449
|
-
@reservable = false
|
450
|
-
else
|
451
|
-
@reservable = nil
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
def set_pub_date(query, options)
|
456
|
-
unless options[:pub_date_from].blank? and options[:pub_date_to].blank?
|
457
|
-
options[:pub_date_from].to_s.gsub!(/\D/, '')
|
458
|
-
options[:pub_date_to].to_s.gsub!(/\D/, '')
|
459
|
-
|
460
|
-
pub_date = {}
|
461
|
-
if options[:pub_date_from].blank?
|
462
|
-
pub_date[:from] = "*"
|
463
|
-
else
|
464
|
-
pub_date[:from] = Time.zone.parse(options[:pub_date_from]).beginning_of_day.utc.iso8601 rescue nil
|
465
|
-
unless pub_date[:from]
|
466
|
-
pub_date[:from] = Time.zone.parse(Time.mktime(options[:pub_date_from]).to_s).beginning_of_day.utc.iso8601
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
if options[:pub_date_to].blank?
|
471
|
-
pub_date[:to] = "*"
|
472
|
-
else
|
473
|
-
pub_date[:to] = Time.zone.parse(options[:pub_date_to]).end_of_day.utc.iso8601 rescue nil
|
474
|
-
unless pub_date[:to]
|
475
|
-
pub_date[:to] = Time.zone.parse(Time.mktime(options[:pub_date_to]).to_s).end_of_year.utc.iso8601
|
476
|
-
end
|
477
|
-
end
|
478
|
-
query = "#{query} date_of_publication_d:[#{pub_date[:from]} TO #{pub_date[:to]}]"
|
479
|
-
end
|
480
|
-
query
|
481
|
-
end
|
482
|
-
|
483
|
-
def set_acquisition_date(query, options)
|
484
|
-
unless options[:acquired_from].blank? and options[:acquired_to].blank?
|
485
|
-
options[:acquired_from].to_s.gsub!(/\D/, '')
|
486
|
-
options[:acquired_to].to_s.gsub!(/\D/, '')
|
487
|
-
|
488
|
-
acquisition_date = {}
|
489
|
-
if options[:acquired_from].blank?
|
490
|
-
acquisition_date[:from] = "*"
|
491
|
-
else
|
492
|
-
acquisition_date[:from] = Time.zone.parse(options[:acquired_from]).beginning_of_day.utc.iso8601 rescue nil
|
493
|
-
unless acquisition_date[:from]
|
494
|
-
acquisition_date[:from] = Time.zone.parse(Time.mktime(options[:acquired_from]).to_s).beginning_of_day.utc.iso8601
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
if options[:acquired_to].blank?
|
499
|
-
acquisition_date[:to] = "*"
|
500
|
-
else
|
501
|
-
acquisition_date[:to] = Time.zone.parse(options[:acquired_to]).end_of_day.utc.iso8601 rescue nil
|
502
|
-
unless acquisition_date[:to]
|
503
|
-
acquisition_date[:to] = Time.zone.parse(Time.mktime(options[:acquired_to]).to_s).end_of_year.utc.iso8601
|
504
|
-
end
|
505
|
-
end
|
506
|
-
query = "#{query} acquired_at_d:[#{acquisition_date[:from]} TO #{acquisition_date[:to]}]"
|
507
|
-
end
|
508
|
-
query
|
509
|
-
end
|
510
|
-
|
511
|
-
def set_title
|
512
|
-
if @series_statement
|
513
|
-
@manifestation.set_series_statement(@series_statement)
|
514
|
-
elsif @original_manifestation
|
515
|
-
@manifestation.original_title = @original_manifestation.original_title
|
516
|
-
@manifestation.title_transcription = @original_manifestation.title_transcription
|
517
|
-
end
|
518
|
-
end
|
519
|
-
end
|