Class: BlacklightOaiProvider::SolrDocumentWrapper
- Inherits:
-
OAI::Provider::Model
- Object
- OAI::Provider::Model
- BlacklightOaiProvider::SolrDocumentWrapper
- Defined in:
- lib/blacklight_oai_provider/solr_document_wrapper.rb
Instance Attribute Summary collapse
-
#document_model ⇒ Object
readonly
Returns the value of attribute document_model.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#solr_timestamp ⇒ Object
readonly
Returns the value of attribute solr_timestamp.
-
#timestamp_field ⇒ Object
readonly
Returns the value of attribute timestamp_field.
Instance Method Summary collapse
- #earliest ⇒ Object
- #find(selector, options = {}) ⇒ Object
-
#initialize(controller, options = {}) ⇒ SolrDocumentWrapper
constructor
A new instance of SolrDocumentWrapper.
- #latest ⇒ Object
- #next_set(token_string) ⇒ Object
- #select_partial(token) ⇒ Object
- #sets ⇒ Object
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, = {}) @controller = controller @document_model = @controller.blacklight_config.document_model @solr_timestamp = document_model. @timestamp_field = 'timestamp' # method name used by ruby-oai @limit = [:limit] || 15 @set = [:set_model] || BlacklightOaiProvider::SolrSet @set.controller = @controller @set.fields = [:set_fields] end |
Instance Attribute Details
#document_model ⇒ Object (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 |
#limit ⇒ Object (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_timestamp ⇒ Object (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 end |
#timestamp_field ⇒ Object (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 end |
Instance Method Details
#earliest ⇒ Object
21 22 23 24 25 |
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 21 def earliest builder = @controller.search_builder.merge(fl: , sort: "#{} asc", rows: 1) response = @controller.repository.search(builder) response.documents.first. 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, = {}) return next_set([:resumption_token]) if [:resumption_token] if selector == :all response = @controller.repository.search(conditions()) if limit && response.total > limit return select_partial(BlacklightOaiProvider::ResumptionToken.new(.merge(last: 0), nil, response.total)) end response.documents else @controller.fetch(selector).first.documents.first end end |
#latest ⇒ Object
27 28 29 30 31 |
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 27 def latest builder = @controller.search_builder.merge(fl: , sort: "#{} desc", rows: 1) response = @controller.repository.search(builder) response.documents.first. end |
#next_set(token_string) ⇒ Object
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
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 |
#sets ⇒ Object
17 18 19 |
# File 'lib/blacklight_oai_provider/solr_document_wrapper.rb', line 17 def sets @set.all end |