Class: NaranyaEcm::Search::Results

Inherits:
Rest::Relation show all
Defined in:
lib/naranya_ecm/search/results.rb

Constant Summary collapse

DEFAULT_MATERIALIZER =
Proc.new do |search_results|

  # Duplicate the hits array - we'll replace each element with the
  # resource:
  result_elements = search_results.hits.dup

  # Load from server all elements yet to materialize:
  pending_hits = result_elements.select { |e| e.is_a? NaranyaEcm::Search::Hit }
  pending_hits.map(&:klass).uniq.each do |hit_klass|
    # Obtain the ids for this hit_klass:
    hit_ids = pending_hits.select { |e| e.klass == hit_klass }.map(&:id)

    # Fetch the data from server:
    hit_klass.where(id: hit_ids).fetch_from_server.each do |fetched_data|
      r = hit_klass.load fetched_data

      hit_data = result_elements.detect { |e| e.is_a?(NaranyaEcm::Search::Hit) && e.klass == r.class && e.id == r.id }
      hit_index = result_elements.find_index hit_data

      r.merge_search_hit_data hit_data
      result_elements[hit_index] = r
    end
  end

  result_elements
end

Instance Attribute Summary collapse

Attributes inherited from Rest::Relation

#conditions, #elements, #klass

Instance Method Summary collapse

Methods inherited from Rest::Relation

#[], #fetch_from_server, #initialize, #limit, #load, #where

Constructor Details

This class inherits a constructor from NaranyaEcm::Rest::Relation

Instance Attribute Details

#materializerObject

Returns the value of attribute materializer.



35
36
37
# File 'lib/naranya_ecm/search/results.rb', line 35

def materializer
  @materializer
end

Instance Method Details

#any?Boolean



61
62
63
# File 'lib/naranya_ecm/search/results.rb', line 61

def any?
  count > 0
end

#countObject



57
58
59
# File 'lib/naranya_ecm/search/results.rb', line 57

def count
  hits.count
end

#digestObject



43
44
45
46
47
48
49
50
# File 'lib/naranya_ecm/search/results.rb', line 43

def digest
  [
    'naranya_ecm',
    'search',
    'results',
    Digest::MD5.hexdigest(@dsl.to_s)
  ]
end

#empty?Boolean



65
66
67
# File 'lib/naranya_ecm/search/results.rb', line 65

def empty?
  count < 1
end

#factsObject



69
70
71
72
# File 'lib/naranya_ecm/search/results.rb', line 69

def facts
  do_search! unless @facts
  @facts
end

#hitsObject



52
53
54
55
# File 'lib/naranya_ecm/search/results.rb', line 52

def hits
  do_search! unless @hits
  @hits
end

#max_scoreObject



74
75
76
77
# File 'lib/naranya_ecm/search/results.rb', line 74

def max_score
  do_search! unless @max_score
  @max_score
end

#query_process_timeObject



79
80
81
82
# File 'lib/naranya_ecm/search/results.rb', line 79

def query_process_time
  do_search! unless @query_process_time
  @query_process_time
end

#query_total_timeObject



84
85
86
87
# File 'lib/naranya_ecm/search/results.rb', line 84

def query_total_time
  do_search! unless @query_total_time
  @query_total_time
end

#to_aObject



93
94
95
96
# File 'lib/naranya_ecm/search/results.rb', line 93

def to_a
  materialize! unless @elements
  elements
end

#total_hitsObject Also known as: total_count



37
38
39
40
# File 'lib/naranya_ecm/search/results.rb', line 37

def total_hits
  do_search! unless @total_hits
  @total_hits
end