Class: Riak::SecondaryIndex

Inherits:
Object show all
Includes:
Client::FeatureDetection, Util::Translation
Defined in:
lib/riak/secondary_index.rb

Overview

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

Constant Summary

Constants included from Client::FeatureDetection

Client::FeatureDetection::VERSION

Instance Method Summary collapse

Methods included from Client::FeatureDetection

#http_props_clearable?, #index_pagination?, #index_return_terms?, #index_streaming?, #key_object_bucket_timeouts?, #mapred_phaseless?, #pb_conditionals?, #pb_head?, #pb_indexes?, #pb_search?, #quorum_controls?, #server_version, #tombstone_vclocks?

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(bucket, index, query, options = {}) ⇒ SecondaryIndex

Create a Riak Secondary Index operation

Parameters:

  • bucket (Bucket)

    the Bucket we’ll query against

  • index (String)

    the index name

  • query (String, Integer, Range<String,Integer>)

    a single value or range of values to query for



17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

Instance Method Details

#get_server_versionObject



31
32
33
# File 'lib/riak/secondary_index.rb', line 31

def get_server_version
  @client.backend { |b| b.send :get_server_version }
end

#has_next_page?Boolean

Determine whether a SecondaryIndex fetch has a next page available

Returns:

  • (Boolean)


59
60
61
# File 'lib/riak/secondary_index.rb', line 59

def has_next_page?
  !!keys.continuation
end

#keys(&block) ⇒ Object

Get the array of matched keys



36
37
38
39
40
41
# 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_pageObject

Get a new SecondaryIndex fetch for the next page



49
50
51
52
53
54
55
56
# 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

#valuesObject

Get the array of values



44
45
46
# File 'lib/riak/secondary_index.rb', line 44

def values
  @values ||= @bucket.get_many(keys).values
end