Module: SpeedyAF::OrderedAggregationIndex::ClassMethods

Defined in:
lib/speedy_af/ordered_aggregation_index.rb

Instance Method Summary collapse

Instance Method Details

#indexed_ordered_aggregation(name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/speedy_af/ordered_aggregation_index.rb', line 7

def indexed_ordered_aggregation(name)
  target_class = reflections[name].class_name
  contains_key = reflections[:"ordered_#{name.to_s.singularize}_proxies"].options[:through]
  mixin = generated_association_methods
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
    def indexed_#{name}
      ids = self.indexed_#{name.to_s.singularize}_ids
      ids.lazy.collect { |id| #{target_class}.find(id) }
    end

    def indexed_#{name.to_s.singularize}_ids
      return [] unless persisted?
      docs = ActiveFedora::SolrService.query "id: \#{self.id}/#{contains_key}", rows: 1
      return [] if docs.empty? or docs.first['ordered_targets_ssim'].nil?
      docs.first['ordered_targets_ssim']
    end
  CODE
end