Class: Riak::Client::ProtobuffsBackend
- Includes:
- FeatureDetection, Util::Escape, Util::Translation
- Defined in:
- lib/riak/client/protobuffs_backend.rb
Direct Known Subclasses
Constant Summary collapse
- MESSAGE_CODES =
BeefcakeMessageCodes
- UINTMAX =
0xffffffff
- QUORUMS =
{ "one" => UINTMAX - 1, "quorum" => UINTMAX - 2, "all" => UINTMAX - 3, "default" => UINTMAX - 4 }.freeze
Constants included from FeatureDetection
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#node ⇒ Object
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
-
#get_index(bucket, index, query) ⇒ Array<String>
Performs a secondary-index query via emulation through MapReduce.
-
#initialize(client, node) ⇒ ProtobuffsBackend
constructor
A new instance of ProtobuffsBackend.
-
#search(index, query, options = {}) ⇒ Hash
Performs search query via emulation through MapReduce.
- #socket ⇒ Object
-
#teardown ⇒ Object
Gracefully shuts down this connection.
Methods included from 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::Escape
#escape, #maybe_escape, #maybe_unescape, #unescape
Methods included from Util::Translation
Constructor Details
#initialize(client, node) ⇒ ProtobuffsBackend
50 51 52 53 |
# File 'lib/riak/client/protobuffs_backend.rb', line 50 def initialize(client, node) @client = client @node = node end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
47 48 49 |
# File 'lib/riak/client/protobuffs_backend.rb', line 47 def client @client end |
#node ⇒ Object
Returns the value of attribute node.
48 49 50 |
# File 'lib/riak/client/protobuffs_backend.rb', line 48 def node @node end |
Class Method Details
.simple(method, code) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/riak/client/protobuffs_backend.rb', line 40 def self.simple(method, code) define_method method do socket.write([1, MESSAGE_CODES.index(code)].pack('NC')) decode_response end end |
Instance Method Details
#get_index(bucket, index, query) ⇒ Array<String>
Performs a secondary-index query via emulation through MapReduce.
61 62 63 64 65 66 67 |
# File 'lib/riak/client/protobuffs_backend.rb', line 61 def get_index(bucket, index, query) mr = Riak::MapReduce.new(client).index(bucket, index, query) unless mapred_phaseless? mr.reduce(%w[riak_kv_mapreduce reduce_identity], :arg => {:reduce_phase_only_1 => true}, :keep => true) end mapred(mr).map {|p| p.last } end |
#search(index, query, options = {}) ⇒ Hash
Performs search query via emulation through MapReduce. This has more limited capabilites than native queries. Essentially, only the ‘id’ field of matched documents will ever be returned, the ‘fl’ and other options have no effect.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/riak/client/protobuffs_backend.rb', line 77 def search(index, query, = {}) mr = Riak::MapReduce.new(client).search(index || 'search', query) unless mapred_phaseless? mr.reduce(%w[riak_kv_mapreduce reduce_identity], :arg => {:reduce_phase_only_1 => true}, :keep => true) end docs = mapred(mr).map {|d| {'id' => d[1] } } # Since we don't get this information back from the MapReduce, # we have to fake the max_score and num_found. { 'docs' => docs, 'num_found' => docs.size, 'max_score' => 0.0 } end |
#socket ⇒ Object
95 96 97 |
# File 'lib/riak/client/protobuffs_backend.rb', line 95 def socket @socket ||= new_socket end |
#teardown ⇒ Object
Gracefully shuts down this connection.
91 92 93 |
# File 'lib/riak/client/protobuffs_backend.rb', line 91 def teardown reset_socket end |