enju_biblio 0.3.11 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/items_controller.rb +13 -2
- data/app/controllers/manifestations_controller.rb +35 -47
- data/app/views/items/_item.json.jbuilder +17 -0
- data/app/views/items/index.json.jbuilder +5 -0
- data/app/views/items/show.json.jbuilder +1 -0
- data/lib/enju_biblio.rb +0 -2
- data/lib/enju_biblio/version.rb +1 -1
- data/spec/controllers/items_controller_spec.rb +36 -0
- data/spec/controllers/manifestations_controller_spec.rb +0 -19
- data/spec/models/manifestation_spec.rb +0 -65
- data/spec/views/items/index.json.jbuilder_spec.rb +15 -0
- data/spec/views/items/show.json.jbuilder_spec.rb +15 -0
- metadata +9 -6
- data/app/views/manifestations/explain.sru +0 -9
- data/app/views/manifestations/index.sru.builder +0 -101
- data/lib/enju_biblio/porta_cql.rb +0 -282
- data/lib/enju_biblio/sru.rb +0 -85
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13bb317c73b54a9d6ff4bc74db706b224929d3474f1de724d53abd0a3c075e12
|
4
|
+
data.tar.gz: 3fc674acbf36775a9394609f1a3108230c94e62455fdf257371571b58d330990
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad673e2ff6572eee73c8ba3314c28895876e41e86e24545f7c8dd090d059544f01c280bb4e0c9cd668d4daa19db04c03771a6b6ddc9d0d385ad42162bf8f51d
|
7
|
+
data.tar.gz: cc53497b07c0d9fea3e1186b9be7e401e47aabb4b32df2087b949e5b95eabb270a0cc056fefc7aea7f65edc31b1f7f02662e1403f1c6704bcad5e1b40eaf3f4f
|
@@ -51,6 +51,17 @@ class ItemsController < ApplicationController
|
|
51
51
|
|
52
52
|
unless @inventory_file
|
53
53
|
search = Sunspot.new_search(Item)
|
54
|
+
selected_attributes = [
|
55
|
+
:id, :item_identifier, :call_number, :manifestation_id, :acquired_at,
|
56
|
+
:binding_item_identifier, :binding_call_number, :binded_at,
|
57
|
+
:include_supplements, :url, :note,
|
58
|
+
:circulation_status_id, :shelf_id,
|
59
|
+
:created_at, :updated_at
|
60
|
+
]
|
61
|
+
selected_attributes += [
|
62
|
+
:memo, :required_role_id, :budget_type_id, :bookstore_id, :price
|
63
|
+
] if current_user.try(:has_role?, 'Librarian')
|
64
|
+
search.data_accessor_for(Item).select = selected_attributes
|
54
65
|
set_role_query(current_user, search)
|
55
66
|
|
56
67
|
@query = query.dup
|
@@ -122,7 +133,7 @@ class ItemsController < ApplicationController
|
|
122
133
|
|
123
134
|
respond_to do |format|
|
124
135
|
format.html # index.html.erb
|
125
|
-
format.json
|
136
|
+
format.json
|
126
137
|
format.txt { render layout: false }
|
127
138
|
format.atom
|
128
139
|
end
|
@@ -137,7 +148,7 @@ class ItemsController < ApplicationController
|
|
137
148
|
|
138
149
|
respond_to do |format|
|
139
150
|
format.html # show.html.erb
|
140
|
-
format.json
|
151
|
+
format.json
|
141
152
|
end
|
142
153
|
end
|
143
154
|
|
@@ -33,25 +33,14 @@ class ManifestationsController < ApplicationController
|
|
33
33
|
per_page = 65534
|
34
34
|
end
|
35
35
|
|
36
|
-
if params[:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
else
|
42
|
-
render template: 'manifestations/explain', layout: false
|
43
|
-
return
|
44
|
-
end
|
36
|
+
if params[:api] == 'openurl'
|
37
|
+
openurl = Openurl.new(params)
|
38
|
+
@manifestations = openurl.search
|
39
|
+
query = openurl.query_text
|
40
|
+
sort = set_search_result_order(params[:sort_by], params[:order])
|
45
41
|
else
|
46
|
-
|
47
|
-
|
48
|
-
@manifestations = openurl.search
|
49
|
-
query = openurl.query_text
|
50
|
-
sort = set_search_result_order(params[:sort_by], params[:order])
|
51
|
-
else
|
52
|
-
query = make_query(params[:query], params)
|
53
|
-
sort = set_search_result_order(params[:sort_by], params[:order])
|
54
|
-
end
|
42
|
+
query = make_query(params[:query], params)
|
43
|
+
sort = set_search_result_order(params[:sort_by], params[:order])
|
55
44
|
end
|
56
45
|
|
57
46
|
# 絞り込みを行わない状態のクエリ
|
@@ -191,37 +180,37 @@ class ManifestationsController < ApplicationController
|
|
191
180
|
else
|
192
181
|
per_page = Manifestation.default_per_page
|
193
182
|
end
|
194
|
-
|
195
|
-
|
183
|
+
|
184
|
+
pub_dates = parse_pub_date(params)
|
185
|
+
pub_date_range = {}
|
186
|
+
|
187
|
+
if pub_dates[:from] == '*'
|
188
|
+
pub_date_range[:from] = 0
|
196
189
|
else
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
if pub_dates[:until] == '*'
|
205
|
-
pub_date_range[:until] = 10000
|
206
|
-
else
|
207
|
-
pub_date_range[:until] = Time.zone.parse(pub_dates[:until]).year
|
208
|
-
end
|
209
|
-
if params[:pub_year_range_interval]
|
210
|
-
pub_year_range_interval = params[:pub_year_range_interval].to_i
|
211
|
-
else
|
212
|
-
pub_year_range_interval = @library_group.pub_year_facet_range_interval || 10
|
213
|
-
end
|
190
|
+
pub_date_range[:from] = Time.zone.parse(pub_dates[:from]).year
|
191
|
+
end
|
192
|
+
if pub_dates[:until] == '*'
|
193
|
+
pub_date_range[:until] = 10000
|
194
|
+
else
|
195
|
+
pub_date_range[:until] = Time.zone.parse(pub_dates[:until]).year
|
196
|
+
end
|
214
197
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
facet :language
|
220
|
-
facet :pub_year, range: pub_date_range[:from]..pub_date_range[:until], range_interval: pub_year_range_interval
|
221
|
-
facet :subject_ids if defined?(EnjuSubject)
|
222
|
-
paginate page: page.to_i, per_page: per_page
|
223
|
-
end
|
198
|
+
if params[:pub_year_range_interval]
|
199
|
+
pub_year_range_interval = params[:pub_year_range_interval].to_i
|
200
|
+
else
|
201
|
+
pub_year_range_interval = @library_group.pub_year_facet_range_interval || 10
|
224
202
|
end
|
203
|
+
|
204
|
+
search.build do
|
205
|
+
facet :reservable if defined?(EnjuCirculation)
|
206
|
+
facet :carrier_type
|
207
|
+
facet :library
|
208
|
+
facet :language
|
209
|
+
facet :pub_year, range: pub_date_range[:from]..pub_date_range[:until], range_interval: pub_year_range_interval
|
210
|
+
facet :subject_ids if defined?(EnjuSubject)
|
211
|
+
paginate page: page.to_i, per_page: per_page
|
212
|
+
end
|
213
|
+
|
225
214
|
search_result = search.execute
|
226
215
|
if @count[:query_result] > @max_number_of_results
|
227
216
|
max_count = @max_number_of_results
|
@@ -261,7 +250,6 @@ class ManifestationsController < ApplicationController
|
|
261
250
|
format.html
|
262
251
|
format.html.phone
|
263
252
|
format.xml { render xml: @manifestations }
|
264
|
-
format.sru { render layout: false }
|
265
253
|
format.rss { render layout: false }
|
266
254
|
format.txt { render layout: false }
|
267
255
|
format.rdf { render layout: false }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
json.id item.id
|
2
|
+
json.manifestation_id item.manifestation_id
|
3
|
+
json.item_identifier item.item_identifier
|
4
|
+
json.call_number item.call_number
|
5
|
+
json.shelf item.shelf.name
|
6
|
+
if defined?(EnjuCirculation)
|
7
|
+
json.circulation_status item.circulation_status&.name
|
8
|
+
end
|
9
|
+
json.binding_item_identifier item.binding_item_identifier
|
10
|
+
json.binding_call_number item.binding_call_number
|
11
|
+
json.binded_at item.binded_at
|
12
|
+
json.acquired_at item.acquired_at
|
13
|
+
json.include_supplements item.include_supplements
|
14
|
+
json.url item.url
|
15
|
+
json.note item.note
|
16
|
+
json.created_at item.created_at
|
17
|
+
json.updated_at item.updated_at
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial!(@item)
|
data/lib/enju_biblio.rb
CHANGED
data/lib/enju_biblio/version.rb
CHANGED
@@ -46,6 +46,18 @@ describe ItemsController do
|
|
46
46
|
expect(assigns(:items)).to_not be_nil
|
47
47
|
expect(assigns(:items).count).to eq 1
|
48
48
|
end
|
49
|
+
|
50
|
+
describe 'in JSON response' do
|
51
|
+
render_views
|
52
|
+
it 'should not assign unnecessary attributes' do
|
53
|
+
get :index, format: :json
|
54
|
+
expect(response.body).to match /manifestation_id/
|
55
|
+
expect(response.body).not_to match /price/
|
56
|
+
expect(response.body).not_to match /memo/
|
57
|
+
expect(response.body).not_to match /bookstore_id/
|
58
|
+
expect(response.body).not_to match /budget_type_id/
|
59
|
+
end
|
60
|
+
end
|
49
61
|
end
|
50
62
|
|
51
63
|
describe 'When logged in as User' do
|
@@ -55,6 +67,18 @@ describe ItemsController do
|
|
55
67
|
get :index
|
56
68
|
expect(assigns(:items)).to_not be_nil
|
57
69
|
end
|
70
|
+
|
71
|
+
describe 'in JSON response' do
|
72
|
+
render_views
|
73
|
+
it 'should not assign unnecessary attributes' do
|
74
|
+
get :index, format: :json
|
75
|
+
expect(response.body).to match /manifestation_id/
|
76
|
+
expect(response.body).not_to match /price/
|
77
|
+
expect(response.body).not_to match /memo/
|
78
|
+
expect(response.body).not_to match /bookstore_id/
|
79
|
+
expect(response.body).not_to match /budget_type_id/
|
80
|
+
end
|
81
|
+
end
|
58
82
|
end
|
59
83
|
|
60
84
|
describe 'When not logged in' do
|
@@ -83,6 +107,18 @@ describe ItemsController do
|
|
83
107
|
assigns(:shelf).should eq Shelf.find(1)
|
84
108
|
expect(assigns(:items)).to eq assigns(:shelf).items.order('created_at DESC').page(1)
|
85
109
|
end
|
110
|
+
|
111
|
+
describe 'in JSON response' do
|
112
|
+
render_views
|
113
|
+
it 'should not assign unnecessary attributes' do
|
114
|
+
get :index, format: :json
|
115
|
+
expect(response.body).to match /manifestation_id/
|
116
|
+
expect(response.body).not_to match /price/
|
117
|
+
expect(response.body).not_to match /memo/
|
118
|
+
expect(response.body).not_to match /bookstore_id/
|
119
|
+
expect(response.body).not_to match /budget_type_id/
|
120
|
+
end
|
121
|
+
end
|
86
122
|
end
|
87
123
|
end
|
88
124
|
|
@@ -58,25 +58,6 @@ describe ManifestationsController do
|
|
58
58
|
expect(response).to render_template('manifestations/index')
|
59
59
|
end
|
60
60
|
|
61
|
-
it 'assigns all manifestations as @manifestations in sru format without operation' do
|
62
|
-
get :index, format: 'sru'
|
63
|
-
assert_response :success
|
64
|
-
expect(assigns(:manifestations)).to be_nil
|
65
|
-
expect(response).to render_template('manifestations/explain')
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'assigns all manifestations as @manifestations in sru format with operation' do
|
69
|
-
get :index, params: { format: 'sru', operation: 'searchRetrieve', query: 'ruby' }
|
70
|
-
expect(assigns(:manifestations)).to_not be_nil
|
71
|
-
expect(response).to render_template('manifestations/index')
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'assigns all manifestations as @manifestations in sru format with operation and title' do
|
75
|
-
get :index, params: { format: 'sru', query: 'title=ruby', operation: 'searchRetrieve' }
|
76
|
-
expect(assigns(:manifestations)).to_not be_nil
|
77
|
-
expect(response).to render_template('manifestations/index')
|
78
|
-
end
|
79
|
-
|
80
61
|
it 'assigns all manifestations as @manifestations in openurl' do
|
81
62
|
get :index, params: { api: 'openurl', title: 'ruby' }
|
82
63
|
expect(assigns(:manifestations)).to_not be_nil
|
@@ -98,71 +98,6 @@ describe Manifestation, solr: true do
|
|
98
98
|
lambda{Openurl.new({aufirst: "テスト 名称"})}.should raise_error(OpenurlQuerySyntaxError)
|
99
99
|
end
|
100
100
|
|
101
|
-
it "should search in sru" do
|
102
|
-
sru = Sru.new({query: "title=Ruby"})
|
103
|
-
sru.search
|
104
|
-
sru.manifestations.size.should eq 18
|
105
|
-
sru.manifestations.first.titles.first.should eq 'Ruby'
|
106
|
-
sru = Sru.new({query: "title=^ruby"})
|
107
|
-
sru.search
|
108
|
-
sru.manifestations.size.should eq 9
|
109
|
-
sru = Sru.new({query: 'title ALL "awk sed"'})
|
110
|
-
sru.search
|
111
|
-
sru.manifestations.size.should eq 2
|
112
|
-
sru.manifestations.collect{|m| m.id}.should eq [184, 116]
|
113
|
-
sru = Sru.new({query: 'title ANY "ruby awk sed"'})
|
114
|
-
sru.search
|
115
|
-
sru.manifestations.size.should eq 22
|
116
|
-
sru = Sru.new({query: 'isbn=9784756137470'})
|
117
|
-
sru.search
|
118
|
-
sru.manifestations.first.id.should eq 114
|
119
|
-
sru = Sru.new({query: "creator=テスト"})
|
120
|
-
sru.search
|
121
|
-
sru.manifestations.size.should eq 1
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should search date in sru" do
|
125
|
-
sru = Sru.new({query: "from = 2000-09 AND until = 2000-11-01"})
|
126
|
-
sru.search
|
127
|
-
sru.manifestations.size.should eq 1
|
128
|
-
sru.manifestations.first.id.should eq 120
|
129
|
-
sru = Sru.new({query: "from = 1993-02-24"})
|
130
|
-
sru.search
|
131
|
-
sru.manifestations.size.should eq 5
|
132
|
-
sru = Sru.new({query: "until = 2006-08-06"})
|
133
|
-
sru.search
|
134
|
-
sru.manifestations.size.should eq 4
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should accept sort_by in sru" do
|
138
|
-
sru = Sru.new({query: "title=Ruby"})
|
139
|
-
sru.sort_by.should eq({sort_by: 'created_at', order: 'desc'})
|
140
|
-
sru = Sru.new({query: 'title=Ruby AND sortBy="title/sort.ascending"', sortKeys: 'creator,0', version: '1.2'})
|
141
|
-
sru.sort_by.should eq({sort_by: 'sort_title', order: 'asc'})
|
142
|
-
sru = Sru.new({query: 'title=Ruby AND sortBy="title/sort.ascending"', sortKeys: 'creator,0', version: '1.1'})
|
143
|
-
sru.sort_by.should eq({sort_by: 'creator', order: 'desc'})
|
144
|
-
sru = Sru.new({query: 'title=Ruby AND sortBy="title/sort.ascending"', sortKeys: 'creator,1', version: '1.1'})
|
145
|
-
sru.sort_by.should eq({sort_by: 'creator', order: 'asc'})
|
146
|
-
sru = Sru.new({query: 'title=Ruby AND sortBy="title'})
|
147
|
-
sru.sort_by.should eq({sort_by: 'sort_title', order: 'asc'})
|
148
|
-
# TODO ソート基準が入手しやすさの場合の処理
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should accept ranges in sru" do
|
152
|
-
sru = Sru.new({query: "from = 1993-02-24 AND until = 2006-08-06 AND title=プログラミング"})
|
153
|
-
sru.search
|
154
|
-
sru.manifestations.size.should eq 2
|
155
|
-
sru = Sru.new({query: "until = 2000 AND title=プログラミング"})
|
156
|
-
sru.search
|
157
|
-
sru.manifestations.size.should eq 1
|
158
|
-
sru = Sru.new({query: "from = 2006 AND title=プログラミング"})
|
159
|
-
sru.search
|
160
|
-
sru.manifestations.size.should eq 1
|
161
|
-
sru = Sru.new({query: "from = 2007 OR title=awk"})
|
162
|
-
sru.search
|
163
|
-
sru.manifestations.size.should eq 6
|
164
|
-
end
|
165
|
-
|
166
101
|
it "should_get_number_of_pages" do
|
167
102
|
manifestations(:manifestation_00001).number_of_pages.should eq 100
|
168
103
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rails_helper.rb"
|
2
|
+
|
3
|
+
describe "items/index.json.jbuilder", solr: true do
|
4
|
+
before(:each) do
|
5
|
+
item = FactoryBot.create(:item)
|
6
|
+
@items = assign(:items, [item] )
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should export JSON format" do
|
10
|
+
params[:format] = "json"
|
11
|
+
render
|
12
|
+
expect(rendered).not_to match(/memo/)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe "items/show.json.jbuilder" do
|
4
|
+
fixtures :all
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
assign(:item, FactoryBot.create(:item))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "renders a template" do
|
11
|
+
render
|
12
|
+
expect(rendered).to match(/item_identifier/)
|
13
|
+
expect(rendered).not_to match(/memo/)
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enju_biblio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kosuke Tanabe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: enju_library
|
@@ -746,6 +746,7 @@ files:
|
|
746
746
|
- app/views/item_custom_properties/new.html.erb
|
747
747
|
- app/views/item_custom_properties/show.html.erb
|
748
748
|
- app/views/items/_form.html.erb
|
749
|
+
- app/views/items/_item.json.jbuilder
|
749
750
|
- app/views/items/_observe_field.html.erb
|
750
751
|
- app/views/items/_shelf_picture.html+phone.erb
|
751
752
|
- app/views/items/_shelf_picture.html.erb
|
@@ -753,10 +754,12 @@ files:
|
|
753
754
|
- app/views/items/edit.html.erb
|
754
755
|
- app/views/items/index.html+phone.erb
|
755
756
|
- app/views/items/index.html.erb
|
757
|
+
- app/views/items/index.json.jbuilder
|
756
758
|
- app/views/items/index.txt.erb
|
757
759
|
- app/views/items/new.html.erb
|
758
760
|
- app/views/items/show.html+phone.erb
|
759
761
|
- app/views/items/show.html.erb
|
762
|
+
- app/views/items/show.json.jbuilder
|
760
763
|
- app/views/languages/_form.html.erb
|
761
764
|
- app/views/languages/edit.html.erb
|
762
765
|
- app/views/languages/index.html.erb
|
@@ -853,7 +856,6 @@ files:
|
|
853
856
|
- app/views/manifestations/_title.html.erb
|
854
857
|
- app/views/manifestations/edit.html.erb
|
855
858
|
- app/views/manifestations/error.xml
|
856
|
-
- app/views/manifestations/explain.sru
|
857
859
|
- app/views/manifestations/index.atom.builder
|
858
860
|
- app/views/manifestations/index.html+phone.erb
|
859
861
|
- app/views/manifestations/index.html.erb
|
@@ -862,7 +864,6 @@ files:
|
|
862
864
|
- app/views/manifestations/index.opds.builder
|
863
865
|
- app/views/manifestations/index.rdf.builder
|
864
866
|
- app/views/manifestations/index.rss.builder
|
865
|
-
- app/views/manifestations/index.sru.builder
|
866
867
|
- app/views/manifestations/index.txt.ruby
|
867
868
|
- app/views/manifestations/new.html.erb
|
868
869
|
- app/views/manifestations/show.html+phone.erb
|
@@ -1079,8 +1080,6 @@ files:
|
|
1079
1080
|
- lib/enju_biblio.rb
|
1080
1081
|
- lib/enju_biblio/engine.rb
|
1081
1082
|
- lib/enju_biblio/openurl.rb
|
1082
|
-
- lib/enju_biblio/porta_cql.rb
|
1083
|
-
- lib/enju_biblio/sru.rb
|
1084
1083
|
- lib/enju_biblio/version.rb
|
1085
1084
|
- lib/generators/enju_biblio/setup/USAGE
|
1086
1085
|
- lib/generators/enju_biblio/setup/setup_generator.rb
|
@@ -1622,6 +1621,8 @@ files:
|
|
1622
1621
|
- spec/views/item_custom_properties/new.html.erb_spec.rb
|
1623
1622
|
- spec/views/item_custom_properties/show.html.erb_spec.rb
|
1624
1623
|
- spec/views/items/index.html.erb_spec.rb
|
1624
|
+
- spec/views/items/index.json.jbuilder_spec.rb
|
1625
|
+
- spec/views/items/show.json.jbuilder_spec.rb
|
1625
1626
|
- spec/views/manifestation_custom_properties/edit.html.erb_spec.rb
|
1626
1627
|
- spec/views/manifestation_custom_properties/index.html.erb_spec.rb
|
1627
1628
|
- spec/views/manifestation_custom_properties/new.html.erb_spec.rb
|
@@ -2033,7 +2034,9 @@ test_files:
|
|
2033
2034
|
- spec/views/item_custom_properties/edit.html.erb_spec.rb
|
2034
2035
|
- spec/views/item_custom_properties/index.html.erb_spec.rb
|
2035
2036
|
- spec/views/item_custom_properties/show.html.erb_spec.rb
|
2037
|
+
- spec/views/items/show.json.jbuilder_spec.rb
|
2036
2038
|
- spec/views/items/index.html.erb_spec.rb
|
2039
|
+
- spec/views/items/index.json.jbuilder_spec.rb
|
2037
2040
|
- spec/views/series_statement_merge_lists/new.html.erb_spec.rb
|
2038
2041
|
- spec/views/series_statement_merge_lists/edit.html.erb_spec.rb
|
2039
2042
|
- spec/views/series_statement_merge_lists/index.html.erb_spec.rb
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<sru:explainResponse xmlns:sru="http://www.loc.gov/zing/srw/">
|
2
|
-
<sru:version>1.2</sru:version>
|
3
|
-
<sru:record>
|
4
|
-
<sru:recordPacking>XML</sru:recordPacking>
|
5
|
-
<sru:recordSchema>http://explain.z3950.org/dtd/2.1/</sru:recordSchema>
|
6
|
-
<sru:recordData>
|
7
|
-
</sru:recordData>
|
8
|
-
</sru:record>
|
9
|
-
</sru:explainResponse>
|
@@ -1,101 +0,0 @@
|
|
1
|
-
if @sru
|
2
|
-
unless @sru.extra_response_data.empty?
|
3
|
-
@extra_response = true
|
4
|
-
@facets = @sru.extra_response_data[:facets]
|
5
|
-
@dpid = @sru.extra_response_data[:dpid]
|
6
|
-
@webget = @sru.extra_response_data[:webget]
|
7
|
-
@digitalize = @sru.extra_response_data[:digitalize]
|
8
|
-
@porta_type = @sru.extra_response_data[:porta_type]
|
9
|
-
@payment = @sru.extra_response_data[:payment]
|
10
|
-
@ndc = @sru.extra_response_data[:ndc]
|
11
|
-
@date = @sru.extra_response_data[:date]
|
12
|
-
end
|
13
|
-
|
14
|
-
@version = @sru.version
|
15
|
-
@packing = @sru.packing
|
16
|
-
@number_of_records = @manifestations.total_count
|
17
|
-
@next_record_position = @sru.start + @manifestations.limit_value
|
18
|
-
end
|
19
|
-
|
20
|
-
def search_retrieve_response!(xml)
|
21
|
-
xml.searchRetrieveResponse xmlns: "http://www.loc.gov/zing/srw/" do
|
22
|
-
xml.version @version
|
23
|
-
xml.numberOfRecords @number_of_records
|
24
|
-
extra_response_data!(xml) if @extra_response
|
25
|
-
xml.records do
|
26
|
-
@manifestations.each_with_index do |rec, idx|
|
27
|
-
xml.record do
|
28
|
-
record!(xml, rec, idx + 1)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
xml.nextRecordPosition @next_record_position
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def extra_response_data!(xml)
|
37
|
-
xml.extraResponseData do
|
38
|
-
xml.facets @facets do
|
39
|
-
lst_tag!(xml, "REPOSITORY_NO", 'dcndl_porta:dpid', @dpid)
|
40
|
-
lst_tag!(xml, "WEBGET_TYPE", 'dcndl_porta:type.Web-get', @webget)
|
41
|
-
lst_tag!(xml, "DIGITALIZE_TYPE", 'dcndl_porta:type.Digitalize', @digitalize)
|
42
|
-
lst_tag!(xml, "PORTA_TYPE", 'dcndl_porta:PORTAType', @porta_type)
|
43
|
-
lst_tag!(xml, "PAYMENT_TYPE", 'dcndl_porta:type.Payment', @payment)
|
44
|
-
lst_tag!(xml, "NDC", 'int', @ndc)
|
45
|
-
lst_tag!(xml, "ISSUED_DATE", 'int', @date)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def lst_tag!(xml, lst_name, tag_name, hash)
|
51
|
-
xml.lst name: lst_name do
|
52
|
-
value_sort(hash).each do |item|
|
53
|
-
xml.tag! tag_name, {name: item[0]}, item[1]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def record!(xml, rec, position)
|
59
|
-
xml.recordSchema 'info:srw/schema/1/dc-v1.1'
|
60
|
-
xml.recordPacking @packing
|
61
|
-
xml.recordData{|x| x << (/\Axml\Z/io =~ @packing ? get_record(rec) : CGI::escapeHTML(get_record(rec)))}
|
62
|
-
xml.recordPosition position
|
63
|
-
end
|
64
|
-
|
65
|
-
def get_record(manifestation)
|
66
|
-
xml = Builder::XmlMarkup.new
|
67
|
-
xml.tag! 'srw_dc:dc',
|
68
|
-
'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
|
69
|
-
'xmlns:srw_dc' => "info:srw/schema/1/dc-v1.1",
|
70
|
-
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
|
71
|
-
'xsi:schemaLocation' => "info:srw/schema/1/dc-v1.1 http://www.loc.gov/standards/sru/dc-schema.xsd" do
|
72
|
-
cache([manifestation, fragment: 'index_sru', role: current_user_role_name, locale: @locale]) do
|
73
|
-
xml.tag! 'dc:title', manifestation.original_title
|
74
|
-
manifestation.creators.readable_by(current_user).each do |agent|
|
75
|
-
xml.tag! 'dc:creator', agent.full_name
|
76
|
-
end
|
77
|
-
manifestation.contributors.each do |agent|
|
78
|
-
xml.tag! 'dc:contributor', agent.full_name
|
79
|
-
end
|
80
|
-
manifestation.publishers.each do |agent|
|
81
|
-
xml.tag! 'dc:publisher', agent.full_name
|
82
|
-
end
|
83
|
-
if defined?(EnjuSubject)
|
84
|
-
manifestation.subjects.each do |subject|
|
85
|
-
xml.tag! "dc:subject", subject.term
|
86
|
-
end
|
87
|
-
end
|
88
|
-
xml.tag! 'dc:description', manifestation.description
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def value_sort(hash)
|
94
|
-
hash.to_a.sort do |a, b|
|
95
|
-
(b[1] <=> a[1]) * 2 + (a[0] <=> b[0])
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
xml = Builder::XmlMarkup.new indent: 2
|
100
|
-
xml.instruct! directive_tag=:xml, encoding: 'UTF-8'
|
101
|
-
search_retrieve_response!(xml)
|
@@ -1,282 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
class QueryError < RuntimeError; end
|
4
|
-
class QuerySyntaxError < QueryError; end
|
5
|
-
|
6
|
-
class Cql
|
7
|
-
def initialize(line)
|
8
|
-
@logic = nil
|
9
|
-
@query = split_clause_text(line).collect{|txt| Clause.new(txt)}
|
10
|
-
|
11
|
-
from_day, @query = extract_with_index(@query, /from/io)
|
12
|
-
@from = comp_date(from_day)
|
13
|
-
until_day, @query = extract_with_index(@query, /until/io)
|
14
|
-
@until = comp_date(until_day)
|
15
|
-
sort_by, @query = extract_with_index(@query, /sortBy/io)
|
16
|
-
@sort_by = sort_by ? sort_by.terms.first : ''
|
17
|
-
end
|
18
|
-
|
19
|
-
attr_reader :query, :from, :until, :sort_by, :logic
|
20
|
-
|
21
|
-
def ==(other)
|
22
|
-
instance_variables.all? do |val|
|
23
|
-
instance_variable_get(val) == other.instance_variable_get(val)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_sunspot
|
28
|
-
(@query.collect{|c| c.to_sunspot} + date_range(@from, @until)).join(" #{@logic} ")
|
29
|
-
end
|
30
|
-
|
31
|
-
def split_clause_text(line)
|
32
|
-
clauses = []
|
33
|
-
|
34
|
-
s = StringScanner.new(line)
|
35
|
-
text = ''
|
36
|
-
while s.rest?
|
37
|
-
case
|
38
|
-
when s.scan(/\s+/)
|
39
|
-
text << s.matched
|
40
|
-
when s.scan(/"(?:[^"\\]|\\.)*"/)
|
41
|
-
text << s.matched
|
42
|
-
when s.scan(/(AND|OR)/i)
|
43
|
-
logic = s.matched.upcase
|
44
|
-
if @logic
|
45
|
-
raise QuerySyntaxError unless @logic == logic
|
46
|
-
else
|
47
|
-
@logic = logic
|
48
|
-
end
|
49
|
-
clauses << text.strip
|
50
|
-
text = ''
|
51
|
-
when s.scan(/\S*/)
|
52
|
-
text << s.matched
|
53
|
-
end
|
54
|
-
end
|
55
|
-
clauses << text.strip
|
56
|
-
clauses.collect{|txt| txt.gsub(/(\A\(|\)\Z)/, '')}
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
def extract_with_index(arr, reg)
|
61
|
-
element, rest = arr.partition{|c| reg =~ c.index }
|
62
|
-
[element.last, rest]
|
63
|
-
end
|
64
|
-
|
65
|
-
def date_range(from_date, until_date)
|
66
|
-
unless from_date == '*' and until_date == '*'
|
67
|
-
["pub_date_dm:[#{from_date} TO #{until_date}]"]
|
68
|
-
else
|
69
|
-
[]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def comp_date(date)
|
74
|
-
if date
|
75
|
-
text = date.terms[0]
|
76
|
-
date_text = case text
|
77
|
-
when /\A\d{4}-\d{2}-\d{2}\Z/
|
78
|
-
text
|
79
|
-
when /\A\d{4}-\d{2}\Z/
|
80
|
-
(text + '-01')
|
81
|
-
when /\A\d{4}\Z/
|
82
|
-
(text + '-01-01')
|
83
|
-
else
|
84
|
-
raise QuerySyntaxError, text.to_s
|
85
|
-
end
|
86
|
-
begin
|
87
|
-
Time.zone.parse(date_text).utc.iso8601.to_s
|
88
|
-
rescue
|
89
|
-
raise QuerySyntaxError, date.to_s
|
90
|
-
end
|
91
|
-
else
|
92
|
-
'*'
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class ScannerError < QuerySyntaxError; end
|
98
|
-
class AdapterError < QuerySyntaxError; end
|
99
|
-
|
100
|
-
class Clause
|
101
|
-
INDEX = /(dpid|dpgroupid|title|creator|publisher|ndc|description|subject|isbn|issn|jpno|from|until|anywhere|porta_type|digitalize_type|webget_type|payment_type|ndl_agent_type|ndlc|itemno)/io
|
102
|
-
SORT_BY = /sortBy/io
|
103
|
-
RELATION = /(=|exact|\^|any|all)/io
|
104
|
-
|
105
|
-
MATCH_ALL = %w[title creator publisher]
|
106
|
-
MATCH_EXACT = %w[dpid dpgroupid isbn issn jpno porta_type digitalize_type webget_type payment_type ndl_agent_type itemno]
|
107
|
-
MATCH_PART = %w[description subject]
|
108
|
-
MATCH_AHEAD = %w[ndc ndlc]
|
109
|
-
MATCH_DATE = %w[from until]
|
110
|
-
MATCH_ANYWHERE = %w[anywhere]
|
111
|
-
LOGIC_ALL = %w[title creator publisher description subject anywhere]
|
112
|
-
LOGIC_ANY = %w[dpid ndl_agent_type]
|
113
|
-
LOGIC_EQUAL = %w[dpgroupid ndc isbn issn jpno from until porta_type digitalize_type webget_type payment_type ndlc itemno]
|
114
|
-
MULTIPLE = %w[dpid title creator publisher description subject anywhere ndl_agent_type]
|
115
|
-
|
116
|
-
def initialize(text)
|
117
|
-
unless text.empty?
|
118
|
-
@index, @relation, @terms = scan(text)
|
119
|
-
porta_adapter
|
120
|
-
@field = @index
|
121
|
-
else
|
122
|
-
@index = ''
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
attr_reader :index, :relation, :terms
|
127
|
-
|
128
|
-
def ==(other)
|
129
|
-
instance_variables.all? do |val|
|
130
|
-
instance_variable_get(val) == other.instance_variable_get(val)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def scan(text)
|
135
|
-
ss = StringScanner.new(text)
|
136
|
-
index = ''
|
137
|
-
relation = ''
|
138
|
-
terms = []
|
139
|
-
|
140
|
-
if ss.scan(INDEX) or ss.scan(SORT_BY)
|
141
|
-
index = ss[0]
|
142
|
-
end
|
143
|
-
# else
|
144
|
-
# raise ScannerError, "index or the sortBy is requested in '#{text}'"
|
145
|
-
# end
|
146
|
-
ss.scan(/\s+/)
|
147
|
-
if ss.scan(RELATION)
|
148
|
-
relation = ss[0].upcase
|
149
|
-
end
|
150
|
-
# else
|
151
|
-
# raise ScannerError, "relation is requested in '#{text}'"
|
152
|
-
# end
|
153
|
-
ss.scan(/\s+/)
|
154
|
-
if ss.scan(/.+/)
|
155
|
-
terms = ss[0].gsub(/(\A\"|\"\Z)/, '').split
|
156
|
-
else
|
157
|
-
raise ScannerError, "search term(s) is requested in '#{text}'"
|
158
|
-
end
|
159
|
-
|
160
|
-
[index, relation, terms]
|
161
|
-
end
|
162
|
-
|
163
|
-
def porta_adapter
|
164
|
-
logic_adapter
|
165
|
-
multiple_adapter
|
166
|
-
end
|
167
|
-
|
168
|
-
def logic_adapter
|
169
|
-
case
|
170
|
-
when LOGIC_ALL.include?(@index)
|
171
|
-
raise AdapterError unless %w[ALL ANY = EXACT ^].include?(@relation)
|
172
|
-
when LOGIC_ANY.include?(@index)
|
173
|
-
raise AdapterError unless %w[ANY =].include?(@relation)
|
174
|
-
when LOGIC_EQUAL.include?(@index)
|
175
|
-
raise AdapterError unless %w[=].include?(@relation)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def multiple_adapter
|
180
|
-
unless MULTIPLE.include?(@index)
|
181
|
-
raise AdapterError if @terms.size > 1
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def to_sunspot
|
186
|
-
case
|
187
|
-
when MATCH_ALL.include?(@index)
|
188
|
-
to_sunspot_match_all
|
189
|
-
when MATCH_EXACT.include?(@index)
|
190
|
-
to_sunspot_match_exact
|
191
|
-
when MATCH_PART.include?(@index)
|
192
|
-
to_sunspot_match_part
|
193
|
-
when MATCH_AHEAD.include?(@index)
|
194
|
-
to_sunspot_match_ahead
|
195
|
-
when MATCH_ANYWHERE.include?(@index)
|
196
|
-
to_sunspot_match_anywhere
|
197
|
-
when @index.empty?
|
198
|
-
@terms.join(' ')
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def to_sunspot_match_all
|
203
|
-
term = @terms.join(' ')
|
204
|
-
case @relation
|
205
|
-
when /\A=\Z/
|
206
|
-
unless /\A\^(.+)/ =~ term
|
207
|
-
"%s_%s:(%s)" % [@field, :text, term]
|
208
|
-
else
|
209
|
-
ahead_tarm = $1.gsub("\s", '').downcase
|
210
|
-
"connect_%s_%s:(%s*)" % [@field, :s, ahead_tarm]
|
211
|
-
end
|
212
|
-
when /\AEXACT\Z/
|
213
|
-
"%s_%s:(%s)" % [@field, :sm, term.gsub(' ', '')]
|
214
|
-
when /\AANY\Z/
|
215
|
-
"%s_%s:(%s)" % [@field, :text, multiple_to_sunspot(@terms, :any)]
|
216
|
-
when /\AALL\Z/
|
217
|
-
"%s_%s:(%s)" % [@field, :text, multiple_to_sunspot(@terms, :all)]
|
218
|
-
else
|
219
|
-
raise QuerySyntaxError
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def to_sunspot_match_exact
|
224
|
-
case @relation
|
225
|
-
when /\A=\Z/
|
226
|
-
term = @terms.join(' ')
|
227
|
-
type = @field != 'issn' ? :sm : :s
|
228
|
-
"%s_%s:(%s)" % [@field, type, term]
|
229
|
-
when /\AANY\Z/
|
230
|
-
"%s_%s:(%s)" % [@field, :sm, multiple_to_sunspot(@terms, :any)]
|
231
|
-
else
|
232
|
-
raise QuerySyntaxError
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
def to_sunspot_match_part
|
237
|
-
case @relation
|
238
|
-
when /\A=\Z/
|
239
|
-
term = @terms.join(' ')
|
240
|
-
"%s_%s:(%s)" % [@field, :text, trim_ahead(term)]
|
241
|
-
when /\AANY\Z/
|
242
|
-
"%s_%s:(%s)" % [@field, :text, multiple_to_sunspot(@terms, :any)]
|
243
|
-
when /\AALL\Z/
|
244
|
-
"%s_%s:(%s)" % [@field, :text, multiple_to_sunspot(@terms, :all)]
|
245
|
-
else
|
246
|
-
raise QuerySyntaxError
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
def to_sunspot_match_ahead
|
251
|
-
"%s_%s:(%s*)" % [@field, :s, @terms.first]
|
252
|
-
end
|
253
|
-
|
254
|
-
def to_sunspot_match_anywhere
|
255
|
-
case @relation
|
256
|
-
when /\A=\Z/
|
257
|
-
term = @terms.join(' ')
|
258
|
-
"(%s)" % [trim_ahead(term)]
|
259
|
-
when /\AANY\Z/
|
260
|
-
"(%s)" % [multiple_to_sunspot(@terms, :any)]
|
261
|
-
when /\AALL\Z/
|
262
|
-
"(%s)" % [multiple_to_sunspot(@terms, :all)]
|
263
|
-
else
|
264
|
-
raise QuerySyntaxError
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
|
269
|
-
private
|
270
|
-
def multiple_to_sunspot(terms, relation)
|
271
|
-
boolean = relation == :any ? ' OR ' : ' AND '
|
272
|
-
(terms.map{|t| trim_ahead(t)}.join(boolean)).to_s
|
273
|
-
end
|
274
|
-
|
275
|
-
def trim_ahead(term)
|
276
|
-
term.sub(/\A\^+/,'')
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
if $PROGRAM_NAME == __FILE__
|
281
|
-
require 'porta_cql_test'
|
282
|
-
end
|
data/lib/enju_biblio/sru.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'enju_biblio/porta_cql'
|
2
|
-
|
3
|
-
class QueryArgumentError < QueryError; end
|
4
|
-
|
5
|
-
class Sru
|
6
|
-
ASC_KEYS = %w(title creator) unless Object.const_defined?(:ASC_KEYS)
|
7
|
-
DESC_KEYS = %w(created_at updated_at date_of_publication) unless Object.const_defined?(:DESC_KEYS)
|
8
|
-
SORT_KEYS = ASC_KEYS + DESC_KEYS unless Object.const_defined?(:SORY_KEYS)
|
9
|
-
MULTI_KEY_MAP = {'title' => 'sort_title'} unless Object.const_defined?(:MULTI_KEY_MAP)
|
10
|
-
def initialize(params)
|
11
|
-
raise QueryArgumentError, 'sru :query is required item.' unless params.key?(:query)
|
12
|
-
|
13
|
-
@cql = Cql.new(params[:query])
|
14
|
-
@version = params.key?(:version) ? params[:version] : '1.2'
|
15
|
-
@start = params.key?(:startRecord) ? params[:startRecord].to_i : 1
|
16
|
-
@maximum = params.key?(:maximumRecords) ? params[:maximumRecords].to_i : 200
|
17
|
-
@maximum = 1000 if 1000 < @maximum
|
18
|
-
@packing = params.key?(:recordPacking) ? params[:recordPacking] : 'string'
|
19
|
-
@schema = params.key?(:recordSchema) ? params[:recordSchema] : 'dc'
|
20
|
-
@sort_key = params[:sortKeys]
|
21
|
-
|
22
|
-
@manifestations = []
|
23
|
-
@extra_response_data = {}
|
24
|
-
end
|
25
|
-
|
26
|
-
attr_reader :version, :cql, :start, :maximum, :packing, :schema, :path, :ascending
|
27
|
-
attr_reader :manifestations, :extra_response_data, :number_of_records, :next_record_position
|
28
|
-
|
29
|
-
def sort_by
|
30
|
-
sort = {sort_by: 'created_at', order: 'desc'}
|
31
|
-
unless '1.1' == @version
|
32
|
-
@path, @ascending = @cql.sort_by.split('/')
|
33
|
-
else
|
34
|
-
@path, @ascending = @sort_key.split(',') if @sort_key
|
35
|
-
end
|
36
|
-
# TODO ソート基準が入手しやすさの場合の処理
|
37
|
-
if SORT_KEYS.include?(@path)
|
38
|
-
if MULTI_KEY_MAP.keys.include?(@path)
|
39
|
-
sort[:sort_by] = MULTI_KEY_MAP[@path]
|
40
|
-
else
|
41
|
-
sort[:sort_by] = @path
|
42
|
-
end
|
43
|
-
sort[:order] = 'asc' if ASC_KEYS.include?(@path)
|
44
|
-
case @ascending
|
45
|
-
when /\A(1|ascending)\Z/
|
46
|
-
sort[:order] = 'asc'
|
47
|
-
when /\A(0|descending)\Z/
|
48
|
-
sort[:order] = 'desc'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
sort
|
52
|
-
end
|
53
|
-
|
54
|
-
def search
|
55
|
-
sunspot_query = @cql.to_sunspot
|
56
|
-
search = Sunspot.new_search(Manifestation)
|
57
|
-
role = Role.default_role
|
58
|
-
search.build do
|
59
|
-
fulltext sunspot_query
|
60
|
-
with(:required_role_id).less_than_or_equal_to role.id
|
61
|
-
paginate page: 1, per_page: 10000
|
62
|
-
end
|
63
|
-
@manifestations = search.execute!.results
|
64
|
-
@extra_response_data = get_extra_response_data
|
65
|
-
@number_of_records, @next_record_position = get_number_of_records
|
66
|
-
|
67
|
-
@manifestations
|
68
|
-
end
|
69
|
-
|
70
|
-
def get_extra_response_data
|
71
|
-
# TODO: NDL で必要な項目が決定し、更に enju にそのフィールドが設けられた後で正式な実装を行なう。
|
72
|
-
if @search.respond_to?(:erd)
|
73
|
-
@schema == 'dc' ? @search.erd : {}
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def get_number_of_records
|
78
|
-
# TODO: sunspot での取得方法が分かり次第、正式な実装を行なう。
|
79
|
-
@schema == 'dc' ? [1405, 1406] : [40,11]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
if $PROGRAM_NAME == __FILE__
|
84
|
-
require 'sru_test'
|
85
|
-
end
|