您可以使用数据存储一次搜索多个字段吗
在我为 GAE 设计的应用程序中,我想要一个全方位搜索栏。
据我了解数据存储如何存储记录,它基本上是哈希图的哈希图。所以我有一个键,然后是一个看起来(为了概念简单)字符串,它是一个值的 JSON 返回。
在关系数据库世界中,如果我想同时搜索名字和姓氏,我必须
select * from user where user.firstname like 'bob' or user.lastname like 'bob'
在数据存储中进行类似的操作,我可以做类似的事情吗
select from user where user.anyfield like 'bob'
?它将搜索用户实体的所有字段,自动返回任何记录,其中user.firstname 和/或 user.lastname 就像“bob”?
in my app that im designing for GAE, i want, shall we say an omni search bar.
as i understand how datastore stores records, its basically a hashmap of hashmaps. so i have a key, then something that would look (for conceptional simplicity) a string that would be a JSON return for a value.
in relational DB world, if i wanted to search first and last name at the same time i would have to have something like this
select * from user where user.firstname like 'bob' or user.lastname like 'bob'
with datastore, can i do something like
select from user where user.anyfield like 'bob'
and it would search all the fields of the user entity automatically returning any record where either user.firstname and/or user.lastname was like 'bob'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
App Engine 不支持
OR
,但正如 Nick 建议的 此处,您可以通过查询名字和查询姓氏并组合结果来完成相同的任务。您也不能直接进行
LIKE
比较,但可以进行“开头为”查询,如下所示 此处。App Engine does not support
OR
, but as Nick suggests here, you can accomplish the same by doing a query for firstnames and another for lastnames and combining the results.You also cannot directly do a
LIKE
comparison, but you can do a "starts with" query, as shown here.有一个解决方案可以完全满足您的需求。它使用列表属性和关系索引实体。
使用 Objectify 实现的示例可以在我的博客 此处找到。要详细了解关系索引实体,请参阅此 Google IO跟踪。
There is a solution that exactly does what you need. It uses list properties and Relation Index Entities.
Example of the implementation using Objectify you can find in my blog here. To learn more about Relation Index Entities see this Google IO track.