Class: BlacklightOaiProvider::SolrSet

Inherits:
Set
  • Object
show all
Defined in:
lib/blacklight_oai_provider/solr_set.rb

Instance Attribute Summary collapse

Attributes inherited from Set

#description, #label, #value

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ SolrSet

Build a set object with, at minimum, a set spec string

Raises:

  • (OAI::ArgumentException)


65
66
67
68
69
70
71
# File 'lib/blacklight_oai_provider/solr_set.rb', line 65

def initialize(spec)
  super(spec)
  config = self.class.field_config_for(label)
  @solr_field = config[:solr_field]
  @description = config[:description]
  raise OAI::ArgumentException if @solr_field.blank?
end

Instance Attribute Details

#solr_fieldObject

OAI Set properties



62
63
64
# File 'lib/blacklight_oai_provider/solr_set.rb', line 62

def solr_field
  @solr_field
end

Class Method Details

.allObject

Return an array of all sets, or nil if sets are not supported



5
6
7
8
9
10
11
12
# File 'lib/blacklight_oai_provider/solr_set.rb', line 5

def all
  return if @fields.nil?

  params = { rows: 0, facet: true, 'facet.field' => solr_fields }
  solr_fields.each { |field| params["f.#{field}.facet.limit"] = -1 } # override any potential blacklight limits
  response, _records = @controller.get_search_results(@controller.params, params)
  sets_from_facets(response.facet_fields) if response.facet_fields
end

.field_config_for(label) ⇒ Object



40
41
42
# File 'lib/blacklight_oai_provider/solr_set.rb', line 40

def field_config_for(label)
  Array.wrap(@fields).find { |f| f[:label] == label } || {}
end

.fields=(value) ⇒ Object

The Solr fields to map to OAI sets. Must be indexed



29
30
31
32
33
34
35
36
37
38
# File 'lib/blacklight_oai_provider/solr_set.rb', line 29

def fields=(value) # The Solr fields to map to OAI sets. Must be indexed
  if value.respond_to?(:each)
    value.each do |config|
      raise ArgumentException, 'OAI sets must define a solr_field' if config[:solr_field].blank?
      config[:label] ||= config[:solr_field]
    end
  end

  super(value)
end

.from_spec(spec) ⇒ Object

Return a Solr filter query given a set spec



15
16
17
# File 'lib/blacklight_oai_provider/solr_set.rb', line 15

def from_spec(spec)
  new(spec).solr_filter
end

.sets_for(record) ⇒ Object

Returns array of sets for a solr document, or empty array if none are available.



20
21
22
23
24
25
26
27
# File 'lib/blacklight_oai_provider/solr_set.rb', line 20

def sets_for(record)
  Array.wrap(@fields).map do |field|
    values = record.get(field[:solr_field], sep: nil)
    Array.wrap(values).map do |value|
      new("#{field[:label]}:#{value}")
    end
  end.flatten
end

Instance Method Details

#nameObject



73
74
75
# File 'lib/blacklight_oai_provider/solr_set.rb', line 73

def name
  spec.titleize.gsub(':', ': ')
end

#solr_filterObject



81
82
83
# File 'lib/blacklight_oai_provider/solr_set.rb', line 81

def solr_filter
  "#{@solr_field}:\"#{@value}\""
end

#specObject



77
78
79
# File 'lib/blacklight_oai_provider/solr_set.rb', line 77

def spec
  "#{@label}:#{@value}"
end