예제 #1
0
 def create(self, key, value, abstract):
     """ Create and index a new node or relationship using the abstract
     provided.
     """
     batch = LegacyWriteBatch(self.graph)
     if self._content_type is Node:
         batch.create(abstract)
         batch.add_to_index(Node, self, key, value, 0)
     elif self._content_type is Relationship:
         batch.create(abstract)
         batch.add_to_index(Relationship, self, key, value, 0)
     else:
         raise TypeError(self._content_type)
     entity, index_entry = batch.submit()
     return entity
예제 #2
0
    def remove(self, key=None, value=None, entity=None):
        """ Remove any entries from the index which match the parameters
        supplied. The allowed parameter combinations are:

        `key`, `value`, `entity`
            remove a specific entity indexed under a given key-value pair

        `key`, `value`
            remove all entities indexed under a given key-value pair

        `key`, `entity`
            remove a specific entity indexed against a given key but with
            any value

        `entity`
            remove all occurrences of a specific entity regardless of
            key and value

        """
        if key and value and entity:
            t = ResourceTemplate(self.resource.uri.string + "/{key}/{value}/{entity}")
            t.expand(key=key, value=value, entity=entity._id).delete()
        elif key and value:
            uris = [
                URI(entity.resource.metadata["indexed"])
                for entity in self.get(key, value)
            ]
            batch = LegacyWriteBatch(self.graph)
            for uri in uris:
                batch.append_delete(uri)
            batch.run()
        elif key and entity:
            t = ResourceTemplate(self.resource.uri.string + "/{key}/{entity}")
            t.expand(key=key, entity=entity._id).delete()
        elif entity:
            t = ResourceTemplate(self.resource.uri.string + "/{entity}")
            t.expand(entity=entity._id).delete()
        else:
            raise TypeError("Illegal parameter combination for index removal")
예제 #3
0
    def remove(self, key=None, value=None, entity=None):
        """ Remove any entries from the index which match the parameters
        supplied. The allowed parameter combinations are:

        `key`, `value`, `entity`
            remove a specific entity indexed under a given key-value pair

        `key`, `value`
            remove all entities indexed under a given key-value pair

        `key`, `entity`
            remove a specific entity indexed against a given key but with
            any value

        `entity`
            remove all occurrences of a specific entity regardless of
            key and value

        """
        if key and value and entity:
            t = ResourceTemplate(self.resource.uri.string +
                                 "/{key}/{value}/{entity}")
            t.expand(key=key, value=value, entity=entity._id).delete()
        elif key and value:
            uris = [
                URI(entity.resource.metadata["indexed"])
                for entity in self.get(key, value)
            ]
            batch = LegacyWriteBatch(self.graph)
            for uri in uris:
                batch.append_delete(uri)
            batch.run()
        elif key and entity:
            t = ResourceTemplate(self.resource.uri.string + "/{key}/{entity}")
            t.expand(key=key, entity=entity._id).delete()
        elif entity:
            t = ResourceTemplate(self.resource.uri.string + "/{entity}")
            t.expand(entity=entity._id).delete()
        else:
            raise TypeError("Illegal parameter combination for index removal")
예제 #4
0
 def create(self, key, value, abstract):
     """ Create and index a new node or relationship using the abstract
     provided.
     """
     batch = LegacyWriteBatch(self.graph)
     if self._content_type is Node:
         batch.create(abstract)
         batch.add_to_index(Node, self, key, value, 0)
     elif self._content_type is Relationship:
         batch.create(abstract)
         batch.add_to_index(Relationship, self, key, value, 0)
     else:
         raise TypeError(self._content_type)
     entity, index_entry = batch.submit()
     return entity