我应该使用NDB还是searchapi来存储用户模型?

2024-10-01 00:26:51 发布

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

假设我在ndb中有一个具有以下属性的基本用户模型:

```

name = ndb.StringProperty(default='')
username = ndb.StringProperty(required=True)
email = ndb.StringProperty(default='')
active = ndb.BooleanProperty(default=True)
admin = ndb.BooleanProperty(default=False)
permissions = ndb.StringProperty(repeated=True)
verified = ndb.BooleanProperty(default=False)
token = ndb.StringProperty(default='')
password_hash = ndb.StringProperty(default='')
bio = ndb.StringProperty(default='')
location = ndb.StringProperty(default='')
facebook = ndb.StringProperty(default='')
twitter = ndb.StringProperty(default='')
gplus = ndb.StringProperty(default='')
github = ndb.StringProperty(default='')

```

假设我想对字段nameusernamebio执行LIKE查询

我读过这篇answer about NDB and Search API,我不清楚是应该只通过搜索API存储nameusernamebio,并手动维护它们的一致性,还是应该通过searchapi存储所有属性,以便检索数据更快/更简单。在

任何建议:)


Tags: 用户name模型apifalsetruedefault属性
2条回答

你应该在任何重要的数据存储中存储。它有冗余和弹性-它是你的“主人”。在

然后你应该传递数据来搜索。。。等等。。。搜索!这可能包括数据存储记录的ID。在

如果需要的字段多于搜索文档中的字段,则可以通过batch gets从Memcache或Datastore中检索完整的数据对象。在

我从未见过任何关于全文搜索API的一致性承诺(即强与最终一致性),它也不能参与事务。在

这意味着,虽然在上运行like查询很有用,但您需要依赖其他一些存储机制作为您的主要数据源。在

所以保存到数据存储中,将感兴趣的字段索引到搜索索引中。查询时,在搜索索引中搜索,然后使用结果中的id/键从数据存储中查找数据(确保满足任何一致性约束)。在

相关问题 更多 >