Class: Krikri::FieldValueReport

Inherits:
ActiveModelBase show all
Defined in:
app/models/krikri/field_value_report.rb

Overview

FieldValueReport gives all unique values for a given field within a document. It represents data that has been indexed into Solr.

This is a read-only object. FieldValueReports are not persisted.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveModelBase

#initialize, #persisted?

Constructor Details

This class inherits a constructor from Krikri::ActiveModelBase

Instance Attribute Details

#:field(: field) ⇒ Object (readonly)

the name of the field. @example: ‘sourceResource_title’



13
# File 'app/models/krikri/field_value_report.rb', line 13

attr_accessor :field, :provider

#:provider(: provider) ⇒ Object (readonly)



13
# File 'app/models/krikri/field_value_report.rb', line 13

attr_accessor :field, :provider

#fieldObject

Returns the value of attribute field.



13
14
15
# File 'app/models/krikri/field_value_report.rb', line 13

def field
  @field
end

#providerObject

Returns the value of attribute provider.



13
14
15
# File 'app/models/krikri/field_value_report.rb', line 13

def provider
  @provider
end

Class Method Details

.fieldsObject

All of the fields for which a report can be created.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/krikri/field_value_report.rb', line 32

def self.fields
  [:dataProvider_providedLabel,
   :sourceResource_alternative_providedLabel,
   :sourceResource_collection_title,
   :sourceResource_contributor_providedLabel,
   :sourceResource_creator_providedLabel,
   :sourceResource_date_providedLabel,
   :sourceResource_description,
   :sourceResource_format,
   :sourceResource_genre_providedLabel,
   :sourceResource_language_providedLabel,
   :sourceResource_publisher_providedLabel,
   :sourceResource_rights,
   :sourceResource_rightsHolder_providedLabel,
   :sourceResource_spatial_providedLabel,
   :sourceResource_subject_providedLabel,
   :sourceResource_temporal,
   :sourceResource_title,
   :sourceResource_type_name]
end

.find(field, provider_id) ⇒ Krikri::FieldValueReport

These two params act as a compound key.

Parameters:

  • field (String)

    the name of the field being reported on @example: ‘sourceResource_title’

  • provider_id (String)

    the id of the provider being reported on

Returns:



22
23
24
25
26
27
28
# File 'app/models/krikri/field_value_report.rb', line 22

def self.find(field, provider_id)
  return nil unless fields.include? field.to_sym
  provider = Krikri::Provider.find(provider_id)
  return nil unless provider.present?
  new({ :field => field,
        :provider => provider })
end

Instance Method Details

#enumerate_rows(opts = {}) ⇒ Object

Parameters:

  • opts (Hash) (defaults to: {})

    optional parameters for the solr request @example: enumerate_rows(batch_size: 1000)



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/krikri/field_value_report.rb', line 65

def enumerate_rows(opts = {})
  Enumerator.new do |yielder|
    loop do
      opts = query_opts(opts)
      response = Krikri::SolrResponseBuilder.new(opts).response
      break if response.docs.empty?

      parse_solr_response(response).each do |row|
        yielder <<  headers.map { |header| row[header] }
      end

      opts[:start] += opts[:rows]
      break if opts[:start] >= response.total
    end
  end
end

#headersObject

The headers for the report table, and the values to be returned from a Solr query.



56
57
58
# File 'app/models/krikri/field_value_report.rb', line 56

def headers
  [:id, :isShownAt_id, field.to_sym]
end