1

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

scphantm
  • 3,491
  • 6
  • 34
  • 70
  • App Engine has neither an `or` nor a `like`. There are suitable workarounds for both - http://stackoverflow.com/questions/930966/app-engine-datastore-does-not-support-operator-or/931193#931193, http://stackoverflow.com/q/47786/70492, respectively. – hyperslug Apr 22 '11 at 04:21
  • @hyperslug You should post that as an answre. @scphantm There's nothing preventing you from filtering on multiple properties in App Engine - subject to the restrictions hyperslug mentions. – Nick Johnson Apr 22 '11 at 06:05

2 Answers2

2

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.

Community
  • 1
  • 1
hyperslug
  • 3,103
  • 1
  • 25
  • 28
0

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.

topchef
  • 17,019
  • 8
  • 58
  • 98