Sha256: 56cafeb33751e2ecf8b91d67eee39b14478be3d3150e08b1d53cf63aa9cb922b
Contents?: true
Size: 2 KB
Versions: 1
Compression:
Stored size: 2 KB
Contents
module BlacklightOaiProvider class SolrDocumentWrapper < ::OAI::Provider::Model attr_reader :model, :timestamp_field attr_accessor :options def initialize(controller, options = {}) @controller = controller defaults = { :timestamp => 'timestamp', :limit => 15} @options = defaults.merge options @timestamp_field = @options[:timestamp] @limit = @options[:limit] end def sets end def earliest Time.parse @controller.get_search_results(@controller.params, {:fl => @timestamp_field, :sort => @timestamp_field +' asc', :rows => 1}).last.first.get(@timestamp_field) end def latest Time.parse @controller.get_search_results(@controller.params, {:fl => @timestamp_field, :sort => @timestamp_field +' desc', :rows => 1}).last.first.get(@timestamp_field) end def find(selector, options={}) return next_set(options[:resumption_token]) if options[:resumption_token] if :all == selector response, records = @controller.get_search_results(@controller.params, {:sort => @timestamp_field + ' asc', :rows => @limit}) if @limit && response.total >= @limit return select_partial(OAI::Provider::ResumptionToken.new(options.merge({:last => 0}))) end else records = @controller.get_search_results(@controller.params, {:phrase_filters => {:id => selector.split('/', 2).last}}).last.first end records end def select_partial token records = @controller.get_search_results(@controller.params, {:sort => @timestamp_field + ' asc', :rows => @limit, :start => token.last}).last raise ::OAI::ResumptionTokenException.new unless records OAI::Provider::PartialResult.new(records, token.next(token.last+@limit)) end def next_set(token_string) raise ::OAI::ResumptionTokenException.new unless @limit token = OAI::Provider::ResumptionToken.parse(token_string) select_partial(token) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blacklight_oai_provider-0.1.0 | lib/blacklight_oai_provider/solr_document_wrapper.rb |