Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Internally it uses `client.modify` with a mutator function to accomplish this.

### client.post(url, post_body, callback)

### client.index(bucket, index, begin_val, end_val, callback)

---

## Semi-deprecated / not in use / possibly not working
Expand Down
39 changes: 39 additions & 0 deletions riak.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,45 @@ RiakClient.prototype.post = function (url, post_body, callback) {
});
};

RiakClient.prototype.index = function (bucket, index, begin_val, end_val, callback) {
var self = this;

if (this.debug_mode) {
this.log("riak index", bucket + ", " + index + ", " + begin_val + ", ", + end_val);
}

if (typeof callback !== "function") {
throw new Error("Callback passed non-function");
}

this.pool.get({
path: "/buckets/" + encodeURIComponent(bucket) + "/index/" + encodeURIComponent(index) + "/" + encodeURIComponent(begin_val) + "/" + encodeURIComponent(end_val),
headers: {
"X-Riak-ClientId": this.client_id,
"Connection": "keep-alive"
}
}, function (err, res, body) {
if (err) {
return callback(err);
}
var obj = {};
if (body.length > 0 && res.statusCode === 200) {
try {
obj = JSON.parse(body);
} catch (json_err) {
console.warn("riak index JSON parse: " + body);
return callback(new Error("JSON parse error"));
}
return callback(null, res, obj);
} else {
if (self.debug_mode) {
self.log("riak index", bucket + ", " + index + " returned non-JSON, statusCode: " + res.statusCode + ", body:" + JSON.stringify(body));
}
return callback(null, res, {error: "non-JSON: " + body});
}
});
};

// TODO - this is no longer used, so it might not work anymore.
RiakClient.prototype.solr = function (bucket, query, limit, callback) {
var self = this;
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,24 @@ specify("append", function (assert) {
});
});

specify("index", function (assert) {
var bucket = "bucket_1",
key = "key_6",
message = "some string full of juicy data",
options = {"http_headers": {"x-riak-index-id_int": "1"}},
index = "id_int",
begin_val = "1",
end_val = "";
client.put(bucket, key, message, options, function (err, res, obj) {
assert.ok(!err);
assert.equal(res.statusCode, 204);

client.index(bucket, index, begin_val, end_val, function(err, res, obj) {
assert.ok(!err);
assert.equal(res.statusCode, 200);
assert.deepEqual(obj, {"keys": ["key_6"]});
});
});
});

specify.run(filters);