blacklight_oai_provider 6.1.1 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +21 -50
- data/.rubocop.yml +1 -4
- data/.rubocop_todo.yml +53 -18
- data/.solr_wrapper +0 -1
- data/README.md +24 -3
- data/VERSION +1 -1
- data/blacklight_oai_provider.gemspec +5 -4
- data/lib/blacklight_oai_provider/solr_document_provider.rb +29 -10
- data/lib/blacklight_oai_provider/solr_document_wrapper.rb +60 -28
- data/lib/blacklight_oai_provider/solr_set.rb +6 -2
- data/lib/generators/blacklight_oai_provider/install_generator.rb +2 -2
- data/solr/conf/solrconfig.xml +182 -55
- data/spec/controllers/catalog_controller_spec.rb +1 -1
- data/spec/integration/blacklight_oai_provider/solr_document_wrapper_spec.rb +64 -0
- data/spec/lib/blacklight_oai_provider/solr_document_provider_spec.rb +18 -3
- data/spec/lib/blacklight_oai_provider/solr_document_wrapper_spec.rb +197 -22
- data/spec/requests/identify_spec.rb +1 -1
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +28 -23
- metadata +47 -17
- data/spec/test_app_templates/templates/catalog_controller.rb +0 -196
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39f7c456bbf8371097aace1c69c879de3c82cae03abe1102a45947a3f99dbc22
|
4
|
+
data.tar.gz: e4482b6884c20cd0abf3cd5f623ed31cba3a1d9294dd1fff1373dbd8d7856043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 721117f9ed5c2a0c15fd76bf5d2e7dd89df953f42229b63b8d4534ffd5167a8341c2770eb8dc514d0c28488581bf075482f05115b770e560c699b4f582108c5b
|
7
|
+
data.tar.gz: cb176cc115eb16e5bc06e0b46b84e673cb8be3713bb24babeb671601612ae6c15e75de2f9f7176d04f12fbfda420be398633bafbb5329ca52880155cf6bdf8da
|
data/.github/workflows/ci.yml
CHANGED
@@ -10,57 +10,28 @@ name: CI
|
|
10
10
|
on: push
|
11
11
|
|
12
12
|
jobs:
|
13
|
-
|
14
|
-
runs-on: ubuntu-latest
|
15
|
-
steps:
|
16
|
-
- uses: actions/checkout@v2
|
17
|
-
- name: Set up Ruby
|
18
|
-
uses: ruby/setup-ruby@v1
|
19
|
-
with:
|
20
|
-
ruby-version: 2.6
|
21
|
-
- name: Install dependencies
|
22
|
-
run: bundle install
|
23
|
-
env:
|
24
|
-
RAILS_VERSION: 5.2.4.4
|
25
|
-
- name: Run linter
|
26
|
-
run: bundle exec rubocop
|
27
|
-
test_rails5_2:
|
28
|
-
runs-on: ubuntu-latest
|
29
|
-
strategy:
|
30
|
-
matrix:
|
31
|
-
ruby: [2.6]
|
32
|
-
steps:
|
33
|
-
- uses: actions/checkout@v2
|
34
|
-
- name: Set up Ruby
|
35
|
-
uses: ruby/setup-ruby@v1
|
36
|
-
with:
|
37
|
-
ruby-version: ${{ matrix.ruby }}
|
38
|
-
- name: Install dependencies
|
39
|
-
run: bundle install
|
40
|
-
env:
|
41
|
-
RAILS_VERSION: 5.2.4.4
|
42
|
-
- name: Run tests
|
43
|
-
run: bundle exec rake ci
|
44
|
-
env:
|
45
|
-
RAILS_VERSION: 5.2.4.4
|
46
|
-
ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
|
47
|
-
test_rails5_1:
|
13
|
+
test:
|
48
14
|
runs-on: ubuntu-latest
|
49
15
|
strategy:
|
50
16
|
matrix:
|
51
|
-
|
17
|
+
rails_version: [6.1.4.7, 7.0.2.3]
|
18
|
+
ruby: [2.7, '3.0']
|
19
|
+
include:
|
20
|
+
- ruby: 2.7
|
21
|
+
rails: 5.2.6.3
|
22
|
+
- ruby: 2.7
|
23
|
+
rails: 6.0.3.7
|
24
|
+
env:
|
25
|
+
RAILS_VERSION: ${{ matrix.rails_version }}
|
52
26
|
steps:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
env:
|
65
|
-
RAILS_VERSION: 5.1.7
|
66
|
-
ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
- name: Install dependencies with Rails ${{ matrix.rails_version }}
|
33
|
+
run: bundle install
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
36
|
+
env:
|
37
|
+
ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
|
data/.rubocop.yml
CHANGED
@@ -4,8 +4,8 @@ inherit_from:
|
|
4
4
|
- .rubocop_todo.yml
|
5
5
|
|
6
6
|
AllCops:
|
7
|
-
TargetRubyVersion: 2.3
|
8
7
|
DisplayCopNames: true
|
8
|
+
TargetRubyVersion: 2.2
|
9
9
|
Exclude:
|
10
10
|
- "blacklight_oai_provider.gemspec"
|
11
11
|
|
@@ -50,6 +50,3 @@ Style/Documentation:
|
|
50
50
|
Lint/UnusedMethodArgument:
|
51
51
|
Exclude:
|
52
52
|
- 'lib/blacklight_oai_provider/set.rb'
|
53
|
-
|
54
|
-
RSpec/NestedGroups:
|
55
|
-
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2022-04-26 10:02:10 -0400 using RuboCop version 0.64.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 4
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Layout/EmptyLineAfterGuardClause:
|
12
|
+
Exclude:
|
13
|
+
- 'app/models/concerns/blacklight_oai_provider/solr_document.rb'
|
14
|
+
- 'lib/blacklight_oai_provider/solr_document_wrapper.rb'
|
15
|
+
- 'lib/blacklight_oai_provider/solr_set.rb'
|
16
|
+
|
9
17
|
# Offense count: 2
|
10
18
|
# Cop supports --auto-correct.
|
11
|
-
# Configuration parameters: EnforcedStyle
|
19
|
+
# Configuration parameters: EnforcedStyle.
|
12
20
|
# SupportedStyles: empty_lines, no_empty_lines
|
13
21
|
Layout/EmptyLinesAroundBlockBody:
|
14
22
|
Exclude:
|
@@ -18,10 +26,10 @@ Layout/EmptyLinesAroundBlockBody:
|
|
18
26
|
Metrics/AbcSize:
|
19
27
|
Max: 28
|
20
28
|
|
21
|
-
# Offense count:
|
22
|
-
# Configuration parameters: CountComments.
|
29
|
+
# Offense count: 4
|
30
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
23
31
|
Metrics/MethodLength:
|
24
|
-
Max:
|
32
|
+
Max: 46
|
25
33
|
|
26
34
|
# Offense count: 2
|
27
35
|
RSpec/BeforeAfterAll:
|
@@ -31,6 +39,16 @@ RSpec/BeforeAfterAll:
|
|
31
39
|
- 'spec/support/**/*.rb'
|
32
40
|
- 'spec/requests/list_identifiers_spec.rb'
|
33
41
|
|
42
|
+
# Offense count: 15
|
43
|
+
# Configuration parameters: Prefixes.
|
44
|
+
# Prefixes: when, with, without
|
45
|
+
RSpec/ContextWording:
|
46
|
+
Exclude:
|
47
|
+
- 'spec/lib/blacklight_oai_provider/solr_document_wrapper_spec.rb'
|
48
|
+
- 'spec/lib/blacklight_oai_provider/solr_set_spec.rb'
|
49
|
+
- 'spec/requests/list_identifiers_spec.rb'
|
50
|
+
- 'spec/requests/list_records_spec.rb'
|
51
|
+
|
34
52
|
# Offense count: 1
|
35
53
|
# Configuration parameters: CustomIncludeMethods.
|
36
54
|
RSpec/EmptyExampleGroup:
|
@@ -49,12 +67,19 @@ RSpec/InstanceVariable:
|
|
49
67
|
Exclude:
|
50
68
|
- 'spec/lib/blacklight_oai_provider/solr_document_wrapper_spec.rb'
|
51
69
|
|
52
|
-
# Offense count:
|
70
|
+
# Offense count: 1
|
71
|
+
# Cop supports --auto-correct.
|
72
|
+
RSpec/LeadingSubject:
|
73
|
+
Exclude:
|
74
|
+
- 'spec/models/solr_document_spec.rb'
|
75
|
+
|
76
|
+
# Offense count: 14
|
77
|
+
# Configuration parameters: AggregateFailuresByDefault.
|
53
78
|
RSpec/MultipleExpectations:
|
54
79
|
Max: 2
|
55
80
|
|
56
81
|
# Offense count: 2
|
57
|
-
# Configuration parameters: EnforcedStyle
|
82
|
+
# Configuration parameters: EnforcedStyle.
|
58
83
|
# SupportedStyles: strict, flexible
|
59
84
|
Rails/TimeZone:
|
60
85
|
Exclude:
|
@@ -62,7 +87,7 @@ Rails/TimeZone:
|
|
62
87
|
|
63
88
|
# Offense count: 1
|
64
89
|
# Cop supports --auto-correct.
|
65
|
-
# Configuration parameters: EnforcedStyle,
|
90
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
66
91
|
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
67
92
|
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
68
93
|
# FunctionalMethods: let, let!, subject, watch
|
@@ -71,21 +96,25 @@ Style/BlockDelimiters:
|
|
71
96
|
Exclude:
|
72
97
|
- 'spec/models/solr_document_spec.rb'
|
73
98
|
|
74
|
-
# Offense count:
|
99
|
+
# Offense count: 1
|
75
100
|
# Cop supports --auto-correct.
|
76
|
-
# Configuration parameters: EnforcedStyle
|
101
|
+
# Configuration parameters: EnforcedStyle.
|
77
102
|
# SupportedStyles: braces, no_braces, context_dependent
|
78
103
|
Style/BracesAroundHashParameters:
|
79
104
|
Exclude:
|
80
|
-
- 'lib/blacklight_oai_provider/solr_document_wrapper.rb'
|
81
105
|
- 'spec/models/solr_document_spec.rb'
|
82
106
|
|
83
|
-
# Offense count:
|
107
|
+
# Offense count: 2
|
108
|
+
Style/CommentedKeyword:
|
109
|
+
Exclude:
|
110
|
+
- 'lib/blacklight_oai_provider/solr_document_wrapper.rb'
|
111
|
+
- 'lib/blacklight_oai_provider/solr_set.rb'
|
112
|
+
|
113
|
+
# Offense count: 1
|
84
114
|
# Cop supports --auto-correct.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
Enabled: false
|
115
|
+
Style/ExpandPathArguments:
|
116
|
+
Exclude:
|
117
|
+
- 'spec/test_app_templates/lib/generators/test_app_generator.rb'
|
89
118
|
|
90
119
|
# Offense count: 2
|
91
120
|
# Configuration parameters: MinBodyLength.
|
@@ -93,9 +122,15 @@ Style/GuardClause:
|
|
93
122
|
Exclude:
|
94
123
|
- 'lib/generators/blacklight_oai_provider/install_generator.rb'
|
95
124
|
|
96
|
-
# Offense count:
|
125
|
+
# Offense count: 1
|
126
|
+
# Cop supports --auto-correct.
|
127
|
+
Style/IfUnlessModifier:
|
128
|
+
Exclude:
|
129
|
+
- 'lib/blacklight_oai_provider/solr_document_wrapper.rb'
|
130
|
+
|
131
|
+
# Offense count: 3
|
97
132
|
# Cop supports --auto-correct.
|
98
|
-
# Configuration parameters: MinSize
|
133
|
+
# Configuration parameters: MinSize.
|
99
134
|
# SupportedStyles: percent, brackets
|
100
135
|
Style/SymbolArray:
|
101
136
|
EnforcedStyle: brackets
|
data/.solr_wrapper
CHANGED
data/README.md
CHANGED
@@ -13,8 +13,14 @@ A few maintenance branches have been left in place in case there is interest to
|
|
13
13
|
|
14
14
|
`v4.x` -> Support for Blacklight 4.0 and Rails 3.0
|
15
15
|
|
16
|
+
`release-5.x` -> Support for Blacklight 5.x
|
17
|
+
|
18
|
+
`release-6.x` -> Support for Blacklight 6.x
|
19
|
+
|
20
|
+
`release-7.x` -> Support for Blacklight 7.x
|
21
|
+
|
16
22
|
## Requirements
|
17
|
-
A Rails app running Rails
|
23
|
+
A Rails app running Rails 6.x and Blacklight 7.x.
|
18
24
|
|
19
25
|
OAI-PMH requires a timestamp field for all records. The Solr index should include an appropriate field. This field should be able to support date range queries. By default, the name of this field is `timestamp` (more on how to configure this [below](#solrdocument-configuration)).
|
20
26
|
|
@@ -75,7 +81,7 @@ configure_blacklight do |config|
|
|
75
81
|
sample_id: '109660'
|
76
82
|
},
|
77
83
|
document: {
|
78
|
-
limit: 25 # number of records returned with each request, default: 15
|
84
|
+
limit: 25, # number of records returned with each request, default: 15
|
79
85
|
set_fields: [ # ability to define ListSets, optional, default: nil
|
80
86
|
{ label: 'language', solr_field: 'language_facet' }
|
81
87
|
]
|
@@ -86,7 +92,7 @@ configure_blacklight do |config|
|
|
86
92
|
end
|
87
93
|
```
|
88
94
|
|
89
|
-
The "provider" configuration is documented as part of the ruby-oai gem at
|
95
|
+
The "provider" configuration is documented as part of the ruby-oai gem at https://github.com/code4lib/ruby-oai and can be lambdas for dynamic configuration (e.g. `repository_name: ->(controller) { controller.send(:repository_name) }`).
|
90
96
|
|
91
97
|
A basic set model is included that maps Solr fields to OAI sets. Provide `set_fields` with an array of hashes defining the solr_field, and optionally a label and description. The configuration above will cause the `ListSets` verb to query Solr for unique values of the `language_facet` field and present each value as a set using a spec format of `language:value`. When the `set` parameter is supplied to the `ListRecords` verb, it will append a filter to the Solr query of the form `fq=language_facet:value`. If no label is provided, the set will use the `solr_field` name. To customize the ListSet implementation, see [customizing listsets](#customizing-listsets).
|
92
98
|
|
@@ -144,6 +150,21 @@ config.oai = {
|
|
144
150
|
}
|
145
151
|
```
|
146
152
|
|
153
|
+
### Disable pretty print stylesheet
|
154
|
+
|
155
|
+
By default, this gem pretty prints results in the browser using an XSLT stylesheet. You can change this behavior by overriding this stylesheet with a custom stylesheet containing an identity transform. In your app, create a file named `app/assets/stylesheets/blacklight_oai_provider/oai2.xsl` containing the following XSLT:
|
156
|
+
|
157
|
+
```xml
|
158
|
+
<?xml version="1.0" ?>
|
159
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
160
|
+
<xsl:template match="/ | @* | node()">
|
161
|
+
<xsl:copy>
|
162
|
+
<xsl:apply-templates select="@* | node()" />
|
163
|
+
</xsl:copy>
|
164
|
+
</xsl:template>
|
165
|
+
</xsl:stylesheet>
|
166
|
+
```
|
167
|
+
|
147
168
|
## Tests
|
148
169
|
We use `engine_cart` and `solr_wrapper` to run tests on a dummy instance of an app using this plugin.
|
149
170
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
7.0.2
|
@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_dependency "blacklight", "~>
|
20
|
-
s.add_dependency "oai", "~> 1.
|
19
|
+
s.add_dependency "blacklight", "~> 7.0"
|
20
|
+
s.add_dependency "oai", "~> 1.2"
|
21
|
+
s.add_dependency "rexml"
|
21
22
|
s.add_development_dependency 'rspec-rails'
|
22
23
|
s.add_development_dependency 'capybara'
|
23
24
|
s.add_development_dependency 'solr_wrapper'
|
@@ -25,6 +26,6 @@ Gem::Specification.new do |s|
|
|
25
26
|
s.add_development_dependency 'webdrivers', '~> 3.0'
|
26
27
|
s.add_development_dependency 'selenium-webdriver', '>= 3.13.1'
|
27
28
|
s.add_development_dependency 'byebug'
|
28
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
29
|
-
s.add_development_dependency "rubocop-rspec", '~> 1.
|
29
|
+
s.add_development_dependency 'rubocop', '~> 0.64.0'
|
30
|
+
s.add_development_dependency "rubocop-rspec", '~> 1.8'
|
30
31
|
end
|
@@ -2,23 +2,42 @@ module BlacklightOaiProvider
|
|
2
2
|
class SolrDocumentProvider < ::OAI::Provider::Base
|
3
3
|
attr_accessor :options
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
PROVIDER_INSTANCE_ATTRS = {
|
6
|
+
name: :repository_name,
|
7
|
+
url: :repository_url,
|
8
|
+
prefix: :record_prefix,
|
9
|
+
email: :admin_email,
|
10
|
+
delete_support: :deletion_support,
|
11
|
+
granularity: :update_granularity,
|
12
|
+
model: :source_model,
|
13
|
+
identifier: :sample_id,
|
14
|
+
description: :extra_description
|
15
|
+
}.freeze
|
10
16
|
|
11
|
-
|
12
|
-
options
|
17
|
+
def initialize(controller, options = {})
|
18
|
+
super(options.merge(provider_context: :instance_based))
|
13
19
|
|
14
|
-
options
|
20
|
+
provider_options = convert_to_instance_options(options.fetch(:provider, {}))
|
21
|
+
provider_options[:granularity] ||= OAI::Const::Granularity::HIGH
|
22
|
+
wrapper_options = options.fetch(:document, {}).dup.merge(granularity: provider_options[:granularity])
|
23
|
+
provider_options[:model] ||= SolrDocumentWrapper.new(controller, wrapper_options)
|
24
|
+
provider_options[:name] ||= controller.view_context.application_name
|
25
|
+
provider_options[:url] ||= controller.view_context.oai_catalog_url
|
26
|
+
provider_options.each do |k, v|
|
15
27
|
v = v.call(controller) if v.is_a?(Proc)
|
16
|
-
|
28
|
+
send :"#{k}=", v
|
17
29
|
end
|
18
30
|
end
|
19
31
|
|
20
32
|
def list_sets(options = {})
|
21
|
-
Response::ListSets.new(self
|
33
|
+
BlacklightOaiProvider::Response::ListSets.new(self, options).to_xml
|
34
|
+
end
|
35
|
+
|
36
|
+
def convert_to_instance_options(controller_options)
|
37
|
+
instance_options = controller_options.dup
|
38
|
+
PROVIDER_INSTANCE_ATTRS.each { |inst_att, class_att| instance_options[inst_att] ||= instance_options.delete(class_att) }
|
39
|
+
instance_options.delete_if { |k, _v| PROVIDER_INSTANCE_ATTRS[k].nil? }
|
40
|
+
instance_options
|
22
41
|
end
|
23
42
|
end
|
24
43
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module BlacklightOaiProvider
|
2
2
|
class SolrDocumentWrapper < ::OAI::Provider::Model
|
3
|
-
attr_reader :document_model, :timestamp_field, :solr_timestamp, :limit
|
3
|
+
attr_reader :document_model, :timestamp_field, :solr_timestamp, :limit, :granularity
|
4
4
|
|
5
5
|
def initialize(controller, options = {})
|
6
6
|
@controller = controller
|
@@ -9,6 +9,7 @@ module BlacklightOaiProvider
|
|
9
9
|
@timestamp_field = 'timestamp' # method name used by ruby-oai
|
10
10
|
@limit = options[:limit] || 15
|
11
11
|
@set = options[:set_model] || BlacklightOaiProvider::SolrSet
|
12
|
+
@granularity = options[:granularity] || OAI::Const::Granularity::HIGH
|
12
13
|
|
13
14
|
@set.controller = @controller
|
14
15
|
@set.fields = options[:set_fields]
|
@@ -18,36 +19,41 @@ module BlacklightOaiProvider
|
|
18
19
|
@set.all
|
19
20
|
end
|
20
21
|
|
22
|
+
def search_service
|
23
|
+
@controller.search_service
|
24
|
+
end
|
25
|
+
|
21
26
|
def earliest
|
22
|
-
builder =
|
23
|
-
response =
|
24
|
-
response.documents.first
|
27
|
+
builder = search_service.search_builder.merge(fl: solr_timestamp, sort: "#{solr_timestamp} asc", rows: 1)
|
28
|
+
response = search_service.repository.search(builder)
|
29
|
+
timestamp_presence(response.documents.first)
|
25
30
|
end
|
26
31
|
|
27
32
|
def latest
|
28
|
-
builder =
|
29
|
-
response =
|
30
|
-
response.documents.first
|
33
|
+
builder = search_service.search_builder.merge(fl: solr_timestamp, sort: "#{solr_timestamp} desc", rows: 1)
|
34
|
+
response = search_service.repository.search(builder)
|
35
|
+
timestamp_presence(response.documents.first)
|
31
36
|
end
|
32
37
|
|
33
38
|
def find(selector, options = {})
|
34
39
|
return next_set(options[:resumption_token]) if options[:resumption_token]
|
35
40
|
|
36
41
|
if selector == :all
|
37
|
-
response =
|
42
|
+
response = search_service.repository.search(conditions(options))
|
38
43
|
|
39
44
|
if limit && response.total > limit
|
40
45
|
return select_partial(BlacklightOaiProvider::ResumptionToken.new(options.merge(last: 0), nil, response.total))
|
41
46
|
end
|
42
47
|
response.documents
|
43
48
|
else
|
44
|
-
|
45
|
-
|
49
|
+
# search_service.fetch(selector).first.documents.first
|
50
|
+
query = search_service.search_builder.where(id: selector).query
|
51
|
+
search_service.repository.search(query).documents.first
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
55
|
def select_partial(token)
|
50
|
-
records =
|
56
|
+
records = search_service.repository.search(token_conditions(token)).documents
|
51
57
|
|
52
58
|
raise ::OAI::ResumptionTokenException unless records
|
53
59
|
|
@@ -61,33 +67,59 @@ module BlacklightOaiProvider
|
|
61
67
|
select_partial(token)
|
62
68
|
end
|
63
69
|
|
70
|
+
def conditions(constraints) # conditions/query derived from options
|
71
|
+
query = search_service.search_builder.merge(sort: "#{solr_timestamp} asc", rows: limit).query
|
72
|
+
|
73
|
+
if constraints[:from].present? || constraints[:until].present?
|
74
|
+
from_val = solr_date(constraints[:from])
|
75
|
+
to_val = solr_date(constraints[:until], true)
|
76
|
+
if from_val == to_val
|
77
|
+
query.append_filter_query("#{solr_timestamp}:\"#{from_val}\"")
|
78
|
+
else
|
79
|
+
query.append_filter_query("#{solr_timestamp}:[#{from_val} TO #{to_val}]")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
query.append_filter_query(@set.from_spec(constraints[:set])) if constraints[:set].present?
|
84
|
+
query
|
85
|
+
end
|
86
|
+
|
64
87
|
private
|
65
88
|
|
66
89
|
def token_conditions(token)
|
67
90
|
conditions(token.to_conditions_hash).merge(start: token.last)
|
68
91
|
end
|
69
92
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
)
|
93
|
+
def solr_date(time, end_val = false)
|
94
|
+
return '*' if time.blank?
|
95
|
+
case time
|
96
|
+
when Date
|
97
|
+
return granularize_date_value(time, end_val)
|
98
|
+
when Time
|
99
|
+
return granularize_time_value(time, end_val)
|
100
|
+
else
|
101
|
+
return time.to_s
|
77
102
|
end
|
103
|
+
end
|
78
104
|
|
79
|
-
|
80
|
-
|
105
|
+
def granularize_date_value(value, end_val)
|
106
|
+
return value.xmlschema[0..9] if granularity == OAI::Const::Granularity::LOW
|
107
|
+
|
108
|
+
# get last second of the day if end of range, else use first second of day
|
109
|
+
value = end_val ? Time.xmlschema((value + 1).xmlschema) - 1 : Time.xmlschema(value.xmlschema)
|
110
|
+
granularize_time_value(value, end_val)
|
81
111
|
end
|
82
112
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
113
|
+
def granularize_time_value(value, end_val)
|
114
|
+
value = value.utc
|
115
|
+
return value.xmlschema[0..9] if granularity == OAI::Const::Granularity::LOW
|
116
|
+
|
117
|
+
end_val ? value.xmlschema.sub(/(\:\d{2})Z$/, '\1.999Z') : value.xmlschema
|
118
|
+
end
|
119
|
+
|
120
|
+
def timestamp_presence(solr_doc)
|
121
|
+
return solr_doc.timestamp.presence if solr_doc && solr_doc.timestamp
|
122
|
+
Time.now.utc.to_s
|
91
123
|
end
|
92
124
|
end
|
93
125
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module BlacklightOaiProvider
|
2
2
|
class SolrSet < BlacklightOaiProvider::Set
|
3
3
|
class << self
|
4
|
+
def search_service
|
5
|
+
@controller.search_service
|
6
|
+
end
|
7
|
+
|
4
8
|
# Return an array of all sets, or nil if sets are not supported
|
5
9
|
def all
|
6
10
|
return if @fields.nil?
|
@@ -8,8 +12,8 @@ module BlacklightOaiProvider
|
|
8
12
|
params = { rows: 0, facet: true, 'facet.field' => solr_fields }
|
9
13
|
solr_fields.each { |field| params["f.#{field}.facet.limit"] = -1 } # override any potential blacklight limits
|
10
14
|
|
11
|
-
builder =
|
12
|
-
response =
|
15
|
+
builder = search_service.search_builder.merge(params)
|
16
|
+
response = search_service.repository.search(builder)
|
13
17
|
|
14
18
|
sets_from_facets(response.facet_fields) if response.facet_fields
|
15
19
|
end
|
@@ -31,8 +31,8 @@ module BlacklightOaiProvider
|
|
31
31
|
"\n concern :oai_provider, BlacklightOaiProvider::Routes.new\n"
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
"\n concerns :
|
34
|
+
gsub_file file_path, /concerns :searchable$/ do
|
35
|
+
"concerns :oai_provider\n concerns :searchable\n"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|