Class: Spotlight::SolrDocumentBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/services/spotlight/solr_document_builder.rb

Overview

Creates solr documents for the documents in a resource

Direct Known Subclasses

UploadSolrDocumentBuilder

Defined Under Namespace

Modules: NilSolrDocument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ SolrDocumentBuilder

Returns a new instance of SolrDocumentBuilder.



4
5
6
# File 'app/services/spotlight/solr_document_builder.rb', line 4

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



8
9
10
# File 'app/services/spotlight/solr_document_builder.rb', line 8

def resource
  @resource
end

Instance Method Details

#documents_to_indexObject

Returns an enumerator of all the indexable documents for this resource.

Returns:

  • an enumerator of all the indexable documents for this resource



13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/spotlight/solr_document_builder.rb', line 13

def documents_to_index
  data = to_solr
  return [] if data.blank?
  data &&= [data] if data.is_a? Hash

  return to_enum(:documents_to_index) { data.size } unless block_given?

  data.lazy.reject(&:blank?).each do |doc|
    yield doc.reverse_merge(exhibit_solr_doc(doc[unique_key]).to_solr)
  end
end