class Krikri::RandomSearchIndexDocumentBuilder
Gets random records from the search index
Attributes
provider_id[RW]
Public Class Methods
new(&block)
click to toggle source
@param &block may contain provider_id
Sample use: RandomSearchIndexDocumentBuilder.new do self.provider_id = '0123' end
# File lib/krikri/random_search_index_document_builder.rb, line 12 def initialize(&block) # set values from block instance_eval &block if block_given? end
Public Instance Methods
document()
click to toggle source
@return Krikri::SearchIndexDocument
# File lib/krikri/random_search_index_document_builder.rb, line 18 def document solr_response = Krikri::SolrResponseBuilder.new(query_params) return nil if solr_response.response.docs.empty? Krikri::SearchIndexDocument.new(solr_response.response.docs.first) end
Private Instance Methods
query_params()
click to toggle source
Parameters for the Solr request. Limits search by @provider_id if it has been specified.
# File lib/krikri/random_search_index_document_builder.rb, line 30 def query_params params = { :id => '*:*', :sort => "random_#{rand(9999)} desc", :rows => 1 } return params unless provider_id.present? provider = RDF::URI(Krikri::Provider.base_uri) / provider_id params[:fq] = "provider_id:\"#{provider}\"" params end