Class: Krikri::RandomRecordGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/krikri/random_record_generator.rb

Overview

Gets random records from the search index

Instance Method Summary collapse

Constructor Details

#initializeRandomRecordGenerator


5
6
7
# File 'lib/krikri/random_record_generator.rb', line 5

def initialize
  @solr_repo = Blacklight::SolrRepository.new(Blacklight::Configuration.new)
end

Instance Method Details

#recordObject


10
11
12
13
14
15
16
17
# File 'lib/krikri/random_record_generator.rb', line 10

def record
  solr_params = { :id => "*:*",
                  :sort => "random_#{rand(9999)} desc",
                  :rows => 1 }
  query_result = @solr_repo.search(solr_params)
  solr_response = Blacklight::SolrResponse.new(query_result, solr_params)
  Krikri::SearchIndexDocument.new(solr_response.docs.first)
end