Rexster: Indices

Bulbs API for the Rexster indices.

Manual Index

class bulbs.rexster.index.ManualIndex(client, result)[source]

Creates, retrieves, and deletes indices provided by the graph database.

Use this class to get, put, and update items in an index.

Parameters:
  • client – The Client object for the database.
  • result – The result list returned by Rexster.
  • classes – Zero or more subclasses of Element to use when initializing the the elements returned by the query. For example, if Person is a subclass of Node (which is defined in model.py and is a subclass of Vertex), and the query returns person elements, pass in the Person class and the method will use the element_type defined in the class to initialize the returned items to a Person object.

Example that creates an index for Web page URL stubs, adds an page element to it, and then retrieves it from the index:

>>> graph = Graph()
>>> graph.indices.create("page","vertex","automatic","[stub]")
>>> index = graph.indices.get("page")
>>> index.put("stub",stub,page._id)
>>> page = index.get("stub",stub)
put(_id, key=None, value=None, **pair)[source]

Put an element into the index at key/value and return Rexster’s response.

Parameters:
  • _id – The element ID.
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
update(_id, key=None, value=None, **pair)[source]

Update the element ID for the key and value and return Rexsters’ response.

Parameters:
  • _id – The element ID.
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
put_unique(_id, key=None, value=None, **pair)[source]

Put an element into the index at key/value and overwrite it if an element already exists at that key and value; thus, there will be a max of 1 element returned for that key/value pair. Return Rexster’s response.

Parameters:
  • _id – The element ID.
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
get_unique(key=None, value=None, **pair)[source]

Returns a max of 1 elements matching the key/value pair in the index.

Parameters:
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
remove(_id, key=None, value=None, **pair)[source]

Remove the element from the index located by key/value.

Parameters:
  • _id – The element ID.
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
count(key=None, value=None, **pair)

Return a count of all elements with ‘key’ equal to ‘value’ in the index.

Parameters:
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
classmethod get_proxy_class(base_type)

Returns the IndexProxy class.

Parameters:base_type (str) – Index base type, either vertex or edge.
Return type:class
index_class

Returns the index class, either vertex or edge.

Return type:class
index_name

Returns the index name.

Return type:str
index_type

Returns the index type, which will either be automatic or manual.

Return type:str
lookup(key=None, value=None, **pair)

Return a generator containing all the elements with key property equal to value in the index.

Parameters:
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • raw – Optional keyword param. If set to True, it won’t try to initialize the results. Defaults to False.
  • 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’.

Automatic Index

class bulbs.rexster.index.AutomaticIndex(client, result)[source]
keys()[source]

Return the index’s keys.

count(key=None, value=None, **pair)

Return a count of all elements with ‘key’ equal to ‘value’ in the index.

Parameters:
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • 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’.
classmethod get_proxy_class(base_type)

Returns the IndexProxy class.

Parameters:base_type (str) – Index base type, either vertex or edge.
Return type:class
index_class

Returns the index class, either vertex or edge.

Return type:class
index_name

Returns the index name.

Return type:str
index_type

Returns the index type, which will either be automatic or manual.

Return type:str
lookup(key=None, value=None, **pair)

Return a generator containing all the elements with key property equal to value in the index.

Parameters:
  • key – The index key. This is optional because you can instead supply a key/value pair such as name=”James”.
  • value – The index key’s value. This is optional because you can instead supply a key/value pair such as name=”James”.
  • raw – Optional keyword param. If set to True, it won’t try to initialize the results. Defaults to False.
  • 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’.

Vertex Index Proxy

class bulbs.rexster.index.VertexIndexProxy(index_class, client)[source]

Manage vertex indices on Rexster.

Parameters:
Variables:
  • index_class – Index class.
  • client – RexsterClient object.
create(index_name)[source]

Creates an Vertex index and returns it.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.index.Index
get(index_name)[source]

Returns the Index object with the specified name or None if not found.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.index.Index
get_or_create(index_name, index_params=None)[source]

Get a Vertex Index or create it if it doesn’t exist.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.index.Index
delete(index_name)[source]

Deletes an index and returns the Response.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.client.RexsterResponse

Edge Index Proxy

class bulbs.rexster.index.EdgeIndexProxy(index_class, client)[source]

Manage edge indices on Rexster.

Parameters:
Variables:
  • index_class – Index class.
  • client – RexsterClient object.
create(index_name, *args, **kwds)[source]

Adds an index to the database and returns it.

index_keys must be a string in this format: ‘[k1,k2]’ Don’t pass actual list b/c keys get double quoted.

Parameters:
  • index_name – The name of the index to create.
  • index_class – The class of the elements stored in the index. Either vertex or edge.
get(index_name)[source]

Returns the Index object with the specified name or None if not found.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.index.Index
get_or_create(index_name, index_params=None)[source]

Get an Edge Index or create it if it doesn’t exist.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.index.Index
delete(index_name)[source]

Deletes an index and returns the Response.

Parameters:index_name (str) – Index name.
Return type:bulbs.rexster.client.RexsterResponse