Class: CheapSkate::ResultSet

Inherits:
Object
  • Object
show all
Defined in:
lib/cheap_skate/models.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#docsObject

Returns the value of attribute docs.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def docs
  @docs
end

#facetsObject

Returns the value of attribute facets.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def facets
  @facets
end

#limitObject

Returns the value of attribute limit.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def limit
  @limit
end

#max_scoreObject

Returns the value of attribute max_score.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def max_score
  @max_score
end

#nl_formatObject

Returns the value of attribute nl_format.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def nl_format
  @nl_format
end

#offsetObject

Returns the value of attribute offset.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def offset
  @offset
end

#queryObject

Returns the value of attribute query.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def query
  @query
end

#query_timeObject

Returns the value of attribute query_time.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def query_time
  @query_time
end

#totalObject

Returns the value of attribute total.



29
30
31
# File 'lib/cheap_skate/models.rb', line 29

def total
  @total
end

Instance Method Details

#<<(obj) ⇒ Object



30
31
32
33
# File 'lib/cheap_skate/models.rb', line 30

def <<(obj)
  @docs ||=[]
  @docs << obj
end

#as_jsonObject



53
54
55
56
57
# File 'lib/cheap_skate/models.rb', line 53

def as_json
  response = self.to_hash
  response["responseHeader"]["wt"] = "json"
  response.to_json
end

#as_rubyObject



48
49
50
51
52
# File 'lib/cheap_skate/models.rb', line 48

def as_ruby
  response = self.to_hash
  response["responseHeader"]["wt"] = "ruby"
  response.inspect
end

#to_hashObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cheap_skate/models.rb', line 35

def to_hash()
  response = {"responseHeader"=>{"status"=>0, "QTime"=>self.query_time, "params"=>{"q"=>self.query, "version"=>"2.2", "rows"=>self.limit}}}
  response["response"] = {"numFound"=>self.total, "start"=>self.offset, "rows"=>(self.docs||[]).length, "docs"=>[]}
  response["response"]["maxScore"] = self.max_score if self.max_score
  if self.docs
    self.docs.each do |doc|
      response["response"]["docs"] << doc
    end
  end
  
  response
end