<commit_before>require 'oai'
module BlacklightOaiProvider
  class SolrDocumentWrapper < ::OAI::Provider::Model
    include Blacklight::SolrHelper
    attr_reader :model, :timestamp_field
    def initialize(options = {})
      @model = Blacklight.solr 
      @timestamp_field = options.delete(:timestamp_field) || 'timestamp'
      @limit = options.delete(:limit)
    end

    def sets
    end

    def earliest
      Time.parse get_search_results({:sort => @timestamp_field +' asc', :rows => 1}).last.first.get(@timestamp_field)
    end

    def latest
      Time.parse get_search_results({: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 = get_search_results({:sort => @timestamp_field + ' asc', :rows => @limit})
                                total = records.count

                                if @limit && total >= @limit
                                        return select_partial ResumptionToken.new options.merge({:last => 0})
                                end
                        else
                                records = get_search_results(:phrase_filters => {:id => selector.split('/', 2).last}).last.first
                        end
                        records

    end
    def select_partial token
                        records = get_search_results({:sort => @timestamp_field + ' asc', :rows => @limit, :start => token.last}).last

                        raise ::OAI::ResumptionTokenException.new unless records

                        PartialResult.new(records, token.next(@limit + token.last))
                    end

                    def next_set(token_string)
                        raise ::OAI::ResumptionTokenException.new unless @limit

                        token = ResumptionToken.parse token_string
                        select_partial token
                    end

    def extra_controller_params

    end
def params
  {}
end
def facet_limit_hash
  {}
end
  end
  class SolrDocumentProvider < ::OAI::Provider::Base
    Blacklight.config[:oai][:provider].each do |k, v|
      self.send k, v
    end
    source_model SolrDocumentWrapper.new Blacklight.config[:oai][:document]
  end
end<commit_msg>use options hash to populate params + extra controller params<commit_after>require 'oai'
module BlacklightOaiProvider
  class SolrDocumentWrapper < ::OAI::Provider::Model
    include Blacklight::SolrHelper
    attr_reader :model, :timestamp_field
    attr_accessor :params, :extra_controller_params
    attr_reader :facet_limit_hash
    def initialize(options = {})
      @model = Blacklight.solr 
      @timestamp_field = options.delete(:timestamp_field) || 'timestamp'
      @limit = options.delete(:limit)
      @params = options.delete(:params) || {}
      @facet_limit_hash = {}
      @extra_controller_params = options
    end

    def sets
    end

    def earliest
      Time.parse get_search_results({:sort => @timestamp_field +' asc', :rows => 1}).last.first.get(@timestamp_field)
    end

    def latest
      Time.parse get_search_results({: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 = get_search_results({:sort => @timestamp_field + ' asc', :rows => @limit})
                                total = records.count

                                if @limit && total >= @limit
                                        return select_partial ResumptionToken.new options.merge({:last => 0})
                                end
                        else
                                records = get_search_results(:phrase_filters => {:id => selector.split('/', 2).last}).last.first
                        end
                        records

    end
    def select_partial token
                        records = get_search_results({:sort => @timestamp_field + ' asc', :rows => @limit, :start => token.last}).last

                        raise ::OAI::ResumptionTokenException.new unless records

                        PartialResult.new(records, token.next(@limit + token.last))
                    end

                    def next_set(token_string)
                        raise ::OAI::ResumptionTokenException.new unless @limit

                        token = ResumptionToken.parse token_string
                        select_partial token
                    end
  end
  class SolrDocumentProvider < ::OAI::Provider::Base
    Blacklight.config[:oai][:provider].each do |k, v|
      self.send k, v
    end
    source_model SolrDocumentWrapper.new Blacklight.config[:oai][:document]
  end
end
{'fraction_non_alphanumeric': 0.09840319361277446, 'fraction_numerical': 0.0015968063872255488, 'mean_word_length': 1.8503981797497155, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3310042', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1221, 'n_words': 284}