Class: BBC::Redux::SearchResults

Inherits:
Object
  • Object
show all
Defined in:
lib/bbc/redux/search_results.rb

Overview

Search results container

Examples:

Properties of search results


results = redux_client.search(:name => 'Pingu')

results.created_at     #=> DateTime
results.query          #=> Hash
results.query_time     #=> Float
results.assets         #=> Array<BBC::Redux::Asset>
results.total          #=> Integer
results.total_returned #=> Integer
results.has_more?      #=> Boolean

Iterating all search results


results = redux_client.search(:name => 'Pingu', :offset => 0)

while true do
  results.assets.each do |asset|
    puts asset.name
  end

  if results.has_more?
    next_query = results.query.merge({
      :offset => results.query[:offset] + 10
    })

    results = redux_client.search(next_query)
  else
    break
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assetsArray<BBC::Redux::Asset> (readonly)

Returns assets returned in this query

Returns:


59
# File 'lib/bbc/redux/search_results.rb', line 59

attribute :assets, Array[Asset]

#created_atDateTime (readonly)

Returns date and time results were retrieved

Returns:

  • (DateTime)

    date and time results were retrieved


47
# File 'lib/bbc/redux/search_results.rb', line 47

attribute :created_at, DateTime

#offsetInteger (readonly)

Returns offset of this set of results

Returns:

  • (Integer)

    offset of this set of results


63
# File 'lib/bbc/redux/search_results.rb', line 63

attribute :offset, Integer

#queryHash (readonly)

Returns original parameters used in this query

Returns:

  • (Hash)

    original parameters used in this query


51
# File 'lib/bbc/redux/search_results.rb', line 51

attribute :query, Hash

#query_timeFloat (readonly)

Returns query time in seconds

Returns:

  • (Float)

    query time in seconds


55
# File 'lib/bbc/redux/search_results.rb', line 55

attribute :query_time, Float

#totalInteger (readonly)

Returns total number of results

Returns:

  • (Integer)

    total number of results


67
# File 'lib/bbc/redux/search_results.rb', line 67

attribute :total, Integer

#total_returnedInteger (readonly)

Returns total number of results returned in this query

Returns:

  • (Integer)

    total number of results returned in this query


71
# File 'lib/bbc/redux/search_results.rb', line 71

attribute :total_returned, Integer

Instance Method Details

#has_more?Boolean

True if there are more results available than returned in this query

Returns:

  • (Boolean)

    true if there are more results available than returned in this query


75
76
77
# File 'lib/bbc/redux/search_results.rb', line 75

def has_more?
  (offset + total_returned) < total
end