Class: BlacklightOaiProvider::SolrDocumentWrapper

Inherits:
OAI::Provider::Model
  • Object
show all
Defined in:
lib/blacklight_oai_provider/solr_document_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, options = {}) ⇒ SolrDocumentWrapper

Returns a new instance of SolrDocumentWrapper.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 5

def initialize(controller, options = {})
  @controller      = controller
  @document_model  = @controller.blacklight_config.document_model
  @solr_timestamp  = document_model.timestamp_key
  @timestamp_field = 'timestamp' # method name used by ruby-oai
  @limit           = options[:limit] || 15
  @set             = options[:set_model] || BlacklightOaiProvider::SolrSet

  @set.controller = @controller
  @set.fields = options[:set_fields]
end

Instance Attribute Details

#document_modelObject (readonly)

Returns the value of attribute document_model.



3
4
5
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 3

def document_model
  @document_model
end

#limitObject (readonly)

Returns the value of attribute limit.



3
4
5
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 3

def limit
  @limit
end

#solr_timestampObject (readonly)

Returns the value of attribute solr_timestamp.



3
4
5
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 3

def solr_timestamp
  @solr_timestamp
end

#timestamp_fieldObject (readonly)

Returns the value of attribute timestamp_field.



3
4
5
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 3

def timestamp_field
  @timestamp_field
end

Instance Method Details

#earliestObject



21
22
23
24
25
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 21

def earliest
  builder = @controller.search_builder.merge(fl: solr_timestamp, sort: "#{solr_timestamp} asc", rows: 1)
  response = @controller.repository.search(builder)
  response.documents.first.timestamp
end

#find(selector, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 33

def find(selector, options = {})
  return next_set(options[:resumption_token]) if options[:resumption_token]

  if selector == :all
    response = @controller.repository.search(conditions(options))

    if limit && response.total > limit
      return select_partial(BlacklightOaiProvider::ResumptionToken.new(options.merge(last: 0), nil, response.total))
    end
    response.documents
  else
    @controller.fetch(selector).first.documents.first
  end
end

#latestObject



27
28
29
30
31
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 27

def latest
  builder = @controller.search_builder.merge(fl: solr_timestamp, sort: "#{solr_timestamp} desc", rows: 1)
  response = @controller.repository.search(builder)
  response.documents.first.timestamp
end

#next_set(token_string) ⇒ Object

Raises:

  • (::OAI::ResumptionTokenException)


56
57
58
59
60
61
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 56

def next_set(token_string)
  raise ::OAI::ResumptionTokenException unless limit

  token = BlacklightOaiProvider::ResumptionToken.parse(token_string)
  select_partial(token)
end

#select_partial(token) ⇒ Object

Raises:

  • (::OAI::ResumptionTokenException)


48
49
50
51
52
53
54
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 48

def select_partial(token)
  records = @controller.repository.search(token_conditions(token)).documents

  raise ::OAI::ResumptionTokenException unless records

  OAI::Provider::PartialResult.new(records, token.next(token.last + limit))
end

#setsObject



17
18
19
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 17

def sets
  @set.all
end