开发者

can you search multiple fields at once with datastore

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'?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜