neomodel:如何跨StructuredNode对象共享索引

时间:2013-07-15 12:37:11

标签: python indexing neo4j cypher neomodel

neomodel如何在节点对象之间共享唯一索引,而无需实例化单独的对象来保存索引数据? 我想基于索引查询找到对象,例如:

...
mynode = BaseObject.index.get(uid=uid_of_Type1Object)
# mynode is now of type `Type1Object`

class BaseObject(StructuredNode):
    uid = StringProperty(unique_index=True)
    ...

class Type1Object(BaseObject):
    ...
    def assign_uid(self, guid):
        # I may need tweaking of uid generator
        # on subclass level
        self.uid = guid

class Type2Object(BaseObject):
    ...
    def assign_uid(self, guid):
        self.uid = guid

1 个答案:

答案 0 :(得分:2)

https://github.com/robinedwards/neomodel/commit/1f1b43377b25cd4d41e17ce2b7f9ca1a1643edea中,它在StructuredNode subclasess上添加了对自定义索引的支持

class BaseObject(StructuredNode):
    __index__ = 'MyBaseIndex'
    uid = StringProperty(unique_index=True)
    ...

class Type1Object(BaseObject):
    __index__ = 'MyBaseIndex'
    ...
    def assign_uid(self, guid):
        # I may need tweaking of uid generator
        # on subclass level
        self.uid = guid

class Type2Object(BaseObject):
    __index__ = 'MyBaseIndex'
    ...
    def assign_uid(self, guid):
        self.uid = guid