scphantm
scphantm

Reputation: 4533

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

Upvotes: 1

Views: 1407

Answers (2)

topchef
topchef

Reputation: 19783

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.

Upvotes: 0

hyperslug
hyperslug

Reputation: 3623

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.

Upvotes: 2

Related Questions