Skip to content

Commit

Permalink
adds get_unique() method to titan.index
Browse files Browse the repository at this point in the history
  • Loading branch information
espeed committed Jan 25, 2014
1 parent 9e7546c commit afa28cc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bulbs/titan/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,26 @@ def lookup(self, key=None, value=None, **pair):
return initialize_elements(self.client,resp)


def get_unique(self,key=None,value=None,**pair):
"""
Returns a max of 1 elements matching the key/value pair in the index.
:param key: The index key. This is optional because you can instead
supply a key/value pair such as name="James".
:param value: The index key's value. This is optional because you can
instead supply a key/value pair such as name="James".
:param pair: Optional keyword param. Instead of supplying key=name
and value = 'James', you can supply a key/value pair in
the form of name='James'.
"""
key, value = self._get_key_value(key,value,pair)
resp = self.client.lookup_vertex(self.index_name,key,value)
if resp.total_size > 0:
result = get_one_result(resp)
return initialize_element(self.client, result)

class KeyIndex(Index):

def keys(self):
Expand Down

0 comments on commit afa28cc

Please sign in to comment.