blacklight_oai_provider 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b00e5287f2ffa229d20459a1c8817abe39846888
4
- data.tar.gz: 6abf579e82431c293cfcaa57f4317a170bb102ca
3
+ metadata.gz: a928d521835ccd466eb70eaed91ac54a0680c60b
4
+ data.tar.gz: 923dbe6d7ec7c741fe4b63418a3b3ca51e8ed000
5
5
  SHA512:
6
- metadata.gz: 91e4142e3c0ccd46c65dc7dfbf63fc0e4e9f9034630ca212e23c1a9e7d1663a7ed8da7b7e37ee9a87e8d93bbe4fbff9700ea49e79f0228611d5993c0aba7e91c
7
- data.tar.gz: 1ea843062141a4d0dc0d58e4d964bee245ae539e7241c1f41b0e0d50362ebb1caac5926f36fa9019b75385f4f638027abdc7184956d80e0e09f3137b0783a822
6
+ metadata.gz: 36e1822ae96de49092998f5e02bba8ed43f3811e905f324be337b398af8d758b9bc9cc56183c0fcdb1884c37b4cc34c07c12504be62a13ef16a6e66074e82a51
7
+ data.tar.gz: 56fbfd912c0a969f35609f61e997151bb5f7b96d41d254c785e9397d4603b628fb0a9f2d0c7a86bcfaf0e0a08f623c8c26962ddc16bb1756061944ff935f409f
data/README.md CHANGED
@@ -66,7 +66,6 @@ configure_blacklight do |config|
66
66
  sample_id: '109660'
67
67
  },
68
68
  document: {
69
- model: SolrDocument, # SolrDocument class being used, default: SolrDocument
70
69
  limit: 25 # number of records returned with each request, default: 15
71
70
  set_fields: [ # ability to define ListSets, optional, default: nil
72
71
  { label: 'language', solr_field: 'language_facet' }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.0
1
+ 5.1.0
@@ -3,7 +3,7 @@ module BlacklightOaiProvider
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def timestamp
6
- timestamp = get(self.class.timestamp_key)
6
+ timestamp = fetch(self.class.timestamp_key, nil)
7
7
  raise BlacklightOaiProvider::Exceptions::MissingTimestamp if timestamp.blank?
8
8
  Time.zone.parse(timestamp) # Solr timestamps are all in UTC.
9
9
  end
@@ -22,7 +22,7 @@ BlacklightOaiProvider v5.x implements configuration changes. Please visit README
22
22
  s.require_paths = ["lib"]
23
23
 
24
24
  s.add_dependency "rails", "~> 4.0"
25
- s.add_dependency "blacklight", "~> 5.0"
25
+ s.add_dependency "blacklight", "~> 5.13"
26
26
  s.add_dependency "oai", "~> 0.4"
27
27
  s.add_development_dependency 'rspec-rails', "~> 3.0"
28
28
  s.add_development_dependency 'capybara'
@@ -4,7 +4,7 @@ module BlacklightOaiProvider
4
4
 
5
5
  def initialize(controller, options = {})
6
6
  @controller = controller
7
- @document_model = options[:model] || ::SolrDocument
7
+ @document_model = @controller.blacklight_config.document_model
8
8
  @solr_timestamp = document_model.timestamp_key
9
9
  @timestamp_field = 'timestamp' # method name used by ruby-oai
10
10
  @limit = options[:limit] || 15
@@ -19,32 +19,34 @@ module BlacklightOaiProvider
19
19
  end
20
20
 
21
21
  def earliest
22
- _response, records = @controller.get_search_results(@controller.params, { fl: solr_timestamp, sort: "#{solr_timestamp} asc", rows: 1 })
23
- records.first.timestamp
22
+ builder = @controller.search_builder.merge(fl: solr_timestamp, sort: "#{solr_timestamp} asc", rows: 1)
23
+ response = @controller.repository.search(builder)
24
+ response.documents.first.timestamp
24
25
  end
25
26
 
26
27
  def latest
27
- _response, records = @controller.get_search_results(@controller.params, { fl: solr_timestamp, sort: "#{solr_timestamp} desc", rows: 1 })
28
- records.first.timestamp
28
+ builder = @controller.search_builder.merge(fl: solr_timestamp, sort: "#{solr_timestamp} desc", rows: 1)
29
+ response = @controller.repository.search(builder)
30
+ response.documents.first.timestamp
29
31
  end
30
32
 
31
33
  def find(selector, options = {})
32
34
  return next_set(options[:resumption_token]) if options[:resumption_token]
33
35
 
34
36
  if selector == :all
35
- response, records = @controller.get_search_results(@controller.params, conditions(options))
37
+ response = @controller.repository.search(conditions(options))
36
38
 
37
39
  if limit && response.total > limit
38
40
  return select_partial(BlacklightOaiProvider::ResumptionToken.new(options.merge(last: 0), nil, response.total))
39
41
  end
42
+ response.documents
40
43
  else
41
- _response, records = @controller.get_solr_response_for_doc_id selector.split('/', 2).last
44
+ @controller.fetch(selector.split('/', 2).last).first.documents.first
42
45
  end
43
- records
44
46
  end
45
47
 
46
48
  def select_partial(token)
47
- _response, records = @controller.get_search_results(@controller.params, token_conditions(token))
49
+ records = @controller.repository.search(token_conditions(token)).documents
48
50
 
49
51
  raise ::OAI::ResumptionTokenException unless records
50
52
 
@@ -60,23 +62,21 @@ module BlacklightOaiProvider
60
62
 
61
63
  private
62
64
 
63
- def base_conditions
64
- { sort: "#{solr_timestamp} asc", rows: limit }
65
- end
66
-
67
65
  def token_conditions(token)
68
66
  conditions(token.to_conditions_hash).merge(start: token.last)
69
67
  end
70
68
 
71
69
  def conditions(options) # conditions/query derived from options
72
- filters = []
70
+ query = @controller.search_builder.merge(sort: "#{solr_timestamp} asc", rows: limit).query
71
+
73
72
  if options[:from].present? || options[:until].present?
74
- filters << "#{solr_timestamp}:[#{solr_date(options[:from])} TO #{solr_date(options[:until]).gsub('Z', '.999Z')}]"
73
+ query.append_filter_query(
74
+ "#{solr_timestamp}:[#{solr_date(options[:from])} TO #{solr_date(options[:until]).gsub('Z', '.999Z')}]"
75
+ )
75
76
  end
76
77
 
77
- filters << @set.from_spec(options[:set]) if options[:set].present?
78
-
79
- base_conditions.merge(fq: filters)
78
+ query.append_filter_query(@set.from_spec(options[:set])) if options[:set].present?
79
+ query
80
80
  end
81
81
 
82
82
  def solr_date(time)
@@ -7,7 +7,10 @@ module BlacklightOaiProvider
7
7
 
8
8
  params = { rows: 0, facet: true, 'facet.field' => solr_fields }
9
9
  solr_fields.each { |field| params["f.#{field}.facet.limit"] = -1 } # override any potential blacklight limits
10
- response, _records = @controller.get_search_results(@controller.params, params)
10
+
11
+ builder = @controller.search_builder.merge(params)
12
+ response = @controller.repository.search(builder)
13
+
11
14
  sets_from_facets(response.facet_fields) if response.facet_fields
12
15
  end
13
16
 
@@ -19,8 +22,7 @@ module BlacklightOaiProvider
19
22
  # Returns array of sets for a solr document, or empty array if none are available.
20
23
  def sets_for(record)
21
24
  Array.wrap(@fields).map do |field|
22
- values = record.get(field[:solr_field], sep: nil)
23
- Array.wrap(values).map do |value|
25
+ record.fetch(field[:solr_field], []).map do |value|
24
26
  new("#{field[:label]}:#{value}")
25
27
  end
26
28
  end.flatten
@@ -6,7 +6,7 @@ namespace :blacklight_oai_provider do
6
6
  require 'yaml'
7
7
 
8
8
  docs = YAML.safe_load(File.open(File.join(BlacklightOaiProvider.root, 'solr', 'sample_solr_documents.yml')))
9
- conn = RSolr.connect(Blacklight.solr_config)
9
+ conn = RSolr.connect(Blacklight.connection_config)
10
10
  conn.add docs
11
11
  conn.commit
12
12
  end
@@ -31,7 +31,6 @@ describe CatalogController do
31
31
 
32
32
  it 'return corrext document configuration' do
33
33
  expect(controller.oai_config[:document][:limit]).to be 25
34
- expect(controller.oai_config[:document][:model]).to be_a Class
35
34
  end
36
35
  end
37
36
 
@@ -44,16 +44,16 @@ class TestAppGenerator < Rails::Generators::Base
44
44
  say_status("warning", "ADDING BL OIA-PMH CONFIG")
45
45
 
46
46
  insert_into_file "app/controllers/catalog_controller.rb", after: " config.default_solr_params = { \n" do
47
- " :fl => '*',\n"
47
+ " fl: '*',\n"
48
48
  end
49
49
 
50
50
  insert_into_file "app/controllers/catalog_controller.rb", after: " configure_blacklight do |config|\n" do
51
51
  <<-CONFIG
52
52
  config.default_document_solr_params = {
53
- :qt => 'search',
54
- :fl => '*',
55
- :rows => 1,
56
- :q => '{!raw f=id v=$id}'
53
+ qt: 'search',
54
+ fl: '*',
55
+ rows: 1,
56
+ q: '{!raw f=id v=$id}'
57
57
  }
58
58
  CONFIG
59
59
  end
@@ -61,20 +61,19 @@ class TestAppGenerator < Rails::Generators::Base
61
61
  insert_into_file "app/controllers/catalog_controller.rb", after: "configure_blacklight do |config|\n" do
62
62
  <<-CONFIG
63
63
  config.oai = {
64
- :provider => {
65
- :repository_name => 'Test Repository',
66
- :repository_url => 'http://localhost/catalog/oai',
67
- :record_prefix => 'oai:test',
68
- :admin_email => 'root@localhost',
69
- :deletion_support => 'persistent',
70
- :sample_id => '109660'
64
+ provider: {
65
+ repository_name: 'Test Repository',
66
+ repository_url: 'http://localhost/catalog/oai',
67
+ record_prefix: 'oai:test',
68
+ admin_email: 'root@localhost',
69
+ deletion_support: 'persistent',
70
+ sample_id: '109660'
71
71
  },
72
- :document => {
73
- :model => SolrDocument,
74
- :set_fields => [
72
+ document: {
73
+ set_fields: [
75
74
  { label: 'language', solr_field: 'language_facet' }
76
75
  ],
77
- :limit => 25
76
+ limit: 25
78
77
  }
79
78
  }
80
79
  CONFIG
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_oai_provider
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-22 00:00:00.000000000 Z
12
+ date: 2017-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.0'
34
+ version: '5.13'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '5.0'
41
+ version: '5.13'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: oai
44
44
  requirement: !ruby/object:Gem::Requirement