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

2024-05-20 00:55:24 发布

您现在位置:Python中文网/ 问答频道 /正文

在neomodel中,如何能够跨节点对象共享一个唯一的索引,而不实例化单独的对象来保存索引数据? 我想根据索引查询查找对象,例如:

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

^{pr2}$

Tags: of数据对象实例uidgetindex节点
1条回答
网友
1楼 · 发布于 2024-05-20 00:55:24

https://github.com/robinedwards/neomodel/commit/1f1b43377b25cd4d41e17ce2b7f9ca1a1643edea中添加了对StructuredNode子类的自定义索引的支持

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

相关问题 更多 >