class Riak::SecondaryIndex

{Riak::SecondaryIndex} provides an object-oriented interface to secondary index (“2i”) functionality in Riak, available on the ‘memory` and `leveldb` backends.

Public Class Methods

new(bucket, index, query, options = {}) click to toggle source

Create a Riak Secondary Index operation @param [Bucket] bucket the {Riak::Bucket} we’ll query against @param [String] index the index name @param [String,Integer,Range<String,Integer>] query

a single value or range of values to query for
# File lib/riak/secondary_index.rb, line 17
def initialize(bucket, index, query, options = {})
  @bucket = bucket
  @client = @bucket.client
  @index = index
  @query = query
  @options = options

  if @bucket.is_a? Riak::BucketTyped::Bucket
    @options = { type: @bucket.type.name }.merge @options
  end

  validate_options
end

Public Instance Methods

get_server_version() click to toggle source
# File lib/riak/secondary_index.rb, line 31
def get_server_version
  @client.backend { |b| b.send :get_server_version }
end
has_next_page?() click to toggle source

Determine whether a SecondaryIndex fetch has a next page available

# File lib/riak/secondary_index.rb, line 59
def has_next_page?
  !!keys.continuation
end
keys(&block) click to toggle source

Get the array of matched keys

# File lib/riak/secondary_index.rb, line 36
def keys(&block)
  @collection ||=
    @client.backend do |b|
      b.get_index @bucket, @index, @query, @options, &block
    end
end
next_page() click to toggle source

Get a new SecondaryIndex fetch for the next page

# File lib/riak/secondary_index.rb, line 49
def next_page
  fail t('index.no_next_page') unless keys.continuation

  self.class.new(@bucket,
                 @index,
                 @query,
                 @options.merge(continuation: keys.continuation))
end
values() click to toggle source

Get the array of values

# File lib/riak/secondary_index.rb, line 44
def values
  @values ||= @bucket.get_many(keys).values
end

Private Instance Methods

paginated?() click to toggle source
# File lib/riak/secondary_index.rb, line 77
def paginated?
  @options[:continuation] || @options[:max_results]
end
validate_options() click to toggle source
# File lib/riak/secondary_index.rb, line 65
def validate_options
  if paginated? && !index_pagination?
    fail t('index.pagination_not_available')
  end

  if @options[:return_terms] && !index_return_terms?
    fail t('index.return_terms_not_available')
  end

  fail t('index.include_terms_is_wrong') if @options[:include_terms]
end