nathanaschbacher / nodiak

Nodiak is a Node.js client for the Riak Distributed Database
MIT License
43 stars 16 forks source link

search.twoi queries on $key return empty list #17

Closed dtonys closed 11 years ago

dtonys commented 11 years ago

Using the http API I can retrieve a list of keys from a bucket via 2i:

> curl 'http://10.0.1.49:8100/buckets/posts/index/$key/0/zzzzz'
     {"keys":["110","109","108","111","103","200","116","114","118","117","112","107"
     ,"106","102","104","101","105","113","115","119","100"]}

Using Nodiak, I get an empty list back when I try to query using the $key param

app.riak.bucket('posts').search.twoi(['0','zzzzz'], '$key', function(err, keys){
  console.log(keys);
});
//returns []

Querying a single value or range on $key both return an empty array as well.

Other 2i queries seem to work fine.

nathanaschbacher commented 11 years ago

So this comes up only when you attempt to use the $key special case index?

dtonys commented 11 years ago

I haven't tested all cases, but queries on a 'category' field worked fine.

So yes, only this case as far as I know. Riak automatically indexes the key into the $key param when leveldb and 2i is enabled, so maybe the way this is done is different than user defined indexes.

nathanaschbacher commented 11 years ago

Yeah it is... I know where the problem is.

https://github.com/nathanaschbacher/nodiak/blob/master/lib/bucket.js#L141

I'm deriving the index type "_int" or "_bin" for you as an abstraction based on what kind of data you send in as your query params.

You can get around this by using the lower level client backend adapter implementation for now, but I can probably fix this tonight without a problem:

https://github.com/nathanaschbacher/nodiak/blob/master/lib/backends/http.js#L234